Advertisement
kocurekc

Pine Script, Yang-Zhang Volatility

Apr 22nd, 2014
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. study("Yang-Zhang Volatility")
  2. // Yang-Zhang Volatility
  3. // source: http://http://www.todaysgroep.nl/media/236846/measuring_historic_volatility.pdf
  4. //
  5. // Rewrite for Tradingview "Pine Script" by Kocurekc, April 2014
  6. // https://getsatisfaction.com/tradingview/
  7. // https://www.tradingview.com/u/kocurekc/
  8. // Code is provided as public domain, no warranty
  9.  
  10. len = input(title="Lookback Period", type=integer, defval=14, minval=2)
  11.  
  12. F = 1
  13. A = log(high/close)
  14. B = log(high/open)
  15. C = log(low/close)
  16. D = log(low/open)
  17.  
  18. sigRS = pow(sum(A*B + C*D,len)/len,0.5)
  19.  
  20. k=0.34/(1.34 + (len+1)/(len-1))
  21. OC1 = log(open/close[1])
  22. CO = log(close/open)
  23. sigOV = (1/(len-1))*sum(pow(OC1 - sma(OC1,len),2),len)
  24. sigOC = (1/(len-1))*sum(pow(CO - sma(CO,len),2),len)
  25.  
  26.  
  27. sigYC = pow((sigOV + k*sigOC + (1 - k)*sigRS),0.5)
  28.  
  29. hline(0.1, linestyle=dashed)
  30. plot(sigYC)
  31. plot(ema(sigYC,14))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement