如何为 OVERbought/OVERsold 条件创建 RSI LOOKback?脚本
How to create RSI LOOKback for OVERbought/OVERsold condition? pinescript
我正在尝试编写回溯输入代码,以检查我的 RSI 超卖情况是否发生在最后 4 个烛台内的任何地方以触发买入信号。(并且对其进行调整将是重新测试策略的理想选择)。我只是不知道如何将其插入我的“多头”策略?。我不断收到“和”错误?似乎无法弄清楚这一点,任何帮助都会非常棒!
这确实有效...
回顾=输入(4,“回顾”)
long = (rsiOversold[lookback]) and open > close[1] 和 high1 - low1 >= 24 * syminfo.mintick
非常感谢大声笑,
保罗
//@version=4
strategy(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, overlay = false, process_orders_on_close = true)
//Get Values
len = input(10, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
overbought = input(title="OB",defval=70)
oversold = input(title="OS",defval=30)
lookback = input(4, "Lookback")
//RSI Value
rsiValue = rsi(src, len)
rsiOverbought = barssince(rsiValue > overbought) ==1
rsiOversold = barssince(rsiValue < oversold) ==1
long = rsiOversold, lookback and open > close[1] and high*1 - low*1 >= 24 * syminfo.mintick
exitLong = close < low[1]
short = rsiOverbought and open < close[1] and high*1 - low*1 >= 24 * syminfo.mintick
exitShort = high > high[1]
bgcolor(barssince(rsiValue > overbought) == 1 ? color.red : na)
bgcolor(barssince(rsiValue < oversold) == 1 ? color.green : na)
//Alerts
alertcondition(rsiOverbought, title = "Overbought", message = "{{close}}")
alertcondition(rsiOversold, title = "Oversold", message = "{{close}}")
// Plotted Values
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
//Entry and Exit
strategy.entry("long", strategy.long, 1, when = long)
strategy.close("long", when = exitLong)
strategy.entry("short", strategy.short, 1, when = short)
strategy.close("short", when = exitShort)
lookback = input(4, "Lookback")
rsiOverboughtWithLookback = barssince(rsiValue > overbought) < lookback
bgcolor(rsiOverboughtWithLookback ? color.lime : na)
如果您的 RSI 超卖情况发生在最后 4 个烛台内的任何地方,该情况将保持真实/为背景石灰着色。
我正在尝试编写回溯输入代码,以检查我的 RSI 超卖情况是否发生在最后 4 个烛台内的任何地方以触发买入信号。(并且对其进行调整将是重新测试策略的理想选择)。我只是不知道如何将其插入我的“多头”策略?。我不断收到“和”错误?似乎无法弄清楚这一点,任何帮助都会非常棒!
这确实有效... 回顾=输入(4,“回顾”) long = (rsiOversold[lookback]) and open > close[1] 和 high1 - low1 >= 24 * syminfo.mintick
非常感谢大声笑,
保罗
//@version=4
strategy(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, overlay = false, process_orders_on_close = true)
//Get Values
len = input(10, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
overbought = input(title="OB",defval=70)
oversold = input(title="OS",defval=30)
lookback = input(4, "Lookback")
//RSI Value
rsiValue = rsi(src, len)
rsiOverbought = barssince(rsiValue > overbought) ==1
rsiOversold = barssince(rsiValue < oversold) ==1
long = rsiOversold, lookback and open > close[1] and high*1 - low*1 >= 24 * syminfo.mintick
exitLong = close < low[1]
short = rsiOverbought and open < close[1] and high*1 - low*1 >= 24 * syminfo.mintick
exitShort = high > high[1]
bgcolor(barssince(rsiValue > overbought) == 1 ? color.red : na)
bgcolor(barssince(rsiValue < oversold) == 1 ? color.green : na)
//Alerts
alertcondition(rsiOverbought, title = "Overbought", message = "{{close}}")
alertcondition(rsiOversold, title = "Oversold", message = "{{close}}")
// Plotted Values
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
//Entry and Exit
strategy.entry("long", strategy.long, 1, when = long)
strategy.close("long", when = exitLong)
strategy.entry("short", strategy.short, 1, when = short)
strategy.close("short", when = exitShort)
lookback = input(4, "Lookback")
rsiOverboughtWithLookback = barssince(rsiValue > overbought) < lookback
bgcolor(rsiOverboughtWithLookback ? color.lime : na)
如果您的 RSI 超卖情况发生在最后 4 个烛台内的任何地方,该情况将保持真实/为背景石灰着色。