Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Motgench
- //@version=4
- study("Pig Downside Upside Volatility",precision=2)
- bgcolor(#000000c0)
- Annual = input( 365, "Annual")
- n = input( 30, "Length")
- lambda = input(0.94, "lambda (EWMA)", step=0.01)
- oneMinusLambda = 1.0 - lambda
- priorClose = nz(close[1], close) // nz() replaces na with 0.0, added ", close)" Divide by zero situation combined with #2
- xPrice = close - priorClose
- logCloseDividedPriorCLose = log(close / priorClose) // #2
- d = xPrice<0.0 ? logCloseDividedPriorCLose : 0.0 // Less than: xPrice < ...
- v = 0.0
- v := lambda * nz(v[1]) + oneMinusLambda * pow(d, 2)
- dhv = sqrt(v) * sqrt(Annual) * 100.0
- u = xPrice>0.0 ? logCloseDividedPriorCLose : 0.0 // Greater than: xPrice > ...
- v2 = 0.0
- v2 := lambda * nz(v2[1]) + oneMinusLambda * pow(u, 2)
- uhv = sqrt(v2) * sqrt(Annual) * 100.0
- plot(dhv, color=color.red)
- plot(uhv, color=color.green) // Was causing na for eternity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement