2

I am seeking for help with a pine script which is on version 2 right now but I am trying convert it into Version 5 and is having so many compilation errors.

Below is the complete script I am trying to convert from V2 to V5 and error I am facing. so please help me to correct the error. Thanks for your help

    study("BUY & SELL VOLUME TO PRICE PRESSURE by @XeL_Arjona", shorttitle="BSVP_XeL", precision=0)
signal = input(title="Base for FastMA Periods:", type=integer, defval=3)
long = input(title="Buy to Sell Conv/Div Lookback:", type=integer, defval=27)
vmacd = input(true, title="Buy to Sell Convergence/Div OSC:")
vinv = input(false, title="Buy to Sell Conv/Div as cummulative:")
norm = input(false, title="Normalised (Filtered) Version:")
//vapi = input(false, title="Display Acc/Dist % :")
vol = iff(volume > 0, volume , 1)
// PRESSURE ALGORITHMS AND VARIABLES
TR = atr(1)
Bull And Bear "Power-Balance" by Vadim Gimelfarb Algorithm's
BP =    iff(close<open,     iff(close[1]<open,  max(high-close[1], close-low), 
                                                    max(high-open, close-low)),
            iff(close>open,     iff(close[1]>open,  high-low, 
                                                    max(open-close[1], high-low)),
            iff(high-close>close-low, iff(close[1]<open,    max(high-close[1],close-low),
                                                            high-open),
            iff(high-close<close-low, iff(close[1]>open,    high-low,
                                                            max(open-close[1], high-low)),
            iff(close[1]>open,  max(high-open, close-low),
            iff(close[1]<open,  max(open-close[1], high-low),
        high-low))))))
SP =    iff(close<open,     iff(close[1]>open,  max(close[1]-open, high-low),
                                                    high-low),
            iff(close>open,     iff(close[1]>open,  max(close[1]-low, high-close),
                                                    max(open-low, high-close)),
            iff(high-close>close-low,   iff(close[1]>open,  max(close[1]-open, high-low),
                                                            high-low),
            iff(high-close<close-low,   iff(close[1]>open,  max(close[1]-low, high-close),
                                                            open-low),
            iff(close[1]>open,  max(close[1]-open, high-low),
            iff(close[1]<open,  max(open-low, high-close),
        high-low))))))
TP = BP+SP
// RAW Pressure Volume Calculations
BPV = (BP/TP)*vol
SPV = (SP/TP)*vol
TPV = BPV+SPV
BPVavg = ema(ema(BPV,signal),signal)
SPVavg = ema(ema(SPV,signal),signal)
TPVavg = ema(wma(TPV,signal),signal)
// Karthik Marar's Pressure Volume Normalized Version (XeL-MOD.)
VN = vol/ema(vol,long)
BPN = ((BP/ema(BP,long))*VN)*100
SPN = ((SP/ema(SP,long))*VN)*100
TPN = BPN+SPN
nbf = ema(wma(BPN,signal),signal)
nsf = ema(wma(SPN,signal),signal)
tpf = ema(wma(TPN,signal),signal)
ndif = nbf-nsf
// Conditional Selectors for RAW/Norm
BPc1 = BPV>SPV ? BPV : -abs(BPV)
BPc2 = BPN>SPN ? BPN : -abs(BPN)
SPc1 = SPV>BPV ? SPV : -abs(SPV)
SPc2 = SPN>BPN ? SPN : -abs(SPN)
BPcon = norm ? BPc2 : BPc1
SPcon = norm ? SPc2 : SPc1
BPAcon = norm ? nbf : BPVavg
SPAcon = norm ? nsf : SPVavg
TPAcon = norm ? tpf : TPVavg
// Volume Pressure Convergence Divergence by XeL_Arjona
vpo1 = vinv ? (( sum(BPVavg,long)-sum(SPVavg,long))/sum(TPVavg,long))*100 : ((BPVavg-SPVavg)/TPVavg)*100
vpo2 = vinv ? (( sum(nbf,long)-sum(nsf,long))/sum(tpf,long))*100 : ((nbf-nsf)/tpf)*100
vph = nz((vpo1 - vpo2),0)
// Plot Indicator
histC = vph > vph[1] ? blue:#BA00AA
Vpo1C = vpo1 > 0 ? green:red
Vpo2C = vpo2 > 0 ? green:red
plot(vmacd ? na:SPcon, color=red, title="SELLING", style=columns, linewidth=3, transp=80)
plot(vmacd ? na:BPcon, color=green, title="BUYING", style=columns, linewidth=3, transp=80)
plot(vmacd ? na:SPAcon, color=red, title="SPAvg", style=line, linewidth=2) //ema(BearPower*SPV,signal)
plot(vmacd ? na:BPAcon, color=green, title="BPAvg", style=line, linewidth=2) //ema(BullPower*BPV,signal)
plot(vmacd ? vpo1:na, color=Vpo1C,title="VPO1", style=line, linewidth=3)
plot(vmacd ? vpo2:na, color=Vpo2C,title="VPO2", style=line, linewidth=1)
plot(vmacd ? vph:na, color=histC, title="VPH", style=columns, linewidth=3, transp=90)
blackgreen
  • 34,072
  • 23
  • 111
  • 129
salem A
  • 21
  • 4

1 Answers1

0

the error was due to the syntax error for variables BP and SP once you shift it in one line it works and can be changed to v3 easily, after that you can use the inbuilt converter to convert it to v4 and v5, check out the migration guide. migration from v3 to v4 or v5, this post also guides the same How do I convert my pinescript v2 to pinescript v4?

//@version=5
indicator('BUY & SELL VOLUME TO PRICE PRESSURE by @XeL_Arjona', shorttitle='BSVP_XeL', precision=0)
signal = input(title='Base for FastMA Periods:', defval=3)
long = input(title='Buy to Sell Conv/Div Lookback:', defval=27)
vmacd = input(true, title='Buy to Sell Convergence/Div OSC:')
vinv = input(false, title='Buy to Sell Conv/Div as cummulative:')
norm = input(false, title='Normalised (Filtered) Version:')
//vapi = input(false, title="Display Acc/Dist % :")
vol = volume > 0 ? volume : 1
// PRESSURE ALGORITHMS AND VARIABLES
TR = ta.atr(1)
// Bull And Bear "Power-Balance" by Vadim Gimelfarb Algorithm's
iff_1 = close[1] < open ? math.max(high - close[1], close - low) : math.max(high - open, close - low)
iff_2 = close[1] > open ? high - low : math.max(open - close[1], high - low)
iff_3 = close[1] < open ? math.max(high - close[1], close - low) : high - open
iff_4 = close[1] > open ? high - low : math.max(open - close[1], high - low)
iff_5 = close[1] < open ? math.max(open - close[1], high - low) : high - low
iff_6 = close[1] > open ? math.max(high - open, close - low) : iff_5
iff_7 = high - close < close - low ? iff_4 : iff_6
iff_8 = high - close > close - low ? iff_3 : iff_7
iff_9 = close > open ? iff_2 : iff_8
BP = close < open ? iff_1 : iff_9
iff_10 = close[1] > open ? math.max(close[1] - open, high - low) : high - low
iff_11 = close[1] > open ? math.max(close[1] - low, high - close) : math.max(open - low, high - close)
iff_12 = close[1] > open ? math.max(close[1] - open, high - low) : high - low
iff_13 = close[1] > open ? math.max(close[1] - low, high - close) : open - low
iff_14 = close[1] < open ? math.max(open - low, high - close) : high - low
iff_15 = close[1] > open ? math.max(close[1] - open, high - low) : iff_14
iff_16 = high - close < close - low ? iff_13 : iff_15
iff_17 = high - close > close - low ? iff_12 : iff_16
iff_18 = close > open ? iff_11 : iff_17
SP = close < open ? iff_10 : iff_18
TP = BP + SP
// RAW Pressure Volume Calculations
BPV = BP / TP * vol
SPV = SP / TP * vol
TPV = BPV + SPV
BPVavg = ta.ema(ta.ema(BPV, signal), signal)
SPVavg = ta.ema(ta.ema(SPV, signal), signal)
TPVavg = ta.ema(ta.wma(TPV, signal), signal)
// Karthik Marar's Pressure Volume Normalized Version (XeL-MOD.)
VN = vol / ta.ema(vol, long)
BPN = BP / ta.ema(BP, long) * VN * 100
SPN = SP / ta.ema(SP, long) * VN * 100
TPN = BPN + SPN
nbf = ta.ema(ta.wma(BPN, signal), signal)
nsf = ta.ema(ta.wma(SPN, signal), signal)
tpf = ta.ema(ta.wma(TPN, signal), signal)
ndif = nbf - nsf
// Conditional Selectors for RAW/Norm
BPc1 = BPV > SPV ? BPV : -math.abs(BPV)
BPc2 = BPN > SPN ? BPN : -math.abs(BPN)
SPc1 = SPV > BPV ? SPV : -math.abs(SPV)
SPc2 = SPN > BPN ? SPN : -math.abs(SPN)
BPcon = norm ? BPc2 : BPc1
SPcon = norm ? SPc2 : SPc1
BPAcon = norm ? nbf : BPVavg
SPAcon = norm ? nsf : SPVavg
TPAcon = norm ? tpf : TPVavg
// Volume Pressure Convergence Divergence by XeL_Arjona
sum_1 = math.sum(BPVavg, long)
sum_2 = math.sum(SPVavg, long)
sum_3 = math.sum(TPVavg, long)
vpo1 = vinv ? (sum_1 - sum_2) / sum_3 * 100 : (BPVavg - SPVavg) / TPVavg * 100
sum_4 = math.sum(nbf, long)
sum_5 = math.sum(nsf, long)
sum_6 = math.sum(tpf, long)
vpo2 = vinv ? (sum_4 - sum_5) / sum_6 * 100 : (nbf - nsf) / tpf * 100
vph = nz(vpo1 - vpo2, 0)
// Plot Indicator
histC = vph > vph[1] ? color.blue : #BA00AA
Vpo1C = vpo1 > 0 ? color.green : color.red
Vpo2C = vpo2 > 0 ? color.green : color.red
plot(vmacd ? na : SPcon, color=color.new(color.red, 80), title='SELLING', style=plot.style_columns, linewidth=3)
plot(vmacd ? na : BPcon, color=color.new(color.green, 80), title='BUYING', style=plot.style_columns, linewidth=3)
plot(vmacd ? na : SPAcon, color=color.new(color.red, 0), title='SPAvg', style=plot.style_line, linewidth=2)  //ema(BearPower*SPV,signal)
plot(vmacd ? na : BPAcon, color=color.new(color.green, 0), title='BPAvg', style=plot.style_line, linewidth=2)  //ema(BullPower*BPV,signal)
plot(vmacd ? vpo1 : na, color=Vpo1C, title='VPO1', style=plot.style_line, linewidth=3)
plot(vmacd ? vpo2 : na, color=Vpo2C, title='VPO2', style=plot.style_line, linewidth=1)
plot(vmacd ? vph : na, color=histC, title='VPH', style=plot.style_columns, linewidth=3, transp=90)

green_ = Vpo1C == color.green and Vpo2C == color.green
red_ = Vpo1C == color.red and Vpo2C == color.red

plotshape(green_ and not green_[1] ? vmacd : na, text='Buy Signal', title='Buy Signal', location=location.absolute, style=shape.arrowup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.green, 0))
plotshape(red_ and not red_[1] ? vmacd : na, text='Sell Signal', title='Sell Signal', location=location.absolute, style=shape.arrowdown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.red, 0))

alertcondition(green_ and not green_[1], title='Buy Signal')  // location=location.absolute, style=shape.arrowup, size=size.tiny, color=green, textcolor=green)
alertcondition(red_ and not red_[1], title='Sell Signal')  //, location=location.absolute,  style=shape.arrowdown, size=size.tiny, color=red, textcolor=red)
TJalam
  • 308
  • 4
  • 16