Indicator · Pine Script v5 · On the chart

Future Trend Channel [ChartPrime]

by webcrack4· code credited to ChartPrime

Calculates trend channels based on a Simple Moving Average (SMA) and Average True Range (ATR) envelope.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code182
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago10 Jan 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

182 lines of Pine Script v5 from 13FutureTrendChannel.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=5
indicator("Future Trend Channel [ChartPrime]", overlay = true, max_lines_count = 500)

// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
int   ftclength = input.int(100, "Trend Length")
float multi  = input.float(3, "Channel Width", step = 0.1)
int   extend = input.int(50, "Index of future price")
color color_up = input.color(#16d897, "Up", inline = "Colors")
color color_dn = input.color(#da853f, "Dn", inline = "Colors")

float atr    = ta.highest(ta.atr(200), 100)

// UDT ------------------------------>>
type channel 
    line line_mid1 = na
    line line_mid2 = na
    line line_top1 = na
    line line_top2 = na
    line line_low1 = na
    line line_low2 = na

var c = channel.new(line(na), line(na), line(na), line(na), line(na), line(na))


// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
future_price(x1,x2,y1,y2,index)=>
    float slope = (y2-y1)/(x2-x1) 

    float future_price = y1 + slope * (index - x1)

    style = switch
        y1 > y2 =>label.style_label_lower_left
        =>label.style_label_upper_left

    label.new(index, future_price, 
                 text  = str.tostring(future_price, "Future Price: \n #.#"),
                 color = color.new(chart.fg_color, 80),
                 textcolor = chart.fg_color, 
                 style     = style)

ftctrend(ftclength)=>
    var ftctrend = bool(na)
    float sma = ta.sma(close, ftclength)
    float upper = sma + atr
    float lower = sma - atr

    bool signal_up = ta.crossover(close, upper)
    bool signal_dn = ta.crossunder(close, lower)

    if signal_up
        ftctrend := true
    if signal_dn
        ftctrend := false

    ftctrend

bool ftctrend = ftctrend(ftclength)

remove_lines(ftctrend)=>
    if ftctrend and not ftctrend[1]
        c.line_mid2 := line(na)
        c.line_top2 := line(na)
        c.line_low2 := line(na)

    if not ftctrend and ftctrend[1]
        c.line_mid1 := line(na)
        c.line_top1 := line(na)
        c.line_low1 := line(na)

color_lines(line_m, line_t, line_l, color, label)=>
    var color_lines = color

    if color == color_up ? line_m.get_y1() <= line_m.get_y2() : line_m.get_y1() >= line_m.get_y2()
        color_lines := color
        line_m.set_color(color_lines)
        line_l.set_color(color_lines)
        line_t.set_color(color_lines)

        line_m.set_style(line.style_solid)
        line_t.set_style(line.style_solid)
        line_l.set_style(line.style_solid)
        label.set_color(label, color_lines)  

    if  color == color_up ? line_m.get_y1() >= line_m.get_y2() : line_m.get_y1() <= line_m.get_y2()
        color_lines := chart.fg_color
        line_m.set_color(color_lines)
        line_t.set_color(color_lines)
        line_l.set_color(color_lines)

        line_m.set_style(line.style_dashed)
        line_t.set_style(line.style_dashed)
        line_l.set_style(line.style_dashed)
        label.set_color(label, color.new(color_lines, 100))

    label.set_size(label, size.tiny)

    linefill.new(line_l, line_t, color.new(color_lines, 90))

draw_channel(ftctrend)=>
    var label_up = label(na)
    var label_dn = label(na)
    var label_m = label(na)

    series float src = hl2
    series float low_src = src - atr * multi
    series float high_src = src + atr * multi

    // -> New Lines
    if ftctrend and not ftctrend[1]
        label_up := label.new(bar_index, low_src, style = label.style_diamond)
        c.line_mid1 := line.new(bar_index, src, bar_index, src)
        c.line_top1 := line.new(bar_index, high_src, bar_index, high_src)
        c.line_low1 := line.new(bar_index, low_src, bar_index, low_src)

        c.line_mid2.set_xy2(bar_index, src)
        c.line_top2.set_xy2(bar_index, high_src)
        c.line_low2.set_xy2(bar_index, low_src)

    if not ftctrend and ftctrend[1]
        label_dn := label.new(bar_index, high_src, style = label.style_diamond)
        c.line_mid2 := line.new(bar_index, src, bar_index+2, src)
        c.line_top2 := line.new(bar_index, high_src, bar_index, high_src)
        c.line_low2 := line.new(bar_index, low_src, bar_index, low_src)

        c.line_mid1.set_xy2(bar_index, src)
        c.line_top1.set_xy2(bar_index, high_src)
        c.line_low1.set_xy2(bar_index, low_src)

    // Extend
    if ftctrend
        label.delete(label_m)
        c.line_mid2.set_extend(extend.none)
        c.line_top2.set_extend(extend.none)     
        c.line_low2.set_extend(extend.none)   

        c.line_mid1.set_extend(extend.right)
        c.line_top1.set_extend(extend.right)     
        c.line_low1.set_extend(extend.right)   

        c.line_mid1.set_xy2(bar_index, ta.sma(src, 20))
        c.line_top1.set_xy2(bar_index, ta.sma(high_src, 20))
        c.line_low1.set_xy2(bar_index, ta.sma(low_src, 20))

        label_m := future_price(c.line_mid1.get_x1(), c.line_mid1.get_x2(), c.line_mid1.get_y1(), c.line_mid1.get_y2(), bar_index+extend)

    

    if not ftctrend
        label.delete(label_m)
        c.line_mid1.set_extend(extend.none)
        c.line_top1.set_extend(extend.none)     
        c.line_low1.set_extend(extend.none)   

        c.line_mid2.set_extend(extend.right)
        c.line_top2.set_extend(extend.right)     
        c.line_low2.set_extend(extend.right)   

        c.line_mid2.set_xy2(bar_index, ta.sma(src, 20))
        c.line_top2.set_xy2(bar_index, ta.sma(high_src, 20))
        c.line_low2.set_xy2(bar_index, ta.sma(low_src, 20))

        label_m := future_price(c.line_mid2.get_x1(), c.line_mid2.get_x2(), c.line_mid2.get_y1(), c.line_mid2.get_y2(), bar_index+extend)


    color_lines(c.line_mid1, c.line_top1, c.line_low1, color_up, label_up)
    color_lines(c.line_mid2, c.line_top2, c.line_low2, color_dn, label_dn)

    remove_lines(ftctrend)


// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
draw_channel(ftctrend)
// --------------------------------------------------------------------------------------------------------------------}

Overview

When price crosses outside the volatility envelope, the indicator identifies trend changes and draws dynamic mid, top, and bottom channel lines directly on the price chart. It projects channel trajectories forward into future bars and plots predicted future price target labels. Main inputs allow customization of trend length, channel width multiplier, future projection distance, and trend colors.

Details

Published by

webcrack4 on GitHub

Code credit

ChartPrime, 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
Trend Lengthint100ftclength
Channel Widthfloat3multi
Index of future priceint50extend
Upcolor#16d897color_up
Dncolor#da853fcolor_dn
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

[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

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

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