Indicator · Pine Script v6 · On the chart

Adaptive Trend Flow

by rosijay17-cmd· code credited to QuantAlgo

An indicator that draws a volatility band trend line on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code162
Settings8inputs
LicenceGPL-3.0
Last update8 days ago22 Oct 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 Adaptive_Trend_Flow_QuantAlgo.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Adaptive_Trend_Flow_QuantAlgo.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

A basis is built from two EMAs of the typical price, and bands sit above and below it at a multiple of smoothed standard deviation. The trend flips to bullish when price closes above the upper band and to bearish when it closes below the lower band. Settings control length, smoothing and sensitivity, and bars, background and signal markers can be coloured by trend.

Details

Published by

rosijay17-cmd 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.

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

Chandelier Exit

by everget
947 stars

This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.

Indicator v6 Volatility & bandsTrend Repaints
Updated 12 days ago · GPL-3.0 GitHub repository of Chandelier Exit

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
330 stars

Range Filter [Alorse] is a technical indicator overlay for TradingView designed to filter market volatility and identify price trends. It calculates a smoothed range based on historical volatility using a configurable sampling period and multiplier applied to

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of Range Filter [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

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 3 days ago · MIT GitHub repository of NVDA Trend Ribbon

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

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