简体   繁体   中英

How to convert to Pine Script v4 or v5

I am trying to publish this script on trading view but i keep getting an error stating that i need to convert it to pine script v4 or v5 to publish it. I have tried to add //version=5, or //version=4 to the beginning of the code, but I still have no success and end up getting error codes instead.

timeinrange(res, sess) => time(res, sess) != 0

// **** Checkboxes and custom Session
iKZNY = input(true, title="New York Kill Zone")
iOpenKZLondon = input(true, title="London Open Kill Zone")
iCloseKZLondon = input(true, title="London Close Kill Zone")
iAsiaKZ = input(true, title="Asia Kill Zone")
KZNY = input('1230-1430', type=session, title="New York Kill Zone")
LondonOpenKZ = input('0600-1000', type=session, title="London Open Kill Zone")
LondonCloseKZ = input('1500-1700', type=session, title="London Close Kill Zone")
AsiaKZ = input('2300-0300', type=session, title="Asia Kill Zone")

iRealOpenSessionAlertBar = input(true, title="Real Open Session Alert Bar")
NYOpenAlertBar = input('1330-1345', type=session, title="New York Open Session")
LondonOpenAlertBar = input('0700-0715', type=session, title="London Open Session")
LondonCloseAlertBar = input('1545-1600', type=session, title="London Close Session")
AsiaOpenAlertBar = input('0000-0015', type=session, title="Asia Open Session")

// **** Logic
sessToUse = iKZNY == 1 ? KZNY : '0000-0000'
sessToUse2 = iRealOpenSessionAlertBar == 1 ? NYOpenAlertBar : '0000-0000'
sessToUse3 = iOpenKZLondon == 1 ? LondonOpenKZ : '0000-0000'
sessToUse4 = iRealOpenSessionAlertBar == 1 ? LondonOpenAlertBar : '0000-0000'
sessToUse5 = iCloseKZLondon == 1 ? LondonCloseKZ : '0000-0000'
sessToUse6 = iRealOpenSessionAlertBar == 1 ? LondonCloseAlertBar : '0000-0000'
sessToUse7 = iAsiaKZ == 1 ? AsiaKZ : '0000-0000'
sessToUse8 = iRealOpenSessionAlertBar == 1 ? AsiaOpenAlertBar : '0000-0000'

// *** Apply custom rules
bgPlot = (iKZNY == 0 ? time(period) : time(period, sessToUse)) 
bgPlot2 = (iRealOpenSessionAlertBar == 0 ? time(period) : time(period, sessToUse2)) 
bgPlot3 = (iOpenKZLondon == 0 ? time(period) : time(period, sessToUse3)) 
bgPlot4 = (iRealOpenSessionAlertBar == 0 ? time(period) : time(period, sessToUse4)) 
bgPlot5 = (iCloseKZLondon == 0 ? time(period) : time(period, sessToUse5)) 
bgPlot6 = (iRealOpenSessionAlertBar == 0 ? time(period) : time(period, sessToUse6)) 
bgPlot7 = (iAsiaKZ == 0 ? time(period) : time(period, sessToUse7))
bgPlot8 = (iRealOpenSessionAlertBar == 0 ? time(period) : time(period, sessToUse8))

//**** Plot as background
bgcolor(iKZNY and bgPlot > 0 ? red : na, transp=90) 
bgcolor(iKZNY and iRealOpenSessionAlertBar and bgPlot2 > 0 ? red : na, transp=70) 
bgcolor(iOpenKZLondon and bgPlot3 > 0 ? green : na, transp=90) 
bgcolor(iOpenKZLondon and iRealOpenSessionAlertBar and bgPlot4 > 0 ? green : na, transp=70) 
bgcolor(iCloseKZLondon and bgPlot5 > 0 ? olive : na, transp=90) 
bgcolor(iCloseKZLondon and iRealOpenSessionAlertBar and bgPlot6 > 0 ? olive : na, transp=70) 
bgcolor(iAsiaKZ and bgPlot7 > 0 ? orange : na, transp=90) 
bgcolor(iAsiaKZ and iRealOpenSessionAlertBar and bgPlot8 > 0 ? orange : na, transp=70)```

Adding //@version=5 does not magically convert a script to v5. Many things have changed/renamed since the early versions.

Start with //@version=3 first and then when it is working use the auto converter tool.

在此处输入图像描述

Also, here is your migration guide .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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