简体   繁体   English

如何将我的 pinescript v2 转换为 pinescript v4?

[英]How do I convert my pinescript v2 to pinescript v4?

I have a pinescript v2 that needs to be converted to v4, but I still haven't understood how, any inputs will be useful, thanks.我有一个需要转换为 v4 的 pinescript v2,但我仍然不明白如何,任何输入都会有用,谢谢。 This script was developed a long time back and visiting it now is confusing me.这个脚本是很久以前开发的,现在访问它让我感到困惑。 I have been reading that the variables need to be declared first, I get that, but what is the most efficient way to convert this into v4 of pine?我一直在阅读需要首先声明变量,我明白了,但是将其转换为松树 v4 的最有效方法是什么?

//@version=2
study(title="SuperTrend Oscillator",shorttitle="STO",overlay=false)
//Inputs
spt_ures=input(false,title="Use Cutsom Resolution?")
spt_res=input(type=resolution,defval="M")
spt_lenw=input(200,title="Length Of Warning Range")
spt_len=input(14,title="SuperTrend Length")
spt_mult=input(1,title="SuperTrend Multiple")
spt_ubc=input(true,title="Use Barcolors?")
colup=green
coldn=red
//SuperTrend
spt_atr=atr(spt_len)
spt_nsb=hl2+spt_atr*spt_mult
spt_nlb=hl2-spt_atr*spt_mult
spt_lb=close[1]>spt_lb[1]?max(spt_nlb,spt_lb[1]):spt_nlb
spt_sb=close[1]<spt_sb[1]?min(spt_nsb,spt_sb[1]):spt_nsb
spt_tdur=close>spt_sb[1]?1:close<spt_lb[1]?-1:nz(spt_tdur[1],1)
spt_td=spt_ures?(security(tickerid,spt_res,spt_tdur)):spt_tdur
spt_lvlur=(close-(spt_td==1?spt_lb:spt_sb))
spt_lvl=spt_ures?(security(tickerid,spt_res,spt_lvlur)):spt_lvlur
//Components
spt_lvlup=spt_td==1?spt_lvl:na
spt_lvldn=spt_td==-1?spt_lvl:na
spt_tdup=(spt_td==1)and(spt_td[1]==-1)
spt_tddn=(spt_td==-1)and(spt_td[1]==1)
spt_tr=spt_ures?(security(tickerid,spt_res,tr)):tr
spt_matr=sma(abs(spt_lvl),200)
spt_cls=spt_ures?(security(tickerid,spt_res,close)):close
spt_lvlwup=(spt_lvlup<spt_matr)and(spt_cls<spt_cls[1])
spt_lvlwdn=(spt_lvldn>-spt_matr)and(spt_cls>spt_cls[1])
//Color
spt_col=spt_td==1?colup:coldn
spt_colbar=(spt_td==1)and(spt_lvlwup)?#A7D1AA:(spt_td==-1)and(spt_lvlwdn)?#D1A7AE:spt_td==1?colup:coldn
spt_colhst=spt_tdup?colup:spt_tddn?coldn:spt_lvlwdn?colup:spt_lvlwup?coldn:na
//Plot
p0=plot(0,color=spt_col,style=line,linewidth=1,transp=0,title="Midline")
p1=plot(spt_lvlup,color=colup,style=linebr,linewidth=1,transp=0,title="Uptrend Line")
p2=plot(spt_lvldn,color=coldn,style=linebr,linewidth=1,transp=0,title="Downtrend Line")
plot(spt_lvl,color=spt_colhst,style=histogram,linewidth=3,transp=0,title="Trend Change")
plot(spt_lvl,color=spt_colhst,style=circles,linewidth=2,transp=0,title="Trend Change")
fill(p0,p1,color=colup,transp=90)
fill(p0,p2,color=red,transp=90)
barcolor(spt_ubc?spt_colbar:na)

Take a look at the v2 to v3 migration guide first, once your script is v3 compatible you can often juste use the v4, you can also use the "convert to v4" option.首先查看 v2 到 v3 迁移指南,一旦您的脚本与 v3 兼容,您通常可以只使用 v4,也可以使用“转换为 v4”选项。

在此处输入图像描述

You're in luck because Pine v4 now has a supertrend() built-in .您很幸运,因为 Pine v4 现在内置了supertrend()

You will also want to look into How to avoid repainting when using security() - PineCoders FAQ to avoid the lookahead bias that v2 is suffering from.您还需要查看使用 security() 时如何避免重绘 - PineCoders 常见问题解答以避免 v2 遭受的前瞻偏差。

That should give you a head start.这应该给你一个良好的开端。 If you get stuck along the way and you can post your code, let us know.如果您在此过程中遇到困难并且可以发布您的代码,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM