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)")
- xPrice = close - nz(close[1])
- d = xPrice < 0 ? log(close/nz(close[1])) : 0
- v = 0.0
- v := lambda*nz(v[1])+ (1-lambda)*pow(d,2)
- dhv = sqrt(v)*sqrt(Annual)*100
- u = xPrice > 0 ? log(close/nz(close[1])) : 0
- v2 = 0.0
- v2 := lambda*nz(v2[1])+(1-lambda)*pow(u,2)
- uhv = sqrt(v2)*sqrt(Annual)*100
- plot(dhv,color=color.red)
- plot(uhv,color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement