Indicator · Pine Script v5 · On the chart

Trendline Breakouts With Targets [ Chartprime ]

by webcrack4· code credited to ChartPrime

This overlay indicator draws trendlines on the price chart and marks breakouts with optional targets.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code273
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

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

29TBT.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime

//@version=5
indicator("Trendline Breakouts With Targets [ Chartprime ]",shorttitle = "TBT [ Chartprime ]",overlay = true,max_bars_back = 500,max_lines_count = 500)


bool ChartTime              = time > chart.left_visible_bar_time and time < chart.right_visible_bar_time
   
string CORE                 =  "➞ Core Settings 🔸"
var bool TradeisON          = false
var bool LongTrade          = false
var bool ShortTrade         = false
var float TP                = 0.0
var float SL                = 0.0
int BarTIME                 = time - time[1]
var line tpLine             = na
var label LAB               = na
var int UpdatedX            = 0
var float UpdatedY          = 0.0
var float UpdatedSLP        = 0.0
var int UpdatedXLow         = 0
var float UpdatedYLow       = 0.0
var float UpdatedSLPLow     = 0.0


int Period          = input.int(10, title='     Period     ➞',
     group = CORE,
     inline = "001")

bool Trendtype      = input.string(title = "     Type        ➞",
      defval='Wicks',
      options=['Wicks', 'Body'],
      group = CORE,
      inline = "001")
       == 'Wicks'

string Extensions   = input.string(title='     Extend    ➞', 
     defval='  25',
     options=['  25', '  50', '  75'],
     group = CORE,
     inline = "001")


color LineCol1 = input.color(color.rgb(109, 111, 111, 19),"",group = CORE,inline = "001")
bool ShowTargets = input.bool(true,"Show Targets",group = CORE,inline = "002")
     
ExtenSwitcher(ex) =>
    switch ex 
        '  25' => 1 ,
        '  50' => 2 ,
        => 3


WidthSwitcher(ex) =>
    switch ex 
        '1' => 1 ,
        '2' => 2 ,
        => 3 

StyleSwitcher(style) =>
    switch style 
        'Dashed' => line.style_dashed ,
        'Dotted' => line.style_dotted ,
        => line.style_solid 




method volAdj(int len)=>
    math.min(ta.atr(len) * 0.3, close * (0.3/100)) [20] /2

Zband = volAdj(30)




method Trendlines(float src, int timeIndex,bool dir) =>
    
    var int Start = 1 , var int End = 0 , var int TIME = 1
    var float YEnd = 0, var float YStart = 0 , var float Slope = 0
    var line Line1 = line.new(na,na,na,na)
    var line Line2 = line.new(na,na,na,na)
    var line Line3 = line.new(na,na,na,na)
    
    SCR = fixnan(src)
    if ta.change(SCR) != 0
        TIME := time[timeIndex]
        YStart := SCR[1]
        Start := TIME[1]
        Slope := (SCR - YStart) / (TIME - Start)
        Slope

    EXTime = ExtenSwitcher(Extensions) * BarTIME * 25
    End := TIME + EXTime
    YEnd := SCR + EXTime * Slope
    
    if ta.change(SCR) != 0 and not TradeisON[1]
        LineCond = Slope * time < 0 ? dir ? na : color.rgb(11, 139, 7, 53) : dir ?  color.rgb(212, 46, 0, 54) : na
        if not na(LineCond) //and ChartTime
            Line1 := line.new(Start,
                 YStart,
                 End,
                 YEnd,
                 xloc.bar_time,
                 extend.none,
                 color=color.new(color.white,100)
                 )
    
            Line2:=line.new(Start,
                 YStart - (Zband * 2),
                 End,
                 YEnd - (Zband * 2),
                 xloc.bar_time,
                 extend.none,
                 color=color.new(color.black,100)
                 )
                 
            Line3:=line.new(Start,
                 YStart - (Zband * 1),
                 End,
                 YEnd - (Zband * 1),
                 xloc.bar_time,
                 extend.none,
                 color=color.new(color.black,100)
                 )

            linefill.new(Line3,Line2,color= LineCol1)
            linefill.new(Line3,Line1,color= LineCond)
            // linefill.new(Line,Line2,color= color.rgb(28, 15, 2, 76))
           
    [Start, YStart, Slope]



PH = ta.pivothigh(Trendtype ? high : close > open ? close : open, Period, Period / 2)
PL = ta.pivotlow(Trendtype ? low : close > open ? open : close, Period, Period / 2)




method GetlinePrice(int TIME, float Price, float SLOP, int LookB) =>
    var float Current = 0.0
    EsTime = time - TIME
    Current := Price + (EsTime - LookB * BarTIME) * SLOP
    Current
    

method CheckCross(float Price, int StartTime, float StartPrice, float SLP) =>
    var float Current = 0.0
    var float Previous = 0.0
    if StartPrice[Period] != StartPrice
        Current := GetlinePrice(StartTime, StartPrice, SLP, 0) 
        Previous := GetlinePrice(StartTime, StartPrice, SLP, 1)
        Crossover =  Price[1] < Previous and Price > Current ? 1 : Price[1] > Previous - (Zband*0.1) and Price < Current - (Zband*0.1) ? -1 : 0
        Crossover



[Xx, XZ, SLPXZ] = Trendlines(PH, Period / 2,false)
[XxL, XZL, SLPXZL] = Trendlines(PL, Period / 2, true)




if ta.change(fixnan(PH)) != 0
    UpdatedX := Xx
    UpdatedY := XZ
    UpdatedSLP := SLPXZ
    UpdatedSLP
    
if ta.change(fixnan(PL)) != 0
    UpdatedXLow := XxL
    UpdatedYLow := XZL
    UpdatedSLPLow := SLPXZL
    UpdatedSLPLow

Long = not (UpdatedSLP * time > 0) 
     and CheckCross(close, UpdatedX, UpdatedY, UpdatedSLP)== 1
     and not TradeisON
Short = not (UpdatedSLPLow * time < 0)
     and CheckCross(close, UpdatedXLow, UpdatedYLow, UpdatedSLPLow)==-1
     and not TradeisON


TradeFire = Long or Short

if Long and not TradeisON
    LongTrade:= true
    ShortTrade:= false

if Short and not TradeisON
    LongTrade:= false
    ShortTrade:= true


if true 
    if TradeFire and not TradeisON
        TP := switch
            Long  => high + (Zband *20)
            Short => low - (Zband *20)

        SL := switch
            Long  => low - (Zband *20)
            Short => high + (Zband *20)

        TradeisON:= true
        if ShowTargets
            line.new(bar_index,
                 Long ? high : low,
                 bar_index,
                 TP,
                 width=2,
                 color = color.rgb(154, 103, 20),
                 style= line.style_dashed)

            tpLine:= line.new(bar_index,
                 TP,
                 bar_index+2,
                 TP,
                 style= line.style_dashed,
                 color = color.rgb(154, 103, 20)
                 )
            LAB:=label.new(bar_index,
                 TP,
                 "Target",
                 color = color.rgb(154, 103, 20),
                 style= label.style_label_left,
                 size=size.small,
                 textcolor = color.white
                 )
    if TradeisON
        line.set_x2(tpLine,bar_index)
        label.set_x(LAB,bar_index+1)

    if LongTrade and TradeisON
        if high >= TP
            label.set_color(LAB,color.rgb(6, 128, 10, 37))
            TradeisON:=false
        if close <= SL
            label.set_color(LAB,color.new(color.rgb(246, 7, 7),70))
            TradeisON:=false

    else if ShortTrade and TradeisON

        if low <= TP 
            label.set_color(LAB,color.rgb(6, 128, 10, 37))
            TradeisON:=false
            
        if close >= SL 
            label.set_color(LAB,color.new(color.rgb(246, 7, 7),70))   
            TradeisON:=false



plotshape(Long and not TradeisON[1],
     size = size.small,
     color = color.rgb(46, 192, 6, 11),
     location = location.belowbar,
     style = shape.labelup ,
     text = "",
     textcolor = color.white)

plotshape(Short and not TradeisON[1],
     size = size.small,
     color = color.rgb(241, 2, 2, 11),
     location = location.abovebar,
     style = shape.labeldown ,
     text = "",
     textcolor = color.white)


// -- END -- .

Overview

Trendline Breakouts With Targets [ Chartprime ] builds a slope from successive changes in a wick or body source over a user-set period, then extends the line by a selected multiple of the bar interval. Parallel lines sit a volatility-adjusted distance from the trendline, using a capped ATR calculation. Inputs change the period, source type, extension length, line color, and whether targets appear. The visible code tracks long and short trade states plus target and stop levels, but it does not place orders.

Details

Published by

webcrack4 on GitHub

Code credit

ChartPrime, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Support & resistance, Breakout

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
     Period     ➞int10Period
     Type        ➞stringWicksTrendtype
     Extend    ➞string 25Extensions
LineCol1colorcolor.rgb(109, 111, 111, 19)LineCol1
Show TargetsbooltrueShowTargets
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

The Market Tradability Engine calculates multi-factor tradability, balance, compression, and direction scores to evaluate market regime quality. It classifies market conditions into eight distinct states, including Balance, Compression, Ready, Breakout, Trend,

Indicator v6 TrendVolatility & bands
Updated yesterday · MIT GitHub repository of Market Tradability Engine [WavesUnchained]
1 stars

This Pine Script indicator plots a range filter line along with high and low target bands on the price chart. It calculates a smoothed average range using a sampling period and multiplier, then applies a filter to detect upward and downward trends. Signals tri

Indicator v5 TrendVolatility & bands
Updated 2 months ago · Custom licence GitHub repository of Range Filter Buy and Sell 5min

[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

Sideway Zones Live

by dearvn
257 stars

Sideway Zones Live is an overlay indicator that estimates inner and outer sideways bands from recent highs and lows with a rational quadratic kernel. It tracks swing pivots over a loopback period and counts bars that remain between the outer high and low. Afte

Indicator v5 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Sideway Zones Live

Dynamic Linear Regression

by TradersPost
218 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

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