gr68
gr68

Reputation: 502

how to recognize a signal trend using pine

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 ?

Upvotes: 0

Views: 78

Answers (1)

AnyDozer
AnyDozer

Reputation: 2568

SMItmp = float(na)
SMItmp := ema(SMI,b)
sig = SMItmp[3]<SMItmp[2] and SMItmp[2]<SMItmp[1] and SMItmp[1]<SMItmp[0]
SMIsignal = sig ? SMItmp : na

Upvotes: 1

Related Questions