Indicator · Pine Script v6 · On the chart

Trendline Breakouts With Targets

by shubhamtaywade82

Detects pivot highs and lows, draws sloping trendlines from them and marks breakouts on the price chart.

View on GitHub

Archived by its author

GitHub stars1on the repository
Pine versionv6current
Lines of code335
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago31 May 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

335 lines of Pine Script v6 from indicators/trendlines/Trendline Breakouts With Targets [ Chartprime ].pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Trendline Breakouts With Targets [ Chartprime ].pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shubhamtaywade82 — Lux-inspired refresh (palette / HUD / cleanup).
// Visual style is an original palette inspired by premium dark-chart indicators; not affiliated with LuxAlgo.

//@version=6
indicator(
     title            = 'Trendline Breakouts With Targets [ Lux Edition ]',
     shorttitle       = 'TBT Lux',
     overlay          = true,
     max_bars_back    = 500,
     max_lines_count  = 500,
     max_labels_count = 500
 )

// ═══════════════════════════════════════════════════════════════════════════
// Inputs — grouped (pinescript-agents style)
// ═══════════════════════════════════════════════════════════════════════════
string G_CORE = 'Core'
string G_STYLE = 'Lux style'
string G_DISP = 'Display'

int Period =
     input.int(10, 'Pivot period', minval = 3, maxval = 50, group = G_CORE, tooltip = 'Swing length for pivot high / low.')

bool Trendtype =
     input.string('Wicks', 'Source', options = ['Wicks', 'Body'], group = G_CORE) == 'Wicks'

string Extensions =
     input.string('  25', 'Line extension', options = ['  25', '  50', '  75'], group = G_CORE)

bool ShowTargets =
     input.bool(true, 'Show TP / SL visuals', group = G_DISP)

bool ShowDashboard =
     input.bool(true, 'Show status table', group = G_DISP)

bool LimitTrendlinesToPane =
     input.bool(false, 'Draw trendlines only in visible range', group = G_DISP,
         tooltip = 'Fewer objects when scrolling deep history.')

// Lux-inspired defaults (teal / magenta / violet — not affiliated with LuxAlgo)
color LuxBull =
     input.color(color.new(#26FFD1, 0), 'Bull / long accent', group = G_STYLE)
color LuxBear =
     input.color(color.new(#FF4D8D, 0), 'Bear / short accent', group = G_STYLE)
color LuxMuted =
     input.color(color.new(#8B9CFF, 82), 'Channel fill', group = G_STYLE)
color LuxGrid =
     input.color(color.new(#1A1F35, 70), 'Channel rail (ghost)', group = G_STYLE)

string SignalSize =
     input.string('Small', 'Signal marker size', options = ['Tiny', 'Small', 'Normal'], group = G_STYLE)

// ═══════════════════════════════════════════════════════════════════════════
// State
// ═══════════════════════════════════════════════════════════════════════════
int BarTIME = time - time[1]

var bool TradeisON = false
var bool LongTrade = false
var bool ShortTrade = false
var float TP = 0.0
var float SL = 0.0
var line tpLine = na
var line slConnector = na
var label tpLabel = na
var table dash = 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

bool inVisiblePane =
     time > chart.left_visible_bar_time and time < chart.right_visible_bar_time

// ═══════════════════════════════════════════════════════════════════════════
// Helpers
// ═══════════════════════════════════════════════════════════════════════════
ExtenSwitcher(string ex) =>
    switch ex
        '  25' => 1
        '  50' => 2
        => 3

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

float Zband = volAdj(30)

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

method CheckCross(float Price, int StartTime, float StartPrice, float SLP) =>
    int cross = 0
    if StartPrice[Period] != StartPrice
        float cur = GetlinePrice(StartTime, StartPrice, SLP, 0)
        float prev = GetlinePrice(StartTime, StartPrice, SLP, 1)
        cross :=
             Price[1] < prev and Price > cur ? 1 : Price[1] > prev - Zband * 0.1 and Price < cur - Zband * 0.1 ? -1 : 0
    cross

// ═══════════════════════════════════════════════════════════════════════════
// Trendlines (auto channel + fill)
// ═══════════════════════════════════════════════════════════════════════════
method Trendlines(float src, int timeIndex, bool dir) =>
    var int Start = 1
    var int End = 0
    var int TIME = 1
    var float YEnd = 0.0
    var float YStart = 0.0
    var float Slope = 0.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)

    float SCR = fixnan(src)
    if ta.change(SCR) != 0
        TIME := time[timeIndex]
        YStart := SCR[1]
        Start := TIME[1]
        Slope := (SCR - YStart) / (TIME - Start)

    int EXTime = ExtenSwitcher(Extensions) * BarTIME * 25
    End := TIME + EXTime
    YEnd := SCR + EXTime * Slope

    bool allowDraw = not LimitTrendlinesToPane or inVisiblePane
    if ta.change(SCR) != 0 and not TradeisON[1] and allowDraw
        color lineHue = Slope * time < 0 ? dir ? na : color.new(LuxBull, 45) : dir ? color.new(LuxBear, 45) : na
        if not na(lineHue)
            Line1 := line.new(Start, YStart, End, YEnd, xloc = xloc.bar_time, extend = extend.none, color = LuxGrid, width = 1)

            Line2 := line.new(Start, YStart - Zband * 2, End, YEnd - Zband * 2, xloc = xloc.bar_time, extend = extend.none, color = LuxGrid, width = 1)

            Line3 := line.new(Start, YStart - Zband, End, YEnd - Zband, xloc = xloc.bar_time, extend = extend.none, color = LuxGrid, width = 1)

            linefill.new(Line3, Line2, color = LuxMuted)
            linefill.new(Line3, Line1, color = lineHue)

    [Start, YStart, Slope]

// ═══════════════════════════════════════════════════════════════════════════
// Pivots + geometry
// ═══════════════════════════════════════════════════════════════════════════
float phSrc = Trendtype ? high : close > open ? close : open
float plSrc = Trendtype ? low : close > open ? open : close

float PH = ta.pivothigh(phSrc, Period, Period / 2)
float PL = ta.pivotlow(plSrc, Period, Period / 2)

[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

if ta.change(fixnan(PL)) != 0
    UpdatedXLow := XxL
    UpdatedYLow := XZL
    UpdatedSLPLow := SLPXZL

int longCrossSignal = close.CheckCross(UpdatedX, UpdatedY, UpdatedSLP)
int shortCrossSignal = close.CheckCross(UpdatedXLow, UpdatedYLow, UpdatedSLPLow)

bool Long = not (UpdatedSLP * time > 0) and longCrossSignal == 1 and not TradeisON
bool Short = not (UpdatedSLPLow * time < 0) and shortCrossSignal == -1 and not TradeisON

bool TradeFire = Long or Short

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

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

// ═══════════════════════════════════════════════════════════════════════════
// Trade lifecycle + Lux visuals
// ═══════════════════════════════════════════════════════════════════════════
if TradeFire and not TradeisON
    TP := Long ? high + Zband * 20 : low - Zband * 20
    SL := Long ? low - Zband * 20 : high + Zband * 20
    TradeisON := true

    if ShowTargets
        color bullTint = color.new(LuxBull, 25)
        color bearTint = color.new(LuxBear, 25)
        color legCol = Long ? bullTint : bearTint
        float anchor = Long ? high : low

        slConnector := line.new(bar_index, anchor, bar_index, TP, color = legCol, width = 2, style = line.style_dashed)

        tpLine := line.new(bar_index, TP, bar_index + 2, TP, color = legCol, width = 2, style = line.style_dashed)

        string tpTxt = 'TP  ' + str.tostring(TP, format.mintick)
        tpLabel :=
             label.new(
                 bar_index + 1,
                 TP,
                 tpTxt,
                 style = label.style_label_left,
                 color = Long ? color.new(LuxBull, 12) : color.new(LuxBear, 12),
                 textcolor = color.new(#0D0F14, 0),
                 size = size.small
             )

if TradeisON
    if not na(tpLine)
        line.set_x2(tpLine, bar_index)
    if not na(tpLabel)
        label.set_x(tpLabel, bar_index + 1)

if LongTrade and TradeisON
    if high >= TP
        if not na(tpLabel)
            label.set_color(tpLabel, color.new(LuxBull, 55))
        TradeisON := false
    if close <= SL
        if not na(tpLabel)
            label.set_color(tpLabel, color.new(LuxBear, 35))
        TradeisON := false

else if ShortTrade and TradeisON
    if low <= TP
        if not na(tpLabel)
            label.set_color(tpLabel, color.new(LuxBull, 55))
        TradeisON := false
    if close >= SL
        if not na(tpLabel)
            label.set_color(tpLabel, color.new(LuxBear, 35))
        TradeisON := false

// ═══════════════════════════════════════════════════════════════════════════
// Signals + alerts
// ═══════════════════════════════════════════════════════════════════════════
bool longPlot = Long and not TradeisON[1]
bool shortPlot = Short and not TradeisON[1]

// plotshape(..., size=) must be const — one call per size tier
plotshape(
     longPlot and SignalSize == 'Tiny',
     title = 'Long breakout',
     style = shape.triangleup,
     location = location.belowbar,
     size = size.tiny,
     color = color.new(LuxBull, 0),
     textcolor = color.new(#0D0F14, 0)
 )

plotshape(
     longPlot and SignalSize == 'Small',
     title = 'Long breakout',
     style = shape.triangleup,
     location = location.belowbar,
     size = size.small,
     color = color.new(LuxBull, 0),
     textcolor = color.new(#0D0F14, 0)
 )

plotshape(
     longPlot and SignalSize == 'Normal',
     title = 'Long breakout',
     style = shape.triangleup,
     location = location.belowbar,
     size = size.normal,
     color = color.new(LuxBull, 0),
     textcolor = color.new(#0D0F14, 0)
 )

plotshape(
     shortPlot and SignalSize == 'Tiny',
     title = 'Short breakout',
     style = shape.triangledown,
     location = location.abovebar,
     size = size.tiny,
     color = color.new(LuxBear, 0),
     textcolor = color.new(#0D0F14, 0)
 )

plotshape(
     shortPlot and SignalSize == 'Small',
     title = 'Short breakout',
     style = shape.triangledown,
     location = location.abovebar,
     size = size.small,
     color = color.new(LuxBear, 0),
     textcolor = color.new(#0D0F14, 0)
 )

plotshape(
     shortPlot and SignalSize == 'Normal',
     title = 'Short breakout',
     style = shape.triangledown,
     location = location.abovebar,
     size = size.normal,
     color = color.new(LuxBear, 0),
     textcolor = color.new(#0D0F14, 0)
 )

alertcondition(longPlot, title = 'Long TL break', message = 'Trendline bullish break (Lux edition)')
alertcondition(shortPlot, title = 'Short TL break', message = 'Trendline bearish break (Lux edition)')

// ═══════════════════════════════════════════════════════════════════════════
// Mini dashboard (Lux-style glass panel)
// ═══════════════════════════════════════════════════════════════════════════
if ShowDashboard and barstate.islast
    if na(dash)
        dash := table.new(position.top_right, 2, 5, bgcolor = color.new(#121826, 10), border_width = 1, border_color = color.new(LuxBull, 78))

    table.cell(dash, 0, 0, 'TBT Lux', text_color = LuxBull, text_size = size.small)
    table.cell(dash, 1, 0, '', text_color = LuxBull, text_size = size.small)

    table.cell(dash, 0, 1, 'Position', text_color = color.new(#E8ECFF, 15), text_size = size.small)
    string posTxt =
         TradeisON ? LongTrade ? 'Long active' : ShortTrade ? 'Short active' : 'Flat' : 'Flat'
    table.cell(dash, 1, 1, posTxt, text_color = color.new(#FFFFFF, 0), text_size = size.small)

    table.cell(dash, 0, 2, 'TP', text_color = color.new(#E8ECFF, 15), text_size = size.small)
    table.cell(dash, 1, 2, TradeisON ? str.tostring(TP, format.mintick) : '—', text_color = LuxBull, text_size = size.small)

    table.cell(dash, 0, 3, 'SL', text_color = color.new(#E8ECFF, 15), text_size = size.small)
    table.cell(dash, 1, 3, TradeisON ? str.tostring(SL, format.mintick) : '—', text_color = LuxBear, text_size = size.small)

    float distPct = TradeisON and not na(close) and TP != 0.0 ? math.abs(TP - close) / close * 100.0 : na
    table.cell(dash, 0, 4, 'Dist to TP', text_color = color.new(#E8ECFF, 15), text_size = size.small)
    table.cell(dash, 1, 4, not na(distPct) ? str.tostring(distPct, '#.##') + '%' : '—', text_color = color.new(#C5CCF0, 0), text_size = size.small)

// -- END --

Overview

After a breakout it shows take profit and stop loss visuals and a status table. Settings choose the pivot period, whether lines use wicks or candle bodies, line extension, marker size and colours, and an option to draw trendlines only in the visible range to reduce objects.

Details

Published by

shubhamtaywade82 on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

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
Pivot periodint10Pivot period
SourcestringWicksSource
Line extensionstring 25Line extension
Show TP / SL visualsbooltrueShow TP / SL visuals
Show status tablebooltrueShow status table
Draw trendlines only in visible rangeboolfalseDraw trendlines only in visible range
Bull / long accentcolorcolor.new(#26FFD1, 0)Bull / long accent
Bear / short accentcolorcolor.new(#FF4D8D, 0)Bear / short accent
Channel fillcolorcolor.new(#8B9CFF, 82)Channel fill
Channel rail (ghost)colorcolor.new(#1A1F35, 70)Channel rail (ghost)
Signal marker sizestringSmallSignal marker size
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

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
219 stars

This indicator identifies High Of Low Price (HOLP) and Low Of High Price (LOHP) candlestick setups based on price extremes over a specified lookback period. A HOLP signal triggers when the current bar closes above the high of a recent session low, whereas a LO

Indicator v5 Candlestick patternsBreakout
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns - HOLP-LOHP
218 stars

This indicator plots dynamic support and resistance levels on the price chart. It detects pivot highs and lows using the pivot length and tracks touches to build strength-based levels. Support and resistance zones appear as colored boxes while lines mark key l

Indicator v6 Support & resistanceBreakout
Updated 3 months ago · None stated GitHub repository of Dynamic Support & Resistance

Donchian Channels (DC)

by mihakralj
99 stars

This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their

Indicator v6 Volatility & bandsSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)

Lows from New Highs

by be-thomas
65 stars

This indicator tracks bar lows during consecutive rising highs using Pine Script arrays. When at least four lows accumulate or the price breaches the minimum low in the stack, the script sorts the recorded lows in ascending order and flushes them. It plots up

Indicator v4 Support & resistanceBreakout
Updated 5 days ago · GPL-3.0 GitHub repository of Lows from New Highs

This indicator tracks smart money market structure directly on the price chart. It calculates dual-period swing highs and swing lows to detect Changes of Character (CHoCH), Breaks of Structure (BOS), inducements, and liquidity sweeps. When structural levels ar

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · Apache-2.0 GitHub repository of Market Structure with Inducements & Sweeps [LuxAlgo]

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