使用策略输入时Pinescript错误

问题描述 投票:0回答:1

我正在使用这个指标并试图修改它以发出警报。完成。 然后当我尝试添加策略条目时它说错误:编译脚本和指标不起作用它消失了,没有任何细节 .我尝试了 5-10 个关于策略输入和策略错误的代码,但没有人在工作。我想在 tradingview 策略测试器中测试这个指标

enter image description here

// Tradingview.com Pinescript @author Ni6HTH4wK [LAVA]
study(title="[LAVA] Heiken Ashi Oscillator")

// Inputs
n1  = input(10, title="Multiplier", minval=1)
n2  = input(42, title="RSI Length", minval=2)
q1  = input(false, title="Show as RSI")

// Sources
hk_open = security(heikenashi(tickerid), tostring((interval*n1)), open)
hk_stop = security(heikenashi(tickerid), tostring((interval*n1)), close)
hk_local_open = na(hk_open[1])?open:(hk_open[1]+ohlc4[1])/2
hk_local_stop = ohlc4

// Source logic
oc_hi = max(hk_local_open,hk_local_stop)
oc_lo = min(hk_local_open,hk_local_stop)
oc_dif = avg(oc_hi-oc_lo, high-low)
dif_ema = ema(oc_dif, 14)
std_dev = stdev(dif_ema, 20)

// Heiken Ashi Logic
hk_bull = hk_stop>hk_open?low>=hk_open?3*std_dev+hk_bull[1]:1*std_dev+hk_bull[1]:0
hk_bear = hk_open>hk_stop?high<=hk_open?3*std_dev+hk_bear[1]:1*std_dev+hk_bear[1]:0

// Heiken Ashi RSI
hk_rsi = rsi(cum(hk_bull)-cum(hk_bear), 14)

// Coloring
hk_cci = cci(ohlc4, n2)>0

// Plotting
plot(q1?na:hk_bull>0?hk_bull:na, title="Bullish Heiken Ashi", style=areabr, color=#339933, transp=50)
plot(q1?na:hk_bear>0?hk_bear:na, title="Bearish Heiken Ashi", style=areabr, color=#ff0f0f, transp=50)
plot(q1?hk_rsi:na, title="Heiken Ashi RSI", linewidth=2, color=hk_cci?#459915:#cf0023, transp=50)
plot(q1?70:na, color=#222222)
plot(q1?30:na, color=#222222)


changeToGreen = hk_bull <=0
changeToRed = hk_bear <=0


alertcondition(changeToGreen, title = "AO color changed to greenn", message = "Awesome Oscillator's color has changed to green")
alertcondition(changeToRed, title = "AO color changed to redd", message = "Awesome Oscillator's color has changed to red")

// Order conditions
enterLong = hk_bull <=0

// Submit long orders
if (enterLong)
    strategy.order(id="Enter Long", long=true)

我试图在绿色开始时拉长,在红色开始时拉短。变色时关闭

我可以使用交易视图回测这个策略

pine-script pine-script-v5 tradingview-api pine-script-v4
1个回答
0
投票

您需要添加版本标识符

//@version=2
并将您的脚本更改为
strategy
.

//@version=2
strategy(title="[LAVA] Heiken Ashi Oscillator")
© www.soinside.com 2019 - 2024. All rights reserved.