Advertisement
PineCoders

Optimisation: Alma built-in vs Pine

Aug 31st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. //@version=4
  2. // The built-in is ~15x faster than the Pine version.
  3.  
  4. study("PP alma built-in vs usr function")
  5. s = close, l = 4, o = 0.85, g = 6, d = 1
  6.  
  7. pine_alma(series, windowsize, offset, sigma) =>
  8. m = floor(offset * (windowsize - 1))
  9. s = windowsize / sigma
  10. norm = 0.0
  11. sum = 0.0
  12. for i = 0 to windowsize - 1
  13. weight = exp(-1 * pow(i - m, 2) / (2 * pow(s, 2)))
  14. norm := norm + weight
  15. sum := sum + series[windowsize - i - 1] * weight
  16. sum / norm
  17.  
  18. a = 0.
  19. for i=1 to 9000
  20. // a := alma(s+i,l,o,g) //K iterations working: 5 15 25 50 100 125 140, Not working: 200 150 145 140
  21. a := pine_alma(s+i,l,o,g) //K iterations working: 5 7.5 8.5 9 // Not working: 125 25 15 10
  22. plot(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement