Color plot based on ema crossing sma


Category:
0
0

Hello please can you help me with the script the assign color value when EMA 9 crossover SMA 9

input lengthOne = 9;
input lengthTwo = 9;
input maTypeOne = AverageType.EXPONENTIAL;
input maTypeTwo = AverageType.SIMPLE;
input priceOne = close;
input priceTwo = close;
def maOne = MovingAverage(maTypeOne, priceOne, lengthOne);
def maTwo = MovingAverage(maTypeTwo, priceTwo, lengthTwo);

 

Actually I am looking for line that become red when Sma crossover EMA and green when EMA crossover Sma.

 

Thanks

Marked as spam
Posted by (Questions: 12, Answers: 5)
Asked on January 8, 2021 6:34 pm
193 views
0
Private answer

You did not specify any lines in your code. So I changed the last two lines in your code into plot statements and picked one of those plots to apply the dynamic color.

FYI, there are tons of examples of this already in the forum. Please spend some time searching and learning before posting such a simple request. (most of the easy questions have already been posted and solved).

input lengthOne = 9;
input lengthTwo = 9;
input maTypeOne = AverageType.EXPONENTIAL;
input maTypeTwo = AverageType.SIMPLE;
input priceOne = close;
input priceTwo = close;
plot maOne = MovingAverage(maTypeOne, priceOne, lengthOne);
plot maTwo = MovingAverage(maTypeTwo, priceTwo, lengthTwo);
maOne.AssignValueColor(if maOne > maTwo then Color.CYAN else Color.MAGENTA);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 9, 2021 10:24 am