TrendLine BreakOuts

Category: Indicators By: Iván González Created: October 14, 2025, 2:41 PM
October 14, 2025, 2:41 PM
Indicators
4 Comments

1) Introduction

TrendLine BreakOuts is a indicator inspired by the original concept created by ChartPrime. It automates the discovery of dynamic trendlines built from swing pivots and highlights the first valid breakout with clear, actionable visuals. Once a breakout occurs, the tool overlays ATR-based take-profit (TP) and stop-loss (SL) rails and tracks which level is reached first, helping traders evaluate follow-through after a structural break. Designed for clarity and speed, it works on any timeframe and instrument, and it offers flexible controls to switch between wick or body pivots and to enable/disable bullish or bearish structures.

2) How the Indicator Works

Pivot detection

  • The script scans left/right bars defined by period to confirm swing highs and lows.
  • pivottype = 1 → uses wicks (low/high).
  • pivottype = 0 → uses bodies (min(open, close) / max(open, close)).

A pivot is confirmed when the current candidate is lower (for lows) or higher (for highs) than the surrounding window on both sides. This ensures robust swing points and limits noise.

Trendline construction

  • Bearish lines are drawn by connecting two descending pivot highs (PH).
  • Bullish lines are drawn by connecting two ascending pivot lows (PL).
  • The slope is computed from the latest two relevant pivots and the line is projected forward bar by bar.

Breakout logic

  • For bullish setups (using pivot highs): the indicator checks when price closes above the projected line → breakout.
  • For bearish setups (using pivot lows): the indicator checks when price closes below the projected line → breakout.

On the breakout bar, the script establishes TP/SL levels and begins tracking which one is hit first.

Volatility engine (TP & SL)

  • The buffer Zband is derived from ATR(30) and the instrument price, then shifted and halved as used in the code.
  • TP/SL are placed symmetrically around the breakout reference using a multiplier (*20 in the script).
  • As bars evolve, the script checks: TP hit first (win) or SL hit first (loss).

Drawing layer (what you see)

  • Trendline segments to the breakout point.
  • ▲ / ▼ breakout icons at the crossing.
  • Dotted TP/SL rails that extend until the exit bar.
  • ✖ marker at the exact exit price (TP or SL first).

3) Inputs & Defaults (Configuration Panel)

Input Type Default What it controls Notes & typical ranges
period Integer 9 Swing width (pivot sensitivity) 6–20 common. Lower = more signals, more noise. Higher = smoother, fewer but stronger lines.
pivottype Integer 1 1 = wicks; 0 = bodies Bodies help reduce false breaks from wick spikes; wicks capture “true extremes”.
showtrendUP Boolean 1 Show bullish (breaks of descending highs) Set to 0 to hide all bullish structures.
showtrendDN Boolean 1 Show bearish (breaks of ascending lows) Set to 0 to hide all bearish structures.

Under the hood:

  • leftbars = period
  • rightbars = max(1, floor(period/2))
    This creates a forward/backward confirmation window around each candidate swing.

4) Signal Anatomy & Chart Markings

Bullish pattern (break above a descending line built from pivot highs):

  • Dark green trendline up to the breakout bar.
  • ▲ green marker at the breakout.
  • Green dotted line for TP and dark red dotted line for SL.
  • ✖ orange point at the exit (whichever is hit first), with a small green label.

Bearish pattern (break below an ascending line built from pivot lows):

  • Dark red trendline up to the breakout bar.
  • ▼ dark red marker at the breakout.
  • Green dotted line for TP and dark red dotted line for SL.
  • ✖ orange point at the exit, with a small dark red label.

Legend (quick view):

  • Trendlines: dark green (bullish), dark red (bearish).
  • Breakout icons: (up), (down).
  • TP: dotted (green).
  • SL: dotted (dark red).
  • Exit: (orange point + label).

5) Trade Management Logic

  • On breakout, the indicator computes TP and SL using the volatility buffer Zband.
  • It simulates the path bar by bar after the breakout: if TP is touched first, it registers a win; if SL is touched first, a loss.
  • The script draws until the first event occurs; if neither is hit by the current bar, the rails remain open to barindex.
  • islastbarupdate ensures drawing is efficient and that only relevant, up-to-date segments are output on the last recalculation.

6) Code (ProBuilder)

//--------------------------------------------------//
//PRC_TrendLine BreakOuts by chartprime
//version = 0
//27.11.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------//
// Inputs
//--------------------------------------------------//
period=9
pivottype=1 // 1 means wicks // 0 means Body
showtrendUP=1 //Boolean
showtrendDN=1 //Boolean
//--------------------------------------------------//
// Pivots High and Low
//--------------------------------------------------//
leftbars=period
rightbars=max(1,floor(period/2))
if pivottype then
src1 = low
src2 = high
else
src1 = min(open,close)
src2 = max(open,close)
endif
//---Pivots Low
if src1 > src1[rightbars] and lowest[rightbars](src1) > src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then
$PLy[z+1]=src1[rightbars]
$PLx[z+1]=barindex[rightbars]
z=z+1
//y=(x-x1)*slope+y1
if $PLy[z]>$PLy[z-1] then
$slopeL[z]=($PLy[z]-$PLy[z-1])/($PLx[z]-$PLx[z-1])
endif
endif
//---Pivots High
if src2 < src2[rightbars] and highest[rightbars](src2)<src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then
$PHy[t+1]=src2[rightbars]
$PHx[t+1]=barindex[rightbars]
t=t+1
//y=(x-x1)*slope+y1
if $PHy[t]<$PHy[t-1] then
$slope[t]=($PHy[t]-$PHy[t-1])/($PHx[t]-$PHx[t-1])
endif
endif
//--------------------------------------------------//
//Volatility for TP and SL
//--------------------------------------------------//
Zband=min(averagetruerange[30](close)*0.3,close*(0.3/100))[20]/2
//--------------------------------------------------//
// Draw trendlines and trading signals
//--------------------------------------------------//
//Trendline and Long positions
if islastbarupdate and showtrendUP then
for i=t downto 4 do
if $PHy[i-1]<$PHy[i-2] then
x1=$PHx[i-2]
y1=$PHy[i-2]
for j=$PHx[i-1]+1 to barindex do
x2=j
y2=y1+(x2-x1)*$slope[i-1]
if close[barindex-j]>y2 then
tp=high[barindex-j]+(Zband[barindex-j]*20)
sl=low[barindex-j]-(Zband[barindex-j]*20)
break
endif
next
for k=x2+1 to barindex do
if high[barindex-k]>=tp then
x3=k
sellprice=max(tp,open[barindex-k])
win=1
break
elsif low[barindex-k]<=sl then
x3=k
sellprice=min(sl,open[barindex-k])
win=0
break
else
x3=barindex
endif
next
if x2<$PHx[i] then
drawsegment(x1,y1,x2,y2)coloured("darkgreen")
drawtext("▲",x2,y2-0.25*tr[1])coloured("green")
drawsegment(x2,tp,x3,tp)style(dottedline)coloured("green")
drawsegment(x2,sl,x3,sl)style(dottedline)coloured("darkred")
drawsegment(x2,y2,x2,tp)style(dottedline4,1)coloured("green")
drawsegment(x2,y2,x2,sl)style(dottedline4,1)coloured("green")
if x3<>barindex then
drawpoint(x3,sellprice,1)coloured("orange")
drawtext("✖",x3,sellprice+0.25*tr[1])coloured("green")
endif
endif
endif
next
endif
//---TrendLine and Short positions
if islastbarupdate and showtrendDN then
for i=z downto 4 do
if $PLy[i-1]>$PLy[i-2] then
x1=$PLx[i-2]
y1=$PLy[i-2]
for j=$PLx[i-1]+1 to barindex do
x2=j
y2=y1+(x2-x1)*$slopeL[i-1]
if close[barindex-j]<y2 then
sl=high[barindex-j]+(Zband[barindex-j]*20)
tp=low[barindex-j]-(Zband[barindex-j]*20)
break
endif
next
for k=x2+1 to barindex do
if high[barindex-k]>=sl then
x3=k
sellprice=max(sl,open[barindex-k])
win=0
break
elsif low[barindex-k]<=tp then
x3=k
sellprice=min(tp,open[barindex-k])
win=1
break
else
x3=barindex
endif
next
if x2<$PLx[i] then
drawsegment(x1,y1,x2,y2)coloured("darkred")
drawtext("▼",x2,y2+0.50*tr[1])coloured("darkred")
drawsegment(x2,tp,x3,tp)style(dottedline)coloured("green")
drawsegment(x2,sl,x3,sl)style(dottedline)coloured("darkred")
drawsegment(x2,y2,x2,tp)style(dottedline4,1)coloured("green")
drawsegment(x2,y2,x2,sl)style(dottedline4,1)coloured("green")
if x3<>barindex then
drawpoint(x3,sellprice,1)coloured("orange")
drawtext("✖",x3,sellprice+0.25*tr[1])coloured("darkred")
endif
endif
endif
next
endif
//--------------------------------------------------//
return

Download
Filename: PRC_TrendLine-BreakOuts.itf
Downloads: 205
Iván González Master
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
Author’s Profile

Comments

Logo Logo
Loading...