xmd79

Stationary Filtered Standing Wave with 2 filters

Apr 7th, 2023 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //@version=5
  2. indicator("Stationary Filtered Standing Wave", overlay=false)
  3.  
  4. inp = input(close)
  5.  
  6. // User-defined parameters
  7. len = input.int(title="Length", defval=50)
  8. freq = input.float(title="Frequency", defval=1.0)
  9.  
  10. // Calculate standing wave values
  11. wave = math.sin(2 * math.pi * freq * bar_index / len)
  12.  
  13. // Apply a stationary filter to smooth the wave and add close price
  14. filterLen = 5
  15. filterCoeff = 1.0 / filterLen
  16. filteredWave = filterCoeff * (wave + wave[1] + wave[2] + wave[3] + wave[4] + inp)
  17.  
  18. // Apply another filter using time cycles
  19. timeCycleLen = input.int(title="Time Cycle Length", defval=10)
  20. timeCycleCoeff = 1.0 / timeCycleLen
  21. timeCycle = 0.0
  22. for i = 0 to timeCycleLen - 1
  23. timeCycle := timeCycle + filteredWave[i]
  24. timeCycle := timeCycle / timeCycleLen
  25. filteredWave2 = timeCycleCoeff * (filteredWave + filteredWave[1] + filteredWave[2] + filteredWave[3] + filteredWave[4] - timeCycle * 5)
  26.  
  27. // Apply a third filter enforcing symmetry of trigo functions from unit circle
  28. symFilterLen = 3
  29. symFilterCoeff = 1.0 / symFilterLen
  30. symFilteredWave = symFilterCoeff * (filteredWave2 + filteredWave2[1] - filteredWave2[2])
  31.  
  32. // Plot the results
  33. plot(symFilteredWave, color=color.blue, linewidth=2)
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment