I'm using this code to find SMI at the last candle close time.
a = input(10, "Percent K Length")
b = input(3, "Percent D Length")
ob = input(40, "Overbought")
os = input(-40, "Oversold")
// Range Calculation
ll = lowest (low, a)
hh = highest (high, a)
diff = hh - ll
rdiff = close - (hh+ll)/2
avgrel = ema(ema(rdiff,b),b)
avgdiff = ema(ema(diff,b),b)
// SMI calculations
SMI = avgdiff != 0 ? (avgrel/(avgdiff/2)*100) : 0
SMIsignal = ema(SMI,b)
emasignal = ema(SMI, 10)
The code provides me the current SMIsignal and emasignal at closure time and it works fine.
Is it possible to have the current SMIsignal only if it is lowering in the last 3 (e.g.) candles
and a null (zero) SMIsignal value if the SMIsignal is not lowering in the last 3 (e.g.) candles ?
question from:
https://stackoverflow.com/questions/65934724/how-to-recognize-a-signal-trend-using-pine 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…