Files
QuanTAlib/quantower/lib/sine.pine
T
Miha Kralj 24e86d762a Add documentation links for various volatility indicators and channels
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links.
- Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
2026-02-18 11:55:48 -08:00

48 lines
1.9 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Ehlers Sine Wave (SINE)", "SINE", overlay=false)
//@function Calculates Ehlers original Sine Wave using a twopole HighPass, a SuperSmoother,
// and a Hilberttransform FIR pair (InphaseI / QuadratureQ).
//@param src Series to calculate the Sine Wave from
//@param hpLength HighPass filter length (detrending period)
//@param ssfLength SuperSmoother filter length (cycle smoothing period)
//@returns single normalized sinewave value in [1 … +1]
sine(series float src, simple int hpLength, simple int ssfLength) =>
if hpLength <= 0 or ssfLength <= 0
runtime.error("Periods must be >0")
float pi = 2 * math.asin(1)
float angHP = 2 * pi / hpLength
float aHP = (1 - math.sin(angHP)) / math.cos(angHP)
var float hp = 0.0
hp := 0.5 * (1 + aHP) * (src - nz(src[1])) + aHP * nz(hp[1])
float angSSF = math.sqrt(2) * pi / ssfLength
float aSSF = math.exp(-angSSF)
float bSSF = 2 * aSSF * math.cos(angSSF)
float c2 = bSSF
float c3 = -aSSF * aSSF
float c1 = 1 - c2 - c3
var float filt = 0.0
filt := c1 * (hp + nz(hp[1])) / 2 + c2 * nz(filt[1]) + c3 * nz(filt[2])
float Q = 0.0962 * nz(filt[3]) + 0.5769 * nz(filt[1])
- 0.5769 * nz(filt[5]) - 0.0962 * nz(filt[7])
float I = filt
float pwr = I*I + Q*Q
float sineWave = pwr == 0 ? 0 : I / math.sqrt(pwr)
math.min(1, math.max(-1, sineWave))
// ---------- Main loop ----------
// Inputs
i_source = input.source(close, "Source")
i_hpLength = input.int(40, "HighPass Filter Length", minval=1)
i_ssfLength = input.int(10, "SuperSmoother Filter Length", minval=1)
// Calculation
sine_wave = sine(i_source, i_hpLength, i_ssfLength)
// Plot
plot(sine_wave, "SINE", color=color.yellow, linewidth=2)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dashed)