xmd79

Stationary Filtered Standing Wave

Apr 7th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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. // Plot the results
  28. plot(filteredWave2, color=color.blue, linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment