简体   繁体   中英

Convert Pine Script v1 to v4

Please see below an indicator I found on Trading View. My goal is to combine it with other indicators to develop a trading strategy. Since other indicators are made using the Pine Script version 4, I need to make sure that this indicator is compatible with version 4. When I add //@version=4 on top, it gives an error. It looks like there is something wrong. Could anybody please help me to fix this?

Thank you very much!

//@version=1

study(title="Bar Color", overlay = true)
src = close, len = input(11)
p1= ema(src,len)


ut   = close > p1 and close[1] > p1 
dt = close < p1 and close[1] < p1

uc = close > close[1] or high > high[1] and low > low[1]
dc = close < close[1] or high < high[1] and low < low[1]


showbar = (ut and uc) ? #00FFFF :
   (ut and dc) ? #00FFFF :
   (dt and dc) ? #FF0066 :
   (dt and uc) ? #FF0066 :
   na

barcolor(color=showbar)

Try to use the line 15 as one line

//@version=4

study(title="Bar Color", overlay = true)
src = close, len = input(11)
p1= ema(src,len)


ut   = close > p1 and close[1] > p1 
dt = close < p1 and close[1] < p1

uc = close > close[1] or high > high[1] and low > low[1]
dc = close < close[1] or high < high[1] and low < low[1]


showbar = (ut and uc) ? #00FFFF :   (ut and dc) ? #00FFFF :   (dt and dc) ? #FF0066 :   (dt and uc) ? #FF0066 :   na

barcolor(color=showbar)

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