Moving Average crossover plot


Category:
0
0

Hello, I am having trouble coding this study. I am trying to make a lower study that represents which ema is over the other. I need it so that if the 12 ema is above the 30 ema, a green dot is plotted in a lower study, and if the 30 ema is above the 12 ema a red dot is plotted in a lower study. Thank you!

Marked as spam
Posted by (Questions: 34, Answers: 56)
Asked on April 5, 2017 4:19 am
1681 views
0
Private answer

Pretty sure we show how to do this here: https://www.hahn-tech.com/ans/horizontal-line-moving-average/

You will have to adapt it to work with your chosen moving averages, but the core components are all there.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 5, 2017 7:29 am
0

Thank you, but that post you linked me too confused me. I am just trying to get a horizontal line when the 12 ema is above the 30 ema a green dot is plotted. When the 30 ema is above the 12 ema, a red dot is plotted. Thank you ?

( at April 5, 2017 6:50 pm)
0
Private answer

Here is the code from the post I linked, with the Double moving average code replaced by two simple moving averages:

declare lower;
input MA1_length = 12;
input MA2_length = 30;
def ma1 = Average(close, MA1_length);
def ma2 = Average(close, MA2_length);
plot zeroLine = 0;
zeroLine.AssignValueColor(if ma1 > ma2 then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 5, 2017 7:51 pm
0

How do I change the SMAs to EMAs in this script?

( at April 8, 2017 5:58 am)
0

I must be doing a lousy job teaching this subject.
Check here for details:

http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage.html

And here are the changes:

def ma1 = ExpAverage(close, MA1_length);
def ma2 = ExpAverage(close, MA2_length);

( at April 8, 2017 8:58 am)