Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Tradingview - Pine Script) Convert iff Function to v5 error

I tried to convert pine v2 iff function to v5 but I kept getting this error:

line 32: Undeclared identifier 'vwapsum';
line 33: Undeclared identifier 'volumesum';
line 34: Undeclared identifier 'v2sum'

this one is original v2 script:

newSession = iff(change(start), 1, 0)
vwapsum = iff(newSession, hl2*volume, vwapsum[1]+hl2*volume)
volumesum = iff(newSession, volume, volumesum[1]+volume)
v2sum = iff(newSession, volume*hl2*hl2, v2sum[1]+volume*hl2*hl2)
myvwap = vwapsum/volumesum
dev = sqrt(max(v2sum/volumesum - myvwap*myvwap, 0))

and this is one v5 that I tried to create but give an error

newSession = ta.change(start) ? 1 : 0
vwapsum     = newSession    ?   hl2*volume      : vwapsum[1]+hl2*volume
volumesum   = newSession    ?   volume          : volumesum[1]+volume
v2sum       = newSession    ?   volume*hl2*hl2  : v2sum[1]+volume*hl2*hl2
myvwap      = vwapsum/volumesum
dev         = math.sqrt(math.max(v2sum/volumesum - myvwap*myvwap, 0))
like image 793
podolkerod Avatar asked Nov 02 '25 17:11

podolkerod


1 Answers

Your conversion is correct, however, there is one more change you need to know when upgrading from v2. That is, you cannot use any variable in calculations while you are declaring that variable. So, you need to declare it first then give it a new value.

float vwapsum = 0.0
vwapsum := newSession ? hl2*volume : vwapsum[1]+hl2*volume
like image 83
vitruvius Avatar answered Nov 04 '25 12:11

vitruvius