2

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))
podolkerod
  • 95
  • 2
  • 8

1 Answers1

4

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
vitruvius
  • 15,740
  • 3
  • 16
  • 26