In Thinkorswim, I use the following strategy
code to detect the shift in the daily EMA on a 1-minute chart. The daily EMA looks like a staircase pattern that reset every day. I use Y
to track changes in the daily EMA, and I expect a spike at the start of each trading day when the daily EMA changes its value, but my code only shows a straight line. Does anyone know a fix to this?
# Tested on a 1-minute chart with TSLA
def day_close = close(period = AggregationPeriod.DAY);
plot ema8d = ExpAverage(day_close, 8);
# expect a spike at the start of each trading day
def ema_changed = Round(ema8d[0],2) <> Round(ema8d[1],2);
plot Y = if ema_changed then 179.5 else 179;
I expect the chart to look like this