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
- wave = math.sin(2 * math.pi * freq * bar_index / len)
- // Apply a stationary filter to smooth the wave and add close price
- filterLen = 5
- filterCoeff = 1.0 / filterLen
- filteredWave = filterCoeff * (wave + wave[1] + wave[2] + wave[3] + wave[4] + inp)
- // Apply another filter using time cycles
- timeCycleLen = input.int(title="Time Cycle Length", defval=10)
- timeCycleCoeff = 1.0 / timeCycleLen
- timeCycle = 0.0
- for i = 0 to timeCycleLen - 1
- timeCycle := timeCycle + filteredWave[i]
- timeCycle := timeCycle / timeCycleLen
- filteredWave2 = timeCycleCoeff * (filteredWave + filteredWave[1] + filteredWave[2] + filteredWave[3] + filteredWave[4] - timeCycle * 5)
- // Plot the results
- plot(filteredWave2, color=color.blue, linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment