MACD Multi Timeframe


Category:
0
0

I have been trying to create a MTF MACD crossover at a 30 min timeframe and show bullish or bearish while I’m on the 1 min timeframe. I am having problems getting the aggregation period to work. Hoping you could help, thanks!

Def positive =MACD().”Value” crosses above MACD().”Avg”;

Def negative =MACD().”Value” crosses below MACD().”Avg”;

def signal = if positive then 2 else if negative then 1 else 0;

AddLabel (yes, “30Min ” , (if signal == 2 then Color.Green else if signal == 1 then Color.red else Color.white));

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 3)
Asked on September 19, 2020 7:43 pm
353 views
0
Private answer

The following tutorial video is almost everything I have to say on the topic:

https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

"Almost everything"? Yes, I do have a few more things to say and they are explained in the following video:

https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/

 

Edit: After receiving feedback on this post I decided to provide a complete solution that achieves the specific goals that are implied by the example code provided in the question of this post. The solution is much more complex than the example code permits. So I had to write this from scratch.

input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
input timeFrameOne = AggregationPeriod.THIRTY_MIN;
def value = MovingAverage(macdAverageType, close(period = timeFrameOne), fastLength) - MovingAverage(macdAverageType, close(period = timeFrameOne), slowLength);
def average = MovingAverage(macdAverageType, value, macdLength);
def diff = value - average;
def crossAbove = value[1] < average[1] and value > average;
def crossBelow = value[1] > average[1] and value < average;
AddLabel(yes, "30 Min", if crossAbove then Color.GREEN else if crossBelow then Color.RED else Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 19, 2020 7:50 pm
0
Thank you. I am working on my own strategy and have hit a wall. If you can help answer my original question I would appreciate it. Otherwise, I'm sorry for wasting your time.
( at September 19, 2020 8:10 pm)
0
Wasting my time? I have no clue why you said that. The two videos I linked provide fully functioning MTF MACD chart study and strategy. Everything is already done for you. Simply view the video to learn how it works and download the code. That is the most direct and specific answer to your question you could ever imagine. When you examine the code provided with each of those videos you will understand exactly what it takes to build a multiple time frame chart study for the MACD. When you view the second video you will learn to avoid the major pitfalls when building a multiple time frame chart strategy.
( at September 20, 2020 8:19 am)
0
Thank you again. Sorry, just thought I was wasting your time because you already had a MTF MACD indicator. I say this in the most polite way possible, I'm not interested in the two videos you provided, but it is very impressive.
( at September 20, 2020 9:22 am)
0
Ah, ok. Glad you took the time to explain that. So much is lost in typed text so its sometimes difficult to catch the full meaning. If you have examined the code from either of those videos you will find that Multiple Time Frame computations are much more complex than what your example code is able to achieve. In fact you must use the full and complete code from the MACD in order to get the data to compute from the higher time frames. Be VERY careful to watch and study the second video I linked above. If you miss the most important part of that video you will end up creating a MTF chart strategy that lies. Meaning it will print P/L results that are impossible to achieve in live trading. I have updated my answer to include the specification solution you requested.
( at September 20, 2020 11:57 am)
0
Thank you so much Mr. Hahn! That is exactly what I wanted.
( at September 20, 2020 1:37 pm)