Advertisement
Guest User

Standard Deviation

a guest
Feb 16th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. //@version=4
  2. study("Standard Deviation",shorttitle="Stdev")
  3. length = input(1024)
  4. //Trading view method
  5. a = sma(pow(close,2),length)
  6. b = pow(sum(close,length),2)/pow(length,2)
  7. c = sqrt(a - b)
  8.  
  9.  
  10. //Tradingview method Confirm
  11. d=stdev(close,length)
  12.  
  13. //Direct method
  14. dev = close - sma(close, length)
  15. variance = sum(pow(dev, 2), length) / (length -1)
  16. e=sqrt(variance)
  17.  
  18. //Direction method function
  19. sd(src, length) =>
  20. deviation = src - sma(src, length)
  21. variance = sum(pow(deviation, 2), length) / (length)
  22. sd=sqrt(variance)
  23.  
  24. //Tradingview method function
  25. st_dev(Series, Period) =>
  26. E_1 = 0.0, E_2 = 0.0
  27. for i=0 to Period-1
  28. previousSeries = nz(Series[i])
  29. E_1 := E_1 + previousSeries
  30. E_2 := E_2 + previousSeries * previousSeries
  31. return = sqrt(E_2 / Period - (E_1 * E_1) / (Period * Period))
  32.  
  33. plot(c,color=color.red)
  34. plot(d,color=color.green)
  35. plot(e,color=color.aqua)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement