Indicator · Pine Script v6 · On the chart

Adaptive Trend Flow [QuantAlgo]

by theonetrade· code credited to QuantAlgo

Adaptive Trend Flow [QuantAlgo] is an overlay indicator that identifies market trend direction using dual exponential moving averages combined with smoothed volatility bands.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code162
Settings8inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

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

162 lines of Pine Script v6 from assets/indicator/bit-exact/adaptive_trend_flow_quantalgo_1ttpw8M3.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adaptive_trend_flow_quantalgo_1ttpw8M3.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantAlgo

//@version=6
indicator(title="Adaptive Trend Flow [QuantAlgo]", overlay=true, max_labels_count=500)

//              ╔════════════════════════════════╗              //
//              ║      USER-DEFINED SETTINGS     ║              //
//              ╚════════════════════════════════╝              //

// Input Groups
var string trend_settings    = "════════ Trend Settings ════════"
var string visual_settings   = "════════ Visualization Settings ════════"

// Tooltips
tooltip_length      = "Length of the trend calculation period. Higher values create smoother signals."
tooltip_smooth      = "Smoothing period for volatility. Higher values reduce noise."
tooltip_sens        = "Multiplier for volatility bands. Higher values create wider bands."
tooltip_bars        = "Enable/disable bar coloring based on trend direction"
tooltip_bg          = "Enable/disable background gradient coloring"
tooltip_signals     = "Enable/disable signal markers on trend changes"

// Trend Settings
length        = input.int(10, "Main Length", minval=2, 
                 group=trend_settings, tooltip=tooltip_length)
smooth_len    = input.int(14, "Smoothing Length", minval=2, 
                 group=trend_settings, tooltip=tooltip_smooth)
sensitivity   = input.float(2.0, "Sensitivity", step=0.1, 
                 group=trend_settings, tooltip=tooltip_sens)

// Visualization Settings
bullcolor     = input.color(#00ffaa, "Bullish Color", group=visual_settings)
bearcolor     = input.color(#ff0000, "Bearish Color", group=visual_settings)
showbars      = input.bool(true, "Color Bars?", group=visual_settings, tooltip=tooltip_bars)
showbg        = input.bool(true, "Background Color?", group=visual_settings, tooltip=tooltip_bg)
showsignals   = input.bool(true, "Show Signals?", group=visual_settings, tooltip=tooltip_signals)

//              ╔════════════════════════════════╗              //
//              ║       TREND CALCULATIONS       ║              //
//              ╚════════════════════════════════╝              //

calculate_trend_levels() =>
    typical = hlc3
    fast_ema = ta.ema(typical, length)
    slow_ema = ta.ema(typical, length * 2)
    basis = (fast_ema + slow_ema) / 2
    
    vol = ta.stdev(typical, length)
    smooth_vol = ta.ema(vol, smooth_len)
    
    upper = basis + (smooth_vol * sensitivity)
    lower = basis - (smooth_vol * sensitivity)
    
    [basis, upper, lower]

get_trend_state(upper, lower, basis) =>
    var float prev_level = na
    var int trend = 0
    
    if na(prev_level)
        trend := close > basis ? 1 : -1
        prev_level := trend == 1 ? lower : upper
    
    if trend == 1
        if close < lower
            trend := -1
            prev_level := upper
        else
            prev_level := lower
    else
        if close > upper
            trend := 1
            prev_level := lower
        else
            prev_level := upper
    
    [trend, prev_level]

[basis, upper, lower] = calculate_trend_levels()
[trend, level] = get_trend_state(upper, lower, basis)

//              ╔════════════════════════════════╗              //
//              ║         VISUALIZATION          ║              //
//              ╚════════════════════════════════╝              //

// Signal detection
long_signal = trend == 1 and trend[1] == -1
short_signal = trend == -1 and trend[1] == 1

// Plot average/basis line
p2 = plot(basis, color=trend == 1 ? bullcolor : bearcolor, linewidth=2)

// Plot trend line with breaks
p1 = plot(level, 
     color=close > level ? bullcolor : bearcolor,
     linewidth=2, 
     style=plot.style_linebr)

// Plot additional trend line
plot(level, 
     color=close > level ? bullcolor : bearcolor,
     linewidth=2, 
     style=plot.style_linebr)

// Add labels for crossovers
if showsignals and ta.crossunder(close, level)
    label.new(bar_index, level, "𝑺", 
             color=bearcolor,
             textcolor=chart.fg_color,
             style=label.style_label_lower_right)

if showsignals and ta.crossover(close, level)
    label.new(bar_index, level, "𝑳", 
             color=bullcolor,
             textcolor=chart.bg_color,
             style=label.style_label_upper_right)

// Background gradient coloring
var float intensity = 0.0
var int prev_trend = 0

// Reset intensity on trend change
if trend != prev_trend
    intensity := 0.0
    prev_trend := trend

// Increment intensity based on trend
intensity := trend == 1 ? math.min(intensity + 1, 20) : trend == -1 ? math.min(intensity + 1, 20) : intensity

// Calculate gradient colors
color grad_color = trend == 1 ? 
     color.from_gradient(intensity, 0, 20, color.new(bullcolor, 95), color.new(bullcolor, 80)) :
     color.from_gradient(intensity, 0, 20, color.new(bearcolor, 95), color.new(bearcolor, 80))

bgcolor(showbg ? grad_color : na)

// Fill between the lines
fill(p1, p2, level, basis, trend == 1 ? bullcolor : bearcolor, na)
fill(p1, p2, level, basis, trend == 1 ? bullcolor : bearcolor, na)

// Bar Coloring
barcolor(showbars ? (trend == 1 ? color.new(bullcolor, 15) : color.new(bearcolor, 15)) : na)

//              ╔════════════════════════════════╗              //
//              ║             ALERTS             ║              //
//              ╚════════════════════════════════╝              //

alertcondition(long_signal, title="Adaptive Trend Flow Long", 
     message="Adaptive Trend Flow Long {{exchange}}:{{ticker}}")
alertcondition(short_signal, title="Adaptive Trend Flow Short", 
     message="Adaptive Trend Flow Short {{exchange}}:{{ticker}}")

//              ╔════════════════════════════════╗              //
//              ║           CREATED BY           ║              //
//              ╚════════════════════════════════╝              //

// ██████╗ ██╗   ██╗ █████╗ ███╗   ██╗████████╗     █████╗ ██╗      ██████╗  ██████╗ 
//██╔═══██╗██║   ██║██╔══██╗████╗  ██║╚══██╔══╝    ██╔══██╗██║     ██╔════╝ ██╔═══██╗
//██║   ██║██║   ██║███████║██╔██╗ ██║   ██║       ███████║██║     ██║  ███╗██║   ██║
//██║▄▄ ██║██║   ██║██╔══██║██║╚██╗██║   ██║       ██╔══██║██║     ██║   ██║██║   ██║
//╚██████╔╝╚██████╔╝██║  ██║██║ ╚████║   ██║       ██║  ██║███████╗╚██████╔╝╚██████╔╝
// ╚══▀▀═╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝       ╚═╝  ╚═╝╚══════╝ ╚═════╝  ╚═════╝

Overview

Adaptive Trend Flow [QuantAlgo] calculates a central basis line from two EMAs and projects upper and lower volatility boundaries based on standard deviation. When price crosses these dynamic boundaries, the trend state shifts between bullish and bearish. The indicator provides customizable visual options including bar coloring, background highlighting, and visual trend change markers.

Details

Published by

theonetrade on GitHub

Code credit

QuantAlgo, as written in the script's header

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Main Lengthint10length
Smoothing Lengthint14smooth_len
Sensitivityfloat2.0sensitivity
Bullish Colorcolor#00ffaabullcolor
Bearish Colorcolor#ff0000bearcolor
Color Bars?booltrueshowbars
Background Color?booltrueshowbg
Show Signals?booltrueshowsignals
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

321 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 8 days ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
220 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 2 years ago · None stated GitHub repository of Adaptive MA Slope

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers