Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Harmonic Sine Waves", overlay=true)
- // Define pi constant
- pi = 3.141592653589793
- // User Input: Length of wave
- length = input(title="Length", type=input.integer, defval=40)
- // User Input: Amplitude, Offset, and Phase Shift of Base Sine Wave
- amp = input(title="Base Amplitude", type=input.float, defval=1.0)
- offset = input(title="Base Offset", type=input.float, defval=0.0)
- phase_shift = input(title="Base Phase Shift", type=input.float, defval=0.0)
- // Draw base sine wave
- base = amp * sin(2 * pi * (bar_index + phase_shift) / length) + offset
- plot(base, color=color.blue, linewidth=2, title="Base Sine Wave")
- // Draw 3 harmonic sine waves
- h1 = 2 * base * sin(2 * pi * (bar_index + phase_shift) / (length / 2))
- h2 = base / 2 * sin(2 * pi * (bar_index + phase_shift) / (length * 2))
- h3 = base / 4 * sin(2 * pi * (bar_index + phase_shift) / (length * 4))
- plot(h1, color=color.red, linewidth=2, title="Harmonic Sine Wave 1")
- plot(h2, color=color.green, linewidth=2, title="Harmonic Sine Wave 2")
- plot(h3, color=color.orange, linewidth=2, title="Harmonic Sine Wave 3")
- // Sum all sine waves
- sum_wave = base + h1 + h2 + h3
- plot(sum_wave, color=color.rgb(54, 69, 56), linewidth=2, title="Sum of All Sine Waves")
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © bartekhl
- //@version=5
- plot(close)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement