Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Stationary Filtered Standing Wave", overlay=false)
- inp = input(close)
- // User-defined parameters
- len = input.int(title="Length", defval=50)
- freq = input.float(title="Frequency", defval=1.0)
- // Calculate standing wave values
- wave1 = math.sin(2 * math.pi * freq * bar_index / len)
- wave2 = math.sin(4 * math.pi * freq * bar_index / len)
- wave3 = math.sin(6 * math.pi * freq * bar_index / len)
- // Apply a stationary filter to smooth the wave and add close price
- filterLen = 5
- filterCoeff = 1.0 / filterLen
- filteredWave1 = filterCoeff * (wave1 + wave1[1] + wave1[2] + wave1[3] + wave1[4] + inp)
- filteredWave2 = filterCoeff * (wave2 + wave2[1] + wave2[2] + wave2[3] + wave2[4] + inp)
- filteredWave3 = filterCoeff * (wave3 + wave3[1] + wave3[2] + wave3[3] + wave3[4] + inp)
- // Convert the standing waves into oscillating waves
- osc1 = filteredWave1 - filteredWave1[1]
- osc2 = filteredWave2 - filteredWave2[1]
- osc3 = filteredWave3 - filteredWave3[1]
- // Apply a filter to smooth all series and get the best price reversals on this osc
- filterFreq = input.float(title="Filter Frequency", defval=0.5)
- filterWave = math.sin(2 * math.pi * filterFreq * bar_index / len)
- // Apply the filter wave as the midline for the next filter
- filterLen2 = 5
- filterCoeff2 = 1.0 / filterLen2
- filteredOsc = filterCoeff2 * (osc1 + osc2 + osc3 - 3 * filterWave * 5)
- // Plot the results
- plot(filteredOsc, color=color.blue, linewidth=2)
- midline = hline(0, title="Midline", linestyle=hline.style_dashed, linewidth=1, color=color.black)
- plot(osc1, title="Oscillating Wave 1", color=color.gray, linewidth=1, style=plot.style_circles)
- plot(osc2, title="Oscillating Wave 2", color=color.gray, linewidth=1, style=plot.style_circles)
- plot(osc3, title="Oscillating Wave 3", color=color.gray, linewidth=1, style=plot.style_circles)
Add Comment
Please, Sign In to add comment