Decreasing EMA

Dix

New member
VIP
Is there a way to code for a decreasing EMA? Tried coding this but not quite getting it. For example I would like to determine if the 9 day or 21 day ema is decreasing. Thanks!
 

BenTen

Administrative
Staff member
Staff
VIP
EMA follows the price. If EMA is decreasing, that means the stock is also dropping. Just track the net change of the stock. Does that make sense?
 

Dix

New member
VIP
Yes, that makes sense. I have always tracked the net change however I was trying to determine if I could plot the EMA decreasing bar over bar. For example I have a study showing when the 9 day ema crosses the 21 day ema, however I wanted to see if I can track if the 9 day day ema bar over bar keeps decreasing once it crosses the 21 day ema. This way I can scan and set an alert for these stocks. Hopefully that makes sense.
 

BenTen

Administrative
Staff member
Staff
VIP
Hmm, not sure if this is what you wanted, but worth a try.

This watchlist column will show Green if the current EMA value is greater than the previous bar's EMA value and vice versa if it shows Red.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

input price = close;
input length = 9;
input displace = 0;

plot AvgExp = ExpAverage(price[-displace], length);

AssignBackgroundColor(if AvgExp > AvgExp[1] then Color.Dark_Green else if AvgExp < AvgExp[1] then Color.Dark_Red else Color.Gray);
 

Similar threads

Top