Indicator · Pine Script v6 · Own pane

QQE + AK Trend Combined

by realanthonyc· code credited to Anthony

This indicator combines a Qualitative Quantitative Estimation oscillator with an AK Trend line in a separate pane.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code108
Settings14inputs
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

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

qqe-ak-trend-v1.2.6.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Anthony C. https://x.com/anthonycxc

//@version=6
// -------------------------------------------------------------------------
//  QQE + AK Trend Combined
//  - Single QQE instance
//  - Wilder's smoothing (ta.rma) for ATR-of-RSI
//  - AK Scale Factor based on timeframe
//  v1.2.6
// -------------------------------------------------------------------------
indicator("QQE + AK Trend Combined", shorttitle="QQE + AK Trend", overlay=false, max_lines_count=1, max_bars_back=800)

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

// === QQE ATR length (Wilder) ===
atrLen               = input.int(14, "ATR Length for QQE (Wilder)", minval=1)

// === AK Trend Settings (optional) ===
computeAk            = input.bool(true, "Compute AK Trend")
showAkTrend          = input.bool(true, "Show AK Trend Line")
input1               = input.int(3,  "Fast EMA 1", minval=1)
input2               = input.int(8,  "Fast EMA 2", minval=1)

// === AK Scale Factor Inputs for Different Timeframes ===
ak_scale_less_15m    = input.float(28.0, "AK Scale Factor (<15m)", minval=0.1, step=0.1, tooltip="Scale factor for timeframes less than 15 minutes")
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")
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")
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")

// === AK Scale Factor based on timeframe ===
getAkScaleFactor(_less_15m, _15m_1h, _1h_1d, _above_1d) =>
    timeframeInMinutes = timeframe.period == "1" ? 1 :
                         timeframe.period == "5" ? 5 :
                         timeframe.period == "15" ? 15 :
                         timeframe.period == "30" ? 30 :
                         timeframe.period == "60" ? 60 :
                         timeframe.period == "240" ? 240 :
                         timeframe.period == "D" ? 1440 : 1440
    akScale = timeframeInMinutes < 15 ? _less_15m :
              timeframeInMinutes <= 60 ? _15m_1h :
              timeframeInMinutes <= 1440 ? _1h_1d : _above_1d
    akScale

ak_scale = getAkScaleFactor(ak_scale_less_15m, ak_scale_15m_1h, ak_scale_1h_1d, ak_scale_above_1d)

// === Calculate QQE (Single) ===
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 ===
[qqeTrend, rsi0] = calculateQQE(sourcePrimary, rsiLengthPrimary, rsiSmoothingPrimary, qqeFactorPrimary, atrLen)

// AK Trend (compute gated)
fastmaa = computeAk ? ta.ema(close, input1) : na
fastmab = computeAk ? ta.ema(close, input2) : na
bspread = computeAk ? (fastmaa - fastmab) * 1.001 : na
akTrendColor = bspread > 0 ? color.rgb(5, 152, 5) : color.rgb(180, 0, 0)

// === Plotting ===
// RSI histogram (shifted RSI around 0)
rsiColor = rsi0 >  thresholdPrimary ? color.rgb(144, 238, 144, 50) :
           rsi0 < -thresholdPrimary ? color.rgb(255, 99, 71,   50) :
                                      color.rgb(112, 112, 112, 50)
plot(rsi0, color=rsiColor, title="RSI Histogram (Primary)", style=plot.style_columns)

// Signals (same semantics: histogram over threshold)
sigVal   = rsi0 >  thresholdPrimary ? rsi0 :
           rsi0 < -thresholdPrimary ? rsi0 : na
sigColor = rsi0 >  thresholdPrimary ? color.rgb(144, 238, 144) : color.rgb(255, 99, 71)
plot(sigVal, title="QQE Signals", style=plot.style_columns, color=sigColor)

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

Overview

QQE + AK Trend Combined computes a smoothed Relative Strength Index and builds QQE bands using Wilder's smoothed average true range of the RSI. Additionally, it integrates an adaptive AK Trend calculation that automatically selects scale factors based on the active timeframe. Users can adjust RSI parameters, QQE factors, fast EMA lengths, and scale factor thresholds for different chart timeframes.

Details

Published by

realanthonyc on GitHub

Code credit

Anthony, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend, Moving averages

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 AK TrendbooltruecomputeAk
Show AK Trend LinebooltrueshowAkTrend
Fast EMA 1int3input1
Fast EMA 2int8input2
AK Scale Factor (<15m)float28.0ak_scale_less_15m
AK Scale Factor (15m-1h)float16.0ak_scale_15m_1h
Show all 14 settings
SettingTypeDefaultVariable
AK Scale Factor (>1h-1d)float8.0ak_scale_1h_1d
AK Scale Factor (>1d)float3.0ak_scale_above_1d
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

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Elder Impulse System

by mihakralj
99 stars

Elder Impulse System plots a column series in a separate pane. It compares a 13-period exponential moving average with its previous value and a MACD histogram with its previous value. A rising EMA and rising histogram print 1, a falling EMA and falling histogr

Indicator v5 TrendOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Elder Impulse System
47 stars

This indicator calculates the Williams Gator Oscillator derived from Bill Williams Alligator lines and plots dual histograms in a separate pane. The upper histogram displays the absolute difference between the Jaw and Teeth moving averages, while the lower his

Indicator v6 Oscillators & momentumMoving averages
Updated 8 months ago · MIT GitHub repository of Williams Gator Oscillator

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