[英]Convert strategy Pine script from v2 to v4 , did it, but got different and wrong results
[英]pine script how to convert Fractal indicator from v2 to v4
這是一個名為“分形支撐阻力”的開源指標。
//@version=2
//synapticex.com
study("Fractal Support Resistance", shorttitle="FSR", overlay=true)
tf = input(title="Resolution", type=resolution, defval = "current")
vamp = input(title="VolumeMA", type=integer, defval=6)
vam = sma(volume, vamp)
up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup = up ? high[3] : fractalup[1]
fractaldown = down ? low[3] : fractaldown[1]
fuptf = security(tickerid,tf == "current" ? period : tf, fractalup)
fdowntf = security(tickerid,tf == "current" ? period : tf, fractaldown)
plot(fuptf, "FractalUp", color=lime, linewidth=1, style=cross, transp=0, offset =-3, join=false)
plot(fdowntf, "FractalDown", color=red, linewidth=1, style=cross, transp=0, offset=-3, join=false)
你知道將其轉換為版本 4 嗎? 我把它改成這樣:
//@version=4
study("Fractal Support Resistance", shorttitle="FSR", overlay=true)
tf = input("current" , type = input.resolution )
vamp = input(6, type = input.integer)
vam = sma(volume, vamp)
up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup = up ? high[3] : fractalup[1]
fractaldown = down ? low[3] : fractaldown[1]
fuptf = security(tickerid,tf == "current" ? period : tf, fractalup)
fdowntf = security(tickerid,tf == "current" ? period : tf, fractaldown)
plot(fuptf, "FractalUp", color=lime, linewidth=1, style=cross, transp=0, offset =-3, join=false)
plot(fdowntf, "FractalDown", color=red, linewidth=1, style=cross, transp=0, offset=-3, join=false)
它給了我這個錯誤:
line 12: Undeclared identifier 'fractalup';
line 13: Undeclared identifier 'fractaldown';
line 15: Undeclared identifier 'tickerid';
line 15: Undeclared identifier 'period';
line 15: Undeclared identifier 'fractalup';
line 16: Undeclared identifier 'tickerid';
line 16: Undeclared identifier 'period';
line 16: Undeclared identifier 'fractaldown';
line 18: Undeclared identifier 'fuptf';
line 18: Undeclared identifier 'lime';
line 18: Undeclared identifier 'cross';
line 19: Undeclared identifier 'fdowntf';
line 19: Undeclared identifier 'red';
line 19: Undeclared identifier 'cross'
v2 中的標識符是否存在 v4 中不存在的默認值? 如果是,默認值是多少?
不再允許自引用。
所以,像下面這樣的陳述是無效的:
fractalup = up ? high[3] : fractalup[1]
您需要先聲明變量,然后在其上使用:=
賦值運算符:
fractalup = 0.0
fractalup := up ? high[3] : fractalup[1]
查看遷移指南了解更多信息。 將其轉換為 v3 后,您可以使用自動轉換器工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.