i am trying to write a script to get gann square of 9 levels. I have done it another languages but cant understand the pine script here it says Cannot modify global variable in function. Is there any solution to get the value here is my script
//@version=4
study(title="Volume-weighted average example", max_bars_back=5000, overlay=true)
timeDiff = time - time[4]
// Translate that time period into seconds
diffSeconds = timeDiff / 1000
// Output calculated time difference
//plot(series=diffSeconds)
var ln = 0
var wdvaltrg = 0.0
WdGann(price) =>
for i = 1 to 8
wdvaltrg := (ln+(1/i))*(ln+(1/i))
if wdvaltrg >= price
break
if wdvaltrg < price
ln := ln+1
WdGann(price)
var vwap0935 = 0.0
v = vwap
if hour == 9 and minute == 35
vwap0935 := v
plot(vwap0935)