Free: indicator teardowns, a repaint checker and open-source scripts. No buy/sell signals, ever.

Taught to TradeSystems over signals.

Explainers / Trendlines with Breaks [LuxAlgo]

Trendlines with Breaks [LuxAlgo], explained from the source

Trendlines with Breaks is an open-source TradingView script by LuxAlgo (about 54,000 boosts). It draws a falling line from the latest swing high and a rising line from the latest swing low, and prints a "B" label when the close crosses one of them. This page walks through what the published code does, what each setting changes, and where it fails. It does not say what price does after a label.

The surprise: it does not fit a line to price

Most people read "trendline" as a line drawn through two swing points. This script does not do that. When a swing high is confirmed, the line starts at that high and then falls by a fixed amount every bar. The amount is set once, at the moment the swing is confirmed, from the Slope settings, and it never looks at the next swing. The lower line is the mirror: it starts at a swing low and rises by a fixed amount per bar. The lines are a volatility-sized ramp from one pivot, not a trend measured from price.

Step 1: pivots, known 14 bars late

It finds swing highs and lows with Swing Detection Lookback (default 14) on both sides. A pivot needs 14 bars on the right to exist, so it is only known 14 bars after it happened. Each new pivot replaces the previous one for that side.

Step 2: the slope

The per-bar step is chosen by Slope Calculation Method. Atr (default): the 14-bar ATR divided by the lookback, times the Slope setting. Stdev: the standard deviation of closes over the lookback, divided by the lookback, times Slope. Linreg: the absolute slope of a regression of close against bar number, halved, times Slope. With the Atr default, step times lookback equals ATR times Slope, so by the bar a pivot is confirmed the line has already fallen (or risen) by about one ATR from the pivot price.

Step 3: the breakout label

State resets to "not broken" at every new pivot. After that, the upper-break state turns on when the close is above the falling line, and the lower-break state turns on when the close is below the rising line. A "B" label is drawn on the bar where the state flips on. The test uses only data up to that bar, and the level it compares against is the same level the backpainted line shows on that bar. Because the state resets at each pivot, a new label can print right after a pivot if the close is already past the new line.

Step 4: backpainting

The Backpaint setting is on by default. The plotted lines are shifted back by the lookback (14 bars), so each line appears to start at the pivot bar, although the script only knew about the pivot 14 bars later. The script's own tooltip says that turning backpainting off shows the real-time information. The extended dashed lines are redrawn from the latest pivot each time, so only one extended line per side is on the chart at a time; older ones are replaced, not kept.

What the settings change (synthetic prices, seeds 1 to 3)

On random prices with no structure, the defaults drew an upper-break label about 1.5 to 1.8 times per 100 bars and a lower-break label about 1.5 to 1.6 times per 100. Lookback 7 raised that to about 3.5 per 100; lookback 28 lowered it to about 0.7. These are counts on made-up prices; they show how often the test fires, not whether a label means anything.

The names are easy to misread

The setting called "Up Trendline Color" colors the line that falls from swing highs, and the "Upward Breakout" alert is worded "Price broke the down-trendline upward". The script has two alert conditions, upward and downward breakout. They fire when the test above passes, nothing more.

Where it fails

Also explained: Pivot Point SuperTrend · Support and Resistance Channels · Pivot Points High Low · UT Bot Alerts · Repainting

Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Trendlines with Breaks [LuxAlgo] is by LuxAlgo on TradingView, published under CC BY-NC-SA 4.0; 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, 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, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue

Next steps

  • Get a script fixed. Compiles but behaves differently live, or changes after a reload? In a Pine Script Audit, an AI model reads every line and writes a report on what to fix for $49, or also fixes those problems for $149. It cannot prove a script is safe.
  • Check your own script. Paste its source into the free repaint checker. It runs in your browser and flags known patterns.
Subscribe to the Teardown Letter: $19/moBack to Taught to Trade

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.