Reputation: 135
I am new to pine-script and the documentation on tradingview isnt very clear. I am trying to calculate a the change of volume by the change of price. Here is my code:
V0 = volume
v1 = volume(1)
v2 = volume(2)
v3 = volume(3)
v4 = volume(4)
v5 = volume(5)
avgVol = (v1 + v2 + v3 + v4 + v5)/5
volChange = v0 - avgVol
volPercentage = volChange / avgVol
p0 = close
p1 = close(1)
priceChange = p0 - p1
priceChangePercentage = priceChange / p0
changePercentage = volPercentage * priceChangePercentage
study("My Script")
plot(changePercentage)
I am trying to refer to the data from past candles like ie: p = price(1), v1 = volume(5)
How is the syntax to do that? Please help! Thanks
Upvotes: 0
Views: 249
Reputation: 383
you should use brackets instead. For instance:
v1 = volume[1]
...
In addition, note that study()
must come before all the rest of the code.
I would like to add that the documentation does help a lot. Have a look here: Using series in Pine-script
Good luck!
Upvotes: 2