代码中发生错误。请帮助解决它

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

帮助,我正在尝试编写这种分析策略,但是对此错误发誓。我认为原因是脚本的上半部分来自版本4,下半部分来自版本3。请帮助我确定阻止脚本运行的原因是什么?image error here

strategy("ABCSStrategy CUT long ",shorttitle="Step", overlay=true)
//resolutions
long_step  = input(title="long_step ", type=resolution, defval="180")
length = input(100),fast = input(50),slow = input(200),src = input(close)
//
er = abs(change(src,length))/sum(abs(change(src)),length)
dev = er*stdev(src*2,fast) + (1-er)*stdev(src*2,slow)
a=0.,a := src > nz(a[1],src) + dev ? src : src < nz(a[1],src) - dev ? src : nz(a[1],src)
//
css = fixnan(a > a[1] ? #2E9AFE : a < a[1] ? #e65100 : na)

//emas
slow_ema_period = input(20,"Slow EMA Period")
//avarage price (hlc3)
avg_price = input(hlc3)
//smothing
smooth_length = input(5, minval=1)
fast_end = input(2.5,step=.5)
slow_end = input(20)
//calculate noise
abs_noise = abs(avg_price - avg_price[1])
noise = sum(abs_noise, smooth_length)
//calculate signal
signal = abs(avg_price - avg_price[smooth_length])
//calculate smooth
smooth = pow(iff(noise != 0, signal / noise, 0) * (2/(fast_end + 1) - 2/(slow_end + 1)) + 2/(slow_end + 1), 2) 
//avarage moving avarage
avg_ma = nz(avg_ma[1]) + smooth * (avg_price - nz(avg_ma[1]))


ha_symbol = heikinashi(tickerid)
ha_close = security(ha_symbol, period, avg_ma)


slow_ema = ema(ha_close,slow_ema_period)

plot(long_step,title="LongStep",color=white,linewidth=2,style=line)
plot(slow_ema,title="SlowEMA",color=yellow,linewidth=2,style=line)

//Strategy
longCondition =  crossover(long_step,slow_ema) 
closeCondition = crossunder(long_step,slow_ema)

strategy.entry("long",strategy.long,when = longCondition)
strategy.close("long",when = closeCondition)
pine-script algorithmic-trading trading indicator
1个回答
0
投票

天哪,代码太乱了!我发现其中有两个问题。有相应的评论。不确定修补程序,但至少可以进行编译。还有一件事-不再支持pine v.1。而且调试该代码真的很困难。因此,我的友好建议是迁移到v4。

strategy("ABCSStrategy CUT long ",shorttitle="Step", overlay=true)
//resolutions
// FIRST there's something wrong with this input. It can't be used in crossover
long_step = 180 //input(title="long_step ", type=resolution, defval="180")
length = input(100),fast = input(50),slow = input(200),src = input(close)
//
er = abs(change(src,length))/sum(abs(change(src)),length)
dev = er*stdev(src*2,fast) + (1-er)*stdev(src*2,slow)
// SECOND: here was something wrong with `a`
a= src > nz(a[1],src) + dev ? src : src < nz(a[1],src) - dev ? src : nz(a[1],src)
//
css = fixnan(a > a[1] ? #2E9AFE : a < a[1] ? #e65100 : na)

//emas
slow_ema_period = input(20,"Slow EMA Period")
//avarage price (hlc3)
avg_price = input(hlc3)
//smothing
smooth_length = input(5, minval=1)
fast_end = input(2.5,step=.5)
slow_end = input(20)
//calculate noise
abs_noise = abs(avg_price - avg_price[1])
noise = sum(abs_noise, smooth_length)
//calculate signal
signal = abs(avg_price - avg_price[smooth_length])
//calculate smooth
smooth = pow(iff(noise != 0, signal / noise, 0) * (2/(fast_end + 1) - 2/(slow_end + 1)) + 2/(slow_end + 1), 2) 
//avarage moving avarage
avg_ma = nz(avg_ma[1]) + smooth * (avg_price - nz(avg_ma[1]))


ha_symbol = heikinashi(tickerid)
ha_close = security(ha_symbol, period, avg_ma)


slow_ema = ema(ha_close,slow_ema_period)

plot(long_step,title="LongStep",color=white,linewidth=2,style=line)
plot(slow_ema,title="SlowEMA",color=yellow,linewidth=2,style=line)

//Strategy
longCondition =  crossover(long_step,slow_ema) 
closeCondition = crossunder(long_step,slow_ema)

strategy.entry("long",strategy.long,when = longCondition)
strategy.close("long",when = closeCondition)
© www.soinside.com 2019 - 2024. All rights reserved.