xmd79

Stationary Filtered Standing Wave xxx

Apr 10th, 2023
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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. wave1 = math.sin(2 * math.pi * freq * bar_index / len)
  12. wave2 = math.sin(4 * math.pi * freq * bar_index / len)
  13. wave3 = math.sin(6 * math.pi * freq * bar_index / len)
  14.  
  15. // Apply a stationary filter to smooth the wave and add close price
  16. filterLen = 5
  17. filterCoeff = 1.0 / filterLen
  18. filteredWave1 = filterCoeff * (wave1 + wave1[1] + wave1[2] + wave1[3] + wave1[4] + inp)
  19. filteredWave2 = filterCoeff * (wave2 + wave2[1] + wave2[2] + wave2[3] + wave2[4] + inp)
  20. filteredWave3 = filterCoeff * (wave3 + wave3[1] + wave3[2] + wave3[3] + wave3[4] + inp)
  21.  
  22. // Convert the standing waves into oscillating waves
  23. osc1 = filteredWave1 - filteredWave1[1]
  24. osc2 = filteredWave2 - filteredWave2[1]
  25. osc3 = filteredWave3 - filteredWave3[1]
  26.  
  27. // Apply a filter to smooth all series and get the best price reversals on this osc
  28. filterFreq = input.float(title="Filter Frequency", defval=0.5)
  29. filterWave = math.sin(2 * math.pi * filterFreq * bar_index / len)
  30.  
  31. // Apply the filter wave as the midline for the next filter
  32. filterLen2 = 5
  33. filterCoeff2 = 1.0 / filterLen2
  34. filteredOsc = filterCoeff2 * (osc1 + osc2 + osc3 - 3 * filterWave * 5)
  35.  
  36. // Plot the results
  37. plot(filteredOsc, color=color.blue, linewidth=2)
  38. midline = hline(0, title="Midline", linestyle=hline.style_dashed, linewidth=1, color=color.black)
  39. plot(osc1, title="Oscillating Wave 1", color=color.gray, linewidth=1, style=plot.style_circles)
  40. plot(osc2, title="Oscillating Wave 2", color=color.gray, linewidth=1, style=plot.style_circles)
  41. plot(osc3, title="Oscillating Wave 3", color=color.gray, linewidth=1, style=plot.style_circles)
  42.  
Add Comment
Please, Sign In to add comment