Hello,
I’m writing a script to measure a long chunk of volatility to find out if the current volatility is high or low.
With one twist: At “1”, the indicator should be showing that we are at 100% normal historical volatility.
I have managed to calculate historical volatility, but I can’t make the indicator display the data in the form of “1” = 100% of normal historical volatility.
Here’s my ProRealTime code:
b = summation[24](TR(close))
c = 0.0
FOR i = 24 TO 1200 DO
c = b[i] + c
NEXT
d = c / 50
volat = b / d
Also, not sure if it helps, but I did manage to make it work properly in “PineScript”.
Here is the working snippet in PineScript:
b = sum(atr(1),24)
c = 0.0
for i = 24 to 1200 by +24
c := b[i] + c
d = c / 50
vol = b / d
I would appreciate your help A LOT to make the ProRealTime code version work.
Thank you.
Line 1 in Pinescript code reads ATR (AverageTrueRange in PRT), while you wrote TR which is True Range.
Can this be the source of your problem?
Already tried that, and it didn’t fix the issue, unfortunately.
My guess is that the issue has something to do with the “By” element in the loop, which is present in the PineScript version, but not in my PRT code.
I could not find any “By” equivalent for PRT…
Did you know that ProBuilder has an historical volatility instruction? It might help!
Yeah, I’ve tried it. But I couldn’t figure out how to use it for readings in the form that I need them.
I need an indicator that shows where volatility currently is in comparison to the historical average.
e.g. if the indicator gives a “0.5” reading, it should mean that volatility is currently 50% below historical average. If the indicator gives a “1.0” reading, it should mean that volatility is currently at the exact historical average. And so on…
Do you know how I could do this?
My guess – not tested.
b = 0
for i = 1 to 24
b = b + averagetruerange[i](close)
next
c = 0
FOR i = 1 TO 50
ii= i*24
c = b[ii] + c
NEXT
d = c / 50
volat = b / d
You have to normalize the value in order to make a fixed scale.
Thanks Vonasi, that worked!