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.
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.
On the breakout bar, the script establishes TP/SL levels and begins tracking which one is hit first.
Zband is derived from ATR(30) and the instrument price, then shifted and halved as used in the code.*20 in the script).| 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 = periodrightbars = max(1, floor(period/2))Bullish pattern (break above a descending line built from pivot highs):
Bearish pattern (break below an ascending line built from pivot lows):
Legend (quick view):
Zband.islastbarupdate ensures drawing is efficient and that only relevant, up-to-date segments are output on the last recalculation.//--------------------------------------------------// //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