Indicator · Pine Script v5 · On the chart

Follow Line

by theonetrade

The Follow Line indicator plots a dynamic trend-following line directly on the price chart using a combination of Bollinger Bands and ATR values.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code71
Settings5inputs
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

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

follow_line_UXKo4RaJ.pine
//@version=5
indicator(shorttitle='FL', title='Follow Line', overlay=true)

// --- settings 
ATRperiod = input.int(defval=5, title='ATR Period', minval=1)
BBperiod = input.int(defval=21, title='Bollinger Bands Period', minval=1)
BBdeviation = input.float(defval=1.00, title='Bollinger Bands Deviation', minval=0.1, step=0.1)
UseATRfilter = input(defval=true, title='ATR Filter On/Off') // false = 0, true = 1
showsignals  = input(title='Show Signals ', defval=true)
// --- end of settings

// Bollinger Bands calculation
BBUpper = ta.sma(close, BBperiod) + ta.stdev(close, BBperiod) * BBdeviation
BBLower = ta.sma(close, BBperiod) - ta.stdev(close, BBperiod) * BBdeviation

// ATR calculation
atrValue = ta.atr(ATRperiod)

// Signal initialization
var float FollowLine = na
var int BBSignal = 0

// Determine BB signal
if (close > BBUpper)
    BBSignal := 1
else if (close < BBLower)
    BBSignal := -1

// Buy signal logic
if (BBSignal == 1) 
    if (UseATRfilter) 
        FollowLine := low - atrValue
    else
        FollowLine := low
    if (FollowLine < nz(FollowLine[1]))
        FollowLine := nz(FollowLine[1])

// Sell signal logic
if (BBSignal == -1) 
    if (UseATRfilter) 
        FollowLine := high + atrValue
    else
        FollowLine := high
    if (FollowLine > nz(FollowLine[1]))
        FollowLine := nz(FollowLine[1])

// Trend direction determination
var int iTrend = 0
if (nz(FollowLine) > nz(FollowLine[1]))
    iTrend := 1
else if (nz(FollowLine) < nz(FollowLine[1]))
    iTrend := -1

// Trend line color based on trend direction
lineColor = iTrend > 0 ? color.rgb(9, 98, 232) : color.new(color.rgb(220, 20, 60), 0)

//buy & sell conditions
buy=0.0
sell=0.0
buy:=iTrend[1]==-1 and iTrend==1 ? 1 : na
sell:=iTrend[1]==1 and iTrend==-1? 1 : na

//alerts
alertcondition(sell == 1 ,title="Sell",message="Follow Line Sell")
alertcondition(buy == 1 ,title="Buy",message="Follow Line Buy")
alertcondition(buy == 1 or sell == 1 ,title="Signal",message="Follow Line Signal")

// Plot the trend line and signals
plot(FollowLine, color=lineColor, linewidth=2, title="Follow Line")
plotshape(buy == 1 and showsignals ? FollowLine-atrValue :na, text='BUY', style= shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, offset=0, transp=0,size=size.auto)
plotshape(sell == 1 and showsignals ? FollowLine+atrValue:na, text='SELL', style=shape.labeldown, location=location.absolute, color=color.rgb(102, 15, 15), textcolor=color.white, offset=0, transp=0,size=size.auto)

Overview

When price breaks beyond the Bollinger Bands, the script constructs a ratcheted trailing line adjusted by ATR. Reversals in the trailing line direction establish the prevailing trend and generate buy or sell signal labels. Inputs allow users to configure the Bollinger Band period and deviation, ATR length, ATR filter toggle, and signal display options.

Details

Published by

theonetrade on GitHub

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
ATR Periodint5ATRperiod
Bollinger Bands Periodint21BBperiod
Bollinger Bands Deviationfloat1.00BBdeviation
ATR Filter On/OffbooltrueUseATRfilter
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