在我的 pine 脚本的均值回归策略中出现错误

getting error in my mean-reversion strategy of pine script

提问人:Rashmi Rahul 提问时间:11/15/2023 最后编辑:TylerHRashmi Rahul 更新时间:11/16/2023 访问量:22

问:

我在松树脚本的均值回归策略中遇到了错误。

此Pine脚本代码定义了一种均值回归策略,当RSI高于30且收盘价低于布林带下轨时,该策略会生成多头信号,当RSI穿过70下方且收盘价高于布林带上轨时,会生成空头信号。它还在图表上绘制布林带。

//@version=4
study(title="Mean Reversion Strategy", shorttitle="MRS", overlay=true)

// Input parameters
length = input(14, title="RSI Length")
src = input(close, title="Source")
sma_length = input(20, title="SMA Length")
bb_length = input(20, title="Bollinger Bands Length")
mult = input(2.0, title="Bollinger Bands Standard Deviation")

// Calculate SMA, RSI, and Bollinger Bands
sma = sma(src, sma_length)
rsi = rsi(length)
basis = sma(src, bb_length)
dev = mult * stdev(src, bb_length)

// Define conditions for long and short signals
long_condition = crossover(rsi, 30) and close < basis - dev
short_condition = crossunder(rsi, 70) and close > basis + dev

// Plot signals on the chart
plotshape(series=long_condition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=short_condition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

// Plot Bollinger Bands on the chart
plot(basis, color=color.blue, title="Basis")
plot(basis + dev, color=color.red, title="Upper Band")
plot(basis - dev, color=color.green, title="Lower Band")
pine-script tradingview-api 松脚本-v4

评论

2赞 vitruvius 11/15/2023
我投票关闭这个问题,因为这是 chatGPT 生成的代码。
0赞 vitruvius 11/15/2023
仅供参考,需要两个参数。rsi()

答: 暂无答案