Indicator · Pine Script v6 · Own pane

QQE + AK Trend + EFI

by realanthonyc

This indicator computes and plots a QQE histogram using RSI of the chosen source smoothed with Wilder's ATR method, alongside an AK Trend line derived from fast EMAs with dynamic scale factors adjusted by timeframe.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code128
Settings19inputs
LicenceMPL-2.0
Last update10 months ago4 Dec 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

128 lines of Pine Script v6 from qqe-ak-trend.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

qqe-ak-trend.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © realanthonyc https://www.tradingview.com/u/realanthonyc

//@version=6
// -------------------------------------------------------------------------
//  QQE + AK Trend + EFI
//  - QQE histogram with Wilder's smoothing (ta.rma) for ATR-of-RSI
//  - AK Scale Factor based on timeframe
//  - Elder Force Index (EFI) with dynamic scaling to match QQE trend range
//  - Dynamic scaling adjusts EFI height based on QQE range over the specified number of bars
//  - Divergence visualization between AK Trend and EFI with background color
//  - EFI display disabled when volume = 0 to avoid distortion
//  On GitHub: https://github.com/realanthonyc/QQE-AK-EFI
//  v1.5.8
// -------------------------------------------------------------------------
indicator("QQE + AK Trend + EFI", shorttitle="QQE + AK + EFI", overlay=false, precision=0, max_lines_count=1, max_bars_back=800)

// === QQE Settings ===
rsiLengthPrimary     = input.int(6, "RSI Length", minval=1, group="QQE Settings")
rsiSmoothingPrimary  = input.int(5, "RSI Smoothing", minval=1, group="QQE Settings")
qqeFactorPrimary     = input.float(2.0, "QQE Factor", minval=0.1, step=0.1, tooltip="Lower = smoother QQE band.", group="QQE Settings")
thresholdPrimary     = input.float(10.0, "Threshold", minval=0.1, step=0.1, tooltip="RSI distance from 50 to color histogram.", group="QQE Settings")
sourcePrimary        = input.source(close, "RSI Source", group="QQE Settings")
atrLen               = input.int(14, "ATR Length for QQE (Wilder)", minval=1, group="QQE Settings")

// === AK Trend Settings ===
showAkTrend          = input.bool(true, "Compute and show the AK Trend line", group="AK Trend Settings")
input1               = input.int(3, "Fast EMA 1", minval=1, group="AK Trend Settings")
input2               = input.int(8, "Fast EMA 2", minval=1, group="AK Trend Settings")
ak_scale_less_15m    = input.float(36.0, "AK Scale Factor (<15m)", minval=0.1, step=0.1, tooltip="Scale factor for timeframes less than 15 minutes", group="AK Trend Settings")
ak_scale_15m_1h      = input.float(16.0, "AK Scale Factor (15m-1h)", minval=0.1, step=0.1, tooltip="Scale factor for timeframes between 15 minutes and 1 hour", group="AK Trend Settings")
ak_scale_1h_1d       = input.float(8.0,  "AK Scale Factor (>1h-1d)", minval=0.1, step=0.1, tooltip="Scale factor for timeframes between 1 hour and 1 day", group="AK Trend Settings")
ak_scale_above_1d    = input.float(3.0,  "AK Scale Factor (>1d)", minval=0.1, step=0.1, tooltip="Scale factor for timeframes above 1 day", group="AK Trend Settings")

// === EFI Settings ===
efiLength            = input.int(13, "EFI Length", minval=1, group="EFI Settings")
efiMultiplier        = input.float(2.25, "EFI Multiplier", minval=0.1, step=0.05, tooltip="Multiplier to adjust EFI height relative to QQE range (higher value makes EFI taller).", group="EFI Settings")
dynamicScalingBars   = input.int(300, "Dynamic Scaling Bars", minval=1, tooltip="Number of bars to look back for dynamic scaling of EFI (larger value considers more historical data for range calculation).", group="EFI Settings")

// === Divergence Settings ===
showDivergence = input.bool(true, "Show AK-EFI Divergence", group="AK-EFI Divergence Settings")
colorLongRisk  = input.color(color.rgb(157, 255, 30, 88), "Long Risk", group="AK-EFI Divergence Settings")
colorShortRisk = input.color(color.rgb(255, 127, 180, 88), "Short Risk", group="AK-EFI Divergence Settings")

// === AK Scale Factor based on timeframe ===
getAkScaleFactor(_less_15m, _15m_1h, _1h_1d, _above_1d) =>
    timeframeInSeconds = timeframe.in_seconds()
    akScale = timeframeInSeconds < 900 ? _less_15m :  // 15m (900 seconds)
              timeframeInSeconds <= 3600 ? _15m_1h :  // 1h (3600 seconds)
              timeframeInSeconds <= 86400 ? _1h_1d : _above_1d  // 1d (86400 seconds)
    akScale
ak_scale = getAkScaleFactor(ak_scale_less_15m, ak_scale_15m_1h, ak_scale_1h_1d, ak_scale_above_1d)

// === Calculate QQE ===
calculateQQE(_src, _rsiLen, _sLen, _qqeFactor, _atrLen) =>
    // RSI and smoothing
    _rsi         = ta.rsi(_src, _rsiLen)
    _smoothedRsi = ta.ema(_rsi, _sLen)

    // ATR of RSI via Wilder's smoothing (classic QQE style)
    _atrRsi = math.abs(_smoothedRsi - _smoothedRsi[1])
    _atrW   = ta.rma(_atrRsi, _atrLen)
    _delta  = _atrW * _qqeFactor

    // Bands with proper initialization using nz()
    var float _longBand = na
    var float _shortBand = na
    var int   _trendDir  = 0
    _newShort = _smoothedRsi + _delta
    _newLong  = _smoothedRsi - _delta
    _longPrev  = nz(_longBand[1],  _newLong)
    _shortPrev = nz(_shortBand[1], _newShort)
    _longBand  := _smoothedRsi > _longPrev  ? math.max(_longPrev,  _newLong)  : _newLong
    _shortBand := _smoothedRsi < _shortPrev ? math.min(_shortPrev, _newShort) : _newShort

    // Trend direction with explicit edge checks; seed with nz()
    _crossUp = _smoothedRsi > _shortPrev and _smoothedRsi[1] <= _shortPrev
    _crossDn = _smoothedRsi < _longPrev  and _smoothedRsi[1] >= _longPrev
    _trendDir := _crossUp ? 1 : _crossDn ? -1 : nz(_trendDir[1], 0)
    _qqeTrendLine = _trendDir == 1 ? _longBand : _shortBand
    [_qqeTrendLine, _smoothedRsi - 50]  // return QQE trend (unshifted) and RSI shifted to 0

// === Main Calculations ===
[qqeTrend, rsi0] = calculateQQE(sourcePrimary, rsiLengthPrimary, rsiSmoothingPrimary, qqeFactorPrimary, atrLen)

// AK Trend (compute only when shown)
fastmaa = showAkTrend ? ta.ema(close, input1) : na
fastmab = showAkTrend ? ta.ema(close, input2) : na
bspread = showAkTrend ? (fastmaa - fastmab) * 1.001 : na
akTrendColor = bspread > 0 ? color.rgb(5, 152, 5, 30) : color.rgb(180, 0, 0, 30)
akDirection = bspread > 0 ? 1 : bspread < 0 ? -1 : 0

// EFI Calculation
efi = ta.ema(ta.change(close) * volume, efiLength)

// Dynamic scaling to match QQE trend range
qqeShifted = qqeTrend - 50
qqeHighest = ta.highest(qqeShifted, dynamicScalingBars)
qqeLowest = ta.lowest(qqeShifted, dynamicScalingBars)
efiHighest = ta.highest(efi, dynamicScalingBars)
efiLowest = ta.lowest(efi, dynamicScalingBars)
scaleFactor = efiMultiplier * (math.max(math.abs(qqeHighest), math.abs(qqeLowest)) / math.max(math.max(math.abs(efiHighest), math.abs(efiLowest)), 0.0001))
scaledEfi = volume > 0 ? efi * scaleFactor : na
efiDirection = scaledEfi > 0 ? 1 : scaledEfi < 0 ? -1 : 0

// AK-EFI Divergence visualization
var color divergenceColor = na
if showDivergence
    divergenceColor := akDirection == 1 and efiDirection == -1 ? colorLongRisk : akDirection == -1 and efiDirection == 1 ? colorShortRisk : na
bgcolor(divergenceColor, title="AK-EFI Divergence Background")

// === Plotting ===
// QQE histogram (shifted RSI around 0)
rsiColor = rsi0 >  thresholdPrimary ? color.new(#9FE1D7, 15) :
           rsi0 < -thresholdPrimary ? color.new(#FAB3C9, 15) :
                                      color.rgb(112, 112, 112, 50)
plot(rsi0, color=rsiColor, title="QQE Histogram", style=plot.style_columns)

// EFI area
efiAreaColor = scaledEfi >= 0 ? color.rgb(144, 238, 144, 60) : color.rgb(255, 99, 71, 60)
plot(scaledEfi, color=efiAreaColor, title="EFI Area", style=plot.style_area, display=display.none)

// EFI line (overlay to preserve original shape)
plot(scaledEfi, color=color.rgb(254,185,55), title="EFI Line", linewidth=1)

// AK Trend line (draw only when requested)
akTrendValue = showAkTrend ? bspread * ak_scale : na
plot(akTrendValue, title="AK Trend Line", color=akTrendColor, linewidth=2)

Overview

QQE + AK Trend + EFI also calculates Elder Force Index with adaptive scaling to match the QQE trend range over a lookback period and highlights AK-EFI divergences via background coloring. All elements render in a dedicated pane below the price chart. Primary controls include QQE parameters such as length, factor and threshold, AK scale multipliers per timeframe bracket, EFI length and height multiplier, plus bars for dynamic range calculation and a toggle for divergence visualization.

Details

Published by

realanthonyc on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum, Volatility & bands, Divergence

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

indicatorpinescripttradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint6rsiLengthPrimary
RSI Smoothingint5rsiSmoothingPrimary
QQE Factorfloat2.0qqeFactorPrimary
Thresholdfloat10.0thresholdPrimary
RSI SourcesourceclosesourcePrimary
ATR Length for QQE (Wilder)int14atrLen
Compute and show the AK Trend linebooltrueshowAkTrend
Fast EMA 1int3input1
Fast EMA 2int8input2
AK Scale Factor (<15m)float36.0ak_scale_less_15m
AK Scale Factor (15m-1h)float16.0ak_scale_15m_1h
AK Scale Factor (>1h-1d)float8.0ak_scale_1h_1d
Show all 19 settings
SettingTypeDefaultVariable
AK Scale Factor (>1d)float3.0ak_scale_above_1d
EFI Lengthint13efiLength
EFI Multiplierfloat2.25efiMultiplier
Dynamic Scaling Barsint300dynamicScalingBars
Show AK-EFI DivergencebooltrueshowDivergence
Long Riskcolorcolor.rgb(157, 255, 30, 88)colorLongRisk
Short Riskcolorcolor.rgb(255, 127, 180, 88)colorShortRisk
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

2 stars

The Refined Multi-TF Crypto Analyzer plots technical analysis signals on the main price chart by combining multi-timeframe moving averages, RSI, ADX, and volume spikes. It checks for trend alignment between the chart timeframe and a higher timeframe, identifie

Indicator v6 TrendOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Refined Multi-TF Crypto Analyzer
330 stars

This indicator plots a TTM Squeeze momentum oscillator and a MACD line in a separate pane. It builds the squeeze oscillator from a linear regression of price against a high-low and simple moving average midpoint, and colors the area by slope and sign. Circles

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze + MACD line [Alorse]
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

This indicator plots an oscillator in a separate pane. It builds several SuperTrend series across a user-defined factor range and step, using ATR as the band width. On each bar it measures the distance between the close and each SuperTrend output, then groups

Indicator v5 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of AI SuperTrend Clustering Oscillator [LuxAlgo]

TTM Squeeze Divergence

by TamaraKGreen
46 stars

The TTM Squeeze Divergence indicator plots a classic TTM Squeeze momentum oscillator in a separate pane alongside Bollinger Bands and Keltner Channels squeeze status dots on the zero line. It detects regular and hidden bullish and bearish divergences between p

Indicator v6 Oscillators & momentumVolatility & bands Repaints
Updated 7 weeks ago · None stated GitHub repository of TTM Squeeze Divergence

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers