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)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 //--------------------------------------------------////PRC_TrendLine BreakOuts by chartprime//version = 0//27.11.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------//// Inputs//--------------------------------------------------//period=9pivottype=1 // 1 means wicks // 0 means BodyshowtrendUP=1 //BooleanshowtrendDN=1 //Boolean//--------------------------------------------------//// Pivots High and Low//--------------------------------------------------//leftbars=periodrightbars=max(1,floor(period/2))if pivottype thensrc1 = lowsrc2 = highelsesrc1 = min(open,close)src2 = max(open,close)endif//---Pivots Lowif 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+y1if $PLy[z]>$PLy[z-1] then$slopeL[z]=($PLy[z]-$PLy[z-1])/($PLx[z]-$PLx[z-1])endifendif//---Pivots Highif 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+y1if $PHy[t]<$PHy[t-1] then$slope[t]=($PHy[t]-$PHy[t-1])/($PHx[t]-$PHx[t-1])endifendif//--------------------------------------------------////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 positionsif islastbarupdate and showtrendUP thenfor i=t downto 4 doif $PHy[i-1]<$PHy[i-2] thenx1=$PHx[i-2]y1=$PHy[i-2]for j=$PHx[i-1]+1 to barindex dox2=jy2=y1+(x2-x1)*$slope[i-1]if close[barindex-j]>y2 thentp=high[barindex-j]+(Zband[barindex-j]*20)sl=low[barindex-j]-(Zband[barindex-j]*20)breakendifnextfor k=x2+1 to barindex doif high[barindex-k]>=tp thenx3=ksellprice=max(tp,open[barindex-k])win=1breakelsif low[barindex-k]<=sl thenx3=ksellprice=min(sl,open[barindex-k])win=0breakelsex3=barindexendifnextif x2<$PHx[i] thendrawsegment(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 thendrawpoint(x3,sellprice,1)coloured("orange")drawtext("✖",x3,sellprice+0.25*tr[1])coloured("green")endifendifendifnextendif//---TrendLine and Short positionsif islastbarupdate and showtrendDN thenfor i=z downto 4 doif $PLy[i-1]>$PLy[i-2] thenx1=$PLx[i-2]y1=$PLy[i-2]for j=$PLx[i-1]+1 to barindex dox2=jy2=y1+(x2-x1)*$slopeL[i-1]if close[barindex-j]<y2 thensl=high[barindex-j]+(Zband[barindex-j]*20)tp=low[barindex-j]-(Zband[barindex-j]*20)breakendifnextfor k=x2+1 to barindex doif high[barindex-k]>=sl thenx3=ksellprice=max(sl,open[barindex-k])win=0breakelsif low[barindex-k]<=tp thenx3=ksellprice=min(tp,open[barindex-k])win=1breakelsex3=barindexendifnextif x2<$PLx[i] thendrawsegment(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 thendrawpoint(x3,sellprice,1)coloured("orange")drawtext("✖",x3,sellprice+0.25*tr[1])coloured("darkred")endifendifendifnextendif//--------------------------------------------------//return
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Great Indicator Ivan, thank you so much! It seems better than similar indicator that are available in the market 🙂