Explainers / Trendline Breakouts With Targets by Char
Trendline Breakouts With Targets by ChartPrime, explained from the source
Trendline Breakouts With Targets is an open-source TradingView script by ChartPrime, about 20,400 boosts, published in September 2023. On the chart it is called "TBT". It draws short trendlines through recent turning points, puts an arrow on the bar where the close breaks a line, and draws a "Target" label that later turns green or red. This page walks through its published code in order, says what each part does, and ends with where it fails. It does not say what any line or arrow will do next.
The surprise: the colour of a target label is not a fair score
When an arrow fires, the code sets a target and a stop. Only the target is drawn. The target is measured from the signal bar's high (for an up arrow) and the stop from its low, by the same distance. A breakout bar usually closes near its high, so the target starts out closer to the close than the stop. Then the target counts as reached when a later bar's high touches it, while the stop only counts when a later bar closes beyond it. Both choices make green labels more common. On invented prices that have nothing to find, about 6 in 10 finished labels still turned green.
Step 1: the turning points
The script finds pivot highs and pivot lows. With the default "Type" of Wicks it uses highs and lows; with Body it uses the top or bottom of each candle body. A pivot high is a high above the 10 bars before it ("Period", default 10) and the 5 bars after it (half the period). So each turning point is only known 5 bars after it happened.
Step 2: the lines
Each time a new pivot high is confirmed, the script joins it to the previous pivot high with a straight line and extends it 25 bars past the newer pivot ("Extend": 25, 50 or 75). A resistance line is drawn only when it slopes down; a support line through two pivot lows is drawn only when it slopes up or is flat. No line is drawn while a target from an earlier arrow is still open. Below each line sits a shaded band one to two "bands" thick, where a band is half of the smaller of 0.3 times the 30-bar Average True Range and 0.3% of the close, both taken from 20 bars earlier.
Step 3: when an arrow fires
An up arrow fires on the bar where the close moves from below the newest resistance line to above it. A down arrow fires when the close moves from above the newest support line to below it by at least a tenth of a band, so the two directions do not use the same test. Three more conditions apply. The line must slope the right way. No target may be open. And the line must have changed recently: the code only checks for a cross during the 10 checks after the line's starting point moves, which in practice is about the first 10 bars after the newer pivot is confirmed. The drawn line runs on for 25 bars, so for most of its drawn length a cross produces no arrow. The check uses the newest pair of pivots whether or not that line was drawn, so after a target closes, an arrow can come from a line that never appeared on the chart.
Step 4: the target and the stop
On an up arrow, the target is the signal bar's high plus 20 bands, which works out to the smaller of 3 times the 30-bar ATR and 3% of the close (20 bars old). The stop is the bar's low minus the same amount. A down arrow is the mirror image. A dashed line and a "Target" label mark the target; the stop is never drawn. On each later bar, the label turns green if the high reaches the target, and red if the close goes past the stop. If both happen on the same bar, red is applied last and wins. Until the label changes colour, no new arrows and no new lines appear.
What the settings change
"Period" (10) sets how many bars on the left make a pivot, and half of it sets how late each pivot is confirmed and how many bars on the right it needs. "Type" switches between wicks and candle bodies. "Extend" sets how far the drawn line runs, not how long a cross can fire an arrow: that window stays at about 10 bars, because it is tied to the period. "Show Targets" hides the target line and label but not the logic: an open target still blocks new arrows. The multiplier of 20, the 0.3 factors, the 30-bar ATR and the 20-bar delay are fixed in the code.
What we checked in Python
We ported the line, arrow and target logic to Python and ran it on invented random-walk prices (three runs of 20,000 bars and two of 100,000) with the default settings. It produced about 13 arrows per 1,000 bars. Of the target labels that finished, 58% to 61% turned green. When we changed only one thing, so the stop also counted on a wick, the green share fell to 56% to 60%. The rest of the gap comes from where the target and stop start: on 95% of arrows the target was nearer the signal bar's close than the stop, and the median target distance was 0.75 times the stop distance. Of the drawn lines that a close crossed before the line ended, 26% to 31% were crossed after the 10-check window, so the cross got no arrow. These figures describe the code on invented data, not any market.
Where it fails
- Green labels are tilted. The target is reached on a wick and the stop only on a close, and on a breakout bar the target usually starts nearer. On invented prices about 6 in 10 labels still turned green, so a chart full of green labels does not show the lines work.
- The stop is hidden. It is computed and used, but never drawn, so you cannot see how far away it was.
- Arrows only in a 10-bar window. The drawn line runs 25 bars or more, but a cross after about the tenth bar gets no arrow. On invented prices about 3 in 10 line crosses fell outside the window.
- Arrows can come from lines you never saw. The check uses the newest pivots even when their line was not drawn because a target was open at the time.
- Lines appear 5 bars late. A line can only exist once its second pivot is confirmed. On a scrolled-back chart it is drawn from the earlier pivot, which makes it look as if it was there sooner than it was.
- The arrow can change on an unfinished bar. The code has no check for a closed bar, so on a live bar the arrow can appear and disappear as the close moves. Only closed bars are fixed.
- Up and down use different tests. A down arrow needs the close a tenth of a band beyond the support line; an up arrow needs only a close above the resistance line.
- One target at a time. While a label is open, every other break is ignored, so the number of arrows depends on how long the last target took.
- No alerts and no backtest. The code defines no alert conditions and keeps no record of labels beyond their colour on the chart.
- Not checked on a chart. The realtime behaviour and the shaded band were read from the code only.
- Open and licensed. The code carries a Mozilla Public License 2.0 notice and credits ChartPrime; this page describes it in our own words and pastes none of it.
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Trendline Breakouts With Targets is by ChartPrime on TradingView and carries a Mozilla Public License 2.0 notice; this page describes its published open-source code in our own words and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the script trades.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.