Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

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 ?

question from:https://stackoverflow.com/questions/65934724/how-to-recognize-a-signal-trend-using-pine

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...