Loop to calculate historical volatility
Forums › ProRealTime English forum › ProBuilder support › Loop to calculate historical volatility
- This topic has 7 replies, 4 voices, and was last updated 4 years ago by pascaltmn.
-
-
03/05/2020 at 8:39 AM #121195
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:
Historical volatility123456789b = summation[24](TR(close))c = 0.0FOR i = 24 TO 1200 DOc = b[i] + cNEXTd = c / 50volat = b / dAlso, not sure if it helps, but I did manage to make it work properly in “PineScript”.
Here is the working snippet in PineScript:
Pinescript version of what I need1234567b = sum(atr(1),24)c = 0.0for i = 24 to 1200 by +24c := b[i] + cd = c / 50vol = b / dI would appreciate your help A LOT to make the ProRealTime code version work.
Thank you.
03/05/2020 at 9:17 AM #121199Line 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?
03/05/2020 at 9:27 AM #121200Already 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…
03/05/2020 at 9:29 AM #121201Did you know that ProBuilder has an historical volatility instruction? It might help!
03/05/2020 at 9:38 AM #121203Yeah, 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?
03/05/2020 at 9:53 AM #12120603/05/2020 at 9:54 AM #12120703/05/2020 at 11:50 AM #121226 -
AuthorPosts
Find exclusive trading pro-tools on