Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("MTF Stationary Cosine Wave Cycles", shorttitle="MTF Stationary Cosine Wave Cycles", overlay=false)
- // Inputs
- cycle_len_input = input.int(title="Cycle Length (bars)", defval=10)
- cycle_start_input = input.int(title="Cycle Start Bar Offset", defval=0)
- res_input = input.timeframe(title="Timeframe", defval="60")
- // Variables
- var int cycle_len = cycle_len_input
- var int cycle_start = cycle_start_input
- var string res = res_input
- // Compute stationary waves
- wave_phase_1 = 2 * math.pi * (bar_index - cycle_start) / cycle_len
- wave_value_1 = math.cos(wave_phase_1)
- wave_phase_2 = 2 * math.pi * (bar_index - cycle_start) / cycle_len - math.pi / 2
- wave_value_2 = math.cos(wave_phase_2)
- wave_phase_3 = 2 * math.pi * (bar_index - cycle_start) / cycle_len + math.pi / 2
- wave_value_3 = math.cos(wave_phase_3)
- wave_phase_4 = 2 * math.pi * (bar_index - cycle_start) / cycle_len + math.pi
- wave_value_4 = math.cos(wave_phase_4)
- // Plot stationary waves
- plot(wave_value_1, color=color.blue, linewidth=2)
- plot(wave_value_2, color=color.red, linewidth=2)
- plot(wave_value_3, color=color.orange, linewidth=2)
- plot(wave_value_4, color=color.green, linewidth=2)
- // Format
- bgcolor(color.new(color.black, 100))
Add Comment
Please, Sign In to add comment