当RSI来自超买级和交叉40级,而rsi来自超卖级和交叉60级时,请帮助只获得rsi的第一个信号。
//@version=5
indicator(title='RSI test')
//inputs
rsiob60 = input(title='From overbought level (70) and crossover 60:', defval=60)
rsios40 = input(title='From Oversold level (30) and crossunder 40:', defval=40)
// Get indicator values
rsi = ta.rsi(close, 14)
////============ calculations for new cross
//
short = ta.crossunder(rsi,rsiob60)
long = ta.crossover(rsi,rsios40)
//
plotshape(long, "Short", style=shape.triangleup, location=location.bottom, color=color.green, size=size.tiny)
plotshape(short, "Long", style=shape.triangledown, location=location.top, color=color.red, size=size.tiny)
// Plot
plot(rsiob60, title='Overbought short', color=color.new(color.red, 20))
plot(rsios40, title='Oversold long', color=color.new(color.green, 20))
plot(rsi, title='RSI', color=color.new(color.purple, 0))
hline(70, 'RSI Overbought Level', color.new(color.red, 50))
hline(50, 'RSI Middle Band', color=color.new(#787B86, 60))
hline(30, 'RSI Oversold Level', color.new(color.green, 50))发布于 2022-08-21 20:53:36
使用var查看rsi是否低于OS。然后在crossover时检查此标志。
当有一个crossover时重置标志,因此它将为下一个信号做好准备。
var is_os = false
is_os := ta.crossover(rsi, 40) ? false : (rsi < 30) ? true : is_os注:当有一个crossover时,上面的is_os将是false。因此,使用历史引用操作符(如is_os[1] )检查它的前一个值。
plotshape(Short and is_os[1], "Long", style=shape.triangleup, location=location.bottom, color=color.green, size=size.tiny)

https://stackoverflow.com/questions/73438034
复制相似问题