Advertisement
Guest User

Volatility

a guest
Feb 27th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Motgench
  3.  
  4. //@version=4
  5. study("Pig Downside Upside Volatility",precision=2)
  6. bgcolor(#000000c0)
  7.  
  8. Annual = input(365, "Annual")
  9. n = input(30, "Length")
  10. lambda = input(0.94, "lambda (EWMA)")
  11. xPrice = close - nz(close[1])
  12.  
  13. d = xPrice < 0 ? log(close/nz(close[1])) : 0
  14. v = 0.0
  15. v := lambda*nz(v[1])+ (1-lambda)*pow(d,2)
  16. dhv = sqrt(v)*sqrt(Annual)*100
  17.  
  18. u = xPrice > 0 ? log(close/nz(close[1])) : 0
  19. v2 = 0.0
  20. v2 := lambda*nz(v2[1])+(1-lambda)*pow(u,2)
  21. uhv = sqrt(v2)*sqrt(Annual)*100
  22.  
  23.  
  24. plot(dhv,color=color.red)
  25. plot(uhv,color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement