mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 18:18:04 +00:00
- 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.
57 lines
2.0 KiB
Plaintext
57 lines
2.0 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Zero-Lag Double EMA (ZLDEMA)", "ZLDEMA", overlay=true)
|
|
|
|
//@function Calculates ZLDEMA using zero-lag price and double exponential smoothing with compensator
|
|
//@param source Series to calculate ZLDEMA from
|
|
//@param period Smoothing period
|
|
//@param alpha Optional smoothing factor (overrides period if provided)
|
|
//@returns ZLDEMA value with zero-lag effect applied
|
|
//@optimized Uses lag compensation buffer and exponential warmup compensator on both EMA stages for O(1) complexity
|
|
zldema(series float source, simple int period=0, simple float alpha=0) =>
|
|
if alpha <= 0 and period <= 0
|
|
runtime.error("Alpha or period must be provided")
|
|
float a = alpha > 0 ? alpha : 2.0 / (period + 1)
|
|
float beta = 1.0 - a
|
|
simple int lag = math.max(1, math.round((period - 1) / 2))
|
|
var bool warmup = true
|
|
var float e = 1.0
|
|
var float ema1_raw = 0.0
|
|
var float ema2_raw = 0.0
|
|
var float ema1 = source
|
|
var float ema2 = source
|
|
var priceBuffer = array.new<float>(lag + 1, na)
|
|
if not na(source)
|
|
array.shift(priceBuffer)
|
|
array.push(priceBuffer, source)
|
|
float laggedPrice = nz(array.get(priceBuffer, 0), source)
|
|
float signal = 2 * source - laggedPrice
|
|
ema1_raw := a * (signal - ema1_raw) + ema1_raw
|
|
if warmup
|
|
e *= beta
|
|
float c = 1.0 / (1.0 - e)
|
|
ema1 := c * ema1_raw
|
|
ema2_raw := a * (ema1 - ema2_raw) + ema2_raw
|
|
ema2 := c * ema2_raw
|
|
warmup := e > 1e-10
|
|
else
|
|
ema1 := ema1_raw
|
|
ema2_raw := a * (ema1 - ema2_raw) + ema2_raw
|
|
ema2 := ema2_raw
|
|
2 * ema1 - ema2
|
|
else
|
|
na
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_period = input.int(10, "Period", minval=1)
|
|
i_source = input.source(close, "Source")
|
|
|
|
// Calculation
|
|
zldema_value = zldema(i_source, i_period)
|
|
|
|
// Plot
|
|
plot(zldema_value, "ZLDEMA", color=color.yellow, linewidth=2)
|