xmd79

MTF Stationary Cosine Wave Cycles

May 25th, 2023
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. //@version=5
  2. indicator("MTF Stationary Cosine Wave Cycles", shorttitle="MTF Stationary Cosine Wave Cycles", overlay=false)
  3.  
  4. // Inputs
  5. cycle_len_input = input.int(title="Cycle Length (bars)", defval=10)
  6. cycle_start_input = input.int(title="Cycle Start Bar Offset", defval=0)
  7. res_input = input.timeframe(title="Timeframe", defval="60")
  8.  
  9. // Variables
  10. var int cycle_len = cycle_len_input
  11. var int cycle_start = cycle_start_input
  12. var string res = res_input
  13.  
  14. // Compute stationary waves
  15. wave_phase_1 = 2 * math.pi * (bar_index - cycle_start) / cycle_len
  16. wave_value_1 = math.cos(wave_phase_1)
  17.  
  18. wave_phase_2 = 2 * math.pi * (bar_index - cycle_start) / cycle_len - math.pi / 2
  19. wave_value_2 = math.cos(wave_phase_2)
  20.  
  21. wave_phase_3 = 2 * math.pi * (bar_index - cycle_start) / cycle_len + math.pi / 2
  22. wave_value_3 = math.cos(wave_phase_3)
  23.  
  24. wave_phase_4 = 2 * math.pi * (bar_index - cycle_start) / cycle_len + math.pi
  25. wave_value_4 = math.cos(wave_phase_4)
  26.  
  27. // Plot stationary waves
  28. plot(wave_value_1, color=color.blue, linewidth=2)
  29. plot(wave_value_2, color=color.red, linewidth=2)
  30. plot(wave_value_3, color=color.orange, linewidth=2)
  31. plot(wave_value_4, color=color.green, linewidth=2)
  32.  
  33. // Format
  34. bgcolor(color.new(color.black, 100))
  35.  
  36.  
Add Comment
Please, Sign In to add comment