Files
QuanTAlib/lib/oscillators/qqe/Qqe.md
T
Miha Kralj 90d5638008 Add new moving average implementations: LTMA, MCNMA, NLMA, NMA, NYQMA, RAIN, and TRAMA
- LTMA (Linear Trend Moving Average): Introduces a predictive moving average using dual cascaded EMAs for trend estimation.
- MCNMA (McNicholl EMA): Implements a zero-lag TEMA using a cascaded EMA structure for enhanced responsiveness.
- NLMA (Non-Lag Moving Average): Utilizes a damped cosine kernel to achieve reduced lag in moving averages.
- NMA (Natural Moving Average): Adapts smoothing based on volatility profiles using a square-root kernel.
- NYQMA (Nyquist Moving Average): Applies the Nyquist-Shannon theorem to prevent aliasing in cascaded moving averages.
- RAIN (Rainbow Moving Average): Combines multiple SMA layers with weighted averages for multi-scale smoothing.
- TRAMA (Trend Regularity Adaptive Moving Average): Adapts smoothing based on the frequency of new highs and lows in price data.
2026-02-20 21:40:32 -08:00

4.1 KiB
Raw Blame History

QQE: Quantitative Qualitative Estimation

Quantitative Qualitative Estimation applies a multi-stage smoothing pipeline to RSI and then constructs dynamic volatility-based trailing bands around the smoothed result. The output is a dual-line system: the QQE line (smoothed RSI) and a trailing level that follows price directionally, similar to Parabolic SAR logic. Crossovers between the QQE line and its trailing level signal momentum shifts, while crossovers of the QQE line above and below 50 indicate trend direction. The trailing level adapts to volatility through a double-EMA of RSI absolute changes, making band width contract in quiet markets and expand during volatile conditions.

Historical Context

QQE emerged from the forex trading community in the mid-2000s, attributed to an anonymous developer and popularized through MetaTrader forums. The indicator extends Wilder's RSI concept by addressing two of its primary limitations: noise in the RSI signal and fixed overbought/oversold thresholds. The first problem is solved by EMA smoothing of the RSI output; the second by replacing static thresholds with adaptive trailing bands derived from RSI volatility. The "Quantitative Qualitative" name reflects the dual nature of the system: the quantitative RSI measurement combined with qualitative trend-following logic in the trailing level. The trailing level mechanism borrows from Welles Wilder's Parabolic SAR: it follows the smoothed RSI directionally, only reversing when the RSI breaks through. The default QQE factor of 4.236 (the square of the golden ratio \phi^2 = 2.618... \times 1.618...) has no documented mathematical justification but has become canonical through widespread adoption.

Architecture & Physics

Four-Stage Pipeline

  1. Stage 1: Wilder RSI via RMA (\alpha = 1/\text{rsiPeriod}) with warmup compensation. The exponential decay factor e = \beta^n tracks convergence, applying correction c = 1/(1-e) until e < 10^{-10}.

  2. Stage 2: EMA smoothing of RSI (\alpha = 2/(\text{SF}+1)) with the same warmup compensation. Produces rsiMA, the primary QQE line.

  3. Stage 3: Dynamic Average Range (DAR). Computes |\Delta \text{rsiMA}| bar-to-bar, then applies two consecutive EMAs with period 2 \times \text{SF} - 1. Both EMAs use warmup compensation. The double smoothing produces a stable volatility estimate analogous to ATR but operating on the RSI domain.

  4. Stage 4: Trailing level. Constructs upper/lower bands at \text{rsiMA} \pm \text{qqeFactor} \times \text{DAR}. The trailing logic follows directionally:

    • If rsiMA is above the trail and was above previously: trail = max(trail, lowerBand) (ratchets up)
    • If rsiMA is below the trail and was below previously: trail = min(trail, upperBand) (ratchets down)
    • On crossover: trail flips to the opposite band

Mathematical Foundation

Stage 1: RSI (\alpha_r = 1/p_r, \beta_r = 1 - \alpha_r):

\hat{G}_t = \beta_r \hat{G}_{t-1} + \alpha_r \max(\Delta x_t, 0), \quad e_r = \beta_r^t RSI_t = \frac{100 \cdot \hat{G}_t / (1-e_r)}{\hat{G}_t/(1-e_r) + \hat{L}_t/(1-e_r)}

Stage 2: EMA of RSI (\alpha_s = 2/(SF+1)):

\hat{M}_t = \beta_s \hat{M}_{t-1} + \alpha_s \cdot RSI_t, \quad rsiMA_t = \hat{M}_t / (1 - \beta_s^t)

Stage 3: Double EMA of |delta| (\alpha_d = 2/(2 \cdot SF)):

D_t = |rsiMA_t - rsiMA_{t-1}| \hat{d}_1 = \beta_d \hat{d}_1 + \alpha_d D_t, \quad dar_1 = \hat{d}_1 / (1 - \beta_d^t) \hat{d}_2 = \beta_d \hat{d}_2 + \alpha_d \cdot dar_1, \quad DAR_t = \hat{d}_2 / (1 - \beta_d^t)

Stage 4: Trailing level:

band = qqeFactor × DAR
upper = rsiMA + band
lower = rsiMA - band

if rsiMA > trail AND prev_rsiMA > trail:
    trail = max(trail, lower)
elif rsiMA < trail AND prev_rsiMA < trail:
    trail = min(trail, upper)
else:
    trail = (rsiMA > trail) ? lower : upper

Default parameters: rsiPeriod = 14, smoothFactor = 5, qqeFactor = 4.236.

Resources

  • Wilder, J.W. (1978). New Concepts in Technical Trading Systems. Trend Research (RSI foundation)
  • MetaTrader community documentation on QQE implementation
  • PineScript reference: qqe.pine