OPEN-SOURCE SCRIPT
CleanBreak Lines (Break + First Retest)

CleanBreak lines draws one robust support line (green) from swing lows and one robust resistance line (red) from swing highs, then optionally signals a confirmed break and the first clean retest back to that line. Lines are scored with a transparent W-Score (0–100) so traders can judge quality at a glance. The script is non-repainting and uses only confirmed bar data.
What it does
Auto-builds two trendlines that aim to represent meaningful support and resistance.
Uses a median-based slope so outliers and single spikes do not distort the line.
Computes a W-Score per line from three things: touches, span (how long it held), and respect (staying on the correct side).
Optionally triggers a single, tightly-gated signal on Break + First Retest.
How it works (plain English)
Detect recent swing highs and swing lows.
Fit one line through highs and one through lows using a robust, median-style slope estimate.
Score each line: more clean touches and longer span raise the W-Score; frequent violations lower it.
A break requires a candle close beyond the line by a small ATR margin.
A first retest requires price to come back to the line within a limited number of bars and hold on close.
A single arrow may print on that confirmed retest, with optional alerts.
What it is not
Not a prediction model and not a promises-of-profit tool.
Not a multi-signal spammer: by design it aims to allow one retest entry per break.
Not a regression channel or machine-learning system.
How to use
At a glance: treat the green line as candidate support and the red line as candidate resistance.
Conservative approach: wait for a break on close and then the first retest to hold; use the arrow as a prompt, not a command.
Context-only mode: hide arrows in Style if you want the lines and W-Score only.
Inputs (brief)
Core: Swing Length, Max Pivots, Min Touches, Min Span Bars.
Scoring: Touches Max (cap), Weights for touches vs span, Min W-Score to arm.
Break and Retest: Break Margin x ATR, Retest Tolerance x ATR, Retest Window (bars).
Visuals: Show Labels, Show Table, Line Width, Fade When Refit.
Recommended presets
Cleaner, fewer signals: Min Touches 4–5, Min Span Bars 100–150, Min W-Score 70–80, Break Margin 0.40–0.60 ATR, Retest Tolerance 0.10–0.15 ATR, Retest Window 8–12 bars.
Lines-only: keep defaults and uncheck the two plotshapes in Style.
Alerts
CB Long Retest: break above the red line and first retest holds.
CB Short Retest: break below the green line and first retest holds.
Use “Once per bar close” for consistency.
On-chart table (if enabled)
RES / SUP: W-Score and distance from price in ATR terms.
Status: “Waiting Long RT”, “Waiting Short RT”, or “Idle”.
Thresholds: MinScore and Retest bars for quick context.
Timeframes
Works well on 1h to 1D. On very low timeframes, raise Break Margin x ATR to reduce whipsaw effects. On higher timeframes, increase Min Touches and Min Span Bars.
Non-repainting policy
All logic uses confirmed pivots and confirmed bar closes.
Breaks and retests are validated on close; alerts reference only confirmed conditions.
No lookahead in any request.security call.
Original implementation focused on a median-based robust slope for auto trendlines, plus a transparent W-Score and a single retest gate.
Disclosure
This script is for education and charting. It does not guarantee outcomes, and past behavior does not imply future results. Always validate on historical data and practice risk management.
What it does
Auto-builds two trendlines that aim to represent meaningful support and resistance.
Uses a median-based slope so outliers and single spikes do not distort the line.
Computes a W-Score per line from three things: touches, span (how long it held), and respect (staying on the correct side).
Optionally triggers a single, tightly-gated signal on Break + First Retest.
How it works (plain English)
Detect recent swing highs and swing lows.
Fit one line through highs and one through lows using a robust, median-style slope estimate.
Score each line: more clean touches and longer span raise the W-Score; frequent violations lower it.
A break requires a candle close beyond the line by a small ATR margin.
A first retest requires price to come back to the line within a limited number of bars and hold on close.
A single arrow may print on that confirmed retest, with optional alerts.
What it is not
Not a prediction model and not a promises-of-profit tool.
Not a multi-signal spammer: by design it aims to allow one retest entry per break.
Not a regression channel or machine-learning system.
How to use
At a glance: treat the green line as candidate support and the red line as candidate resistance.
Conservative approach: wait for a break on close and then the first retest to hold; use the arrow as a prompt, not a command.
Context-only mode: hide arrows in Style if you want the lines and W-Score only.
Inputs (brief)
Core: Swing Length, Max Pivots, Min Touches, Min Span Bars.
Scoring: Touches Max (cap), Weights for touches vs span, Min W-Score to arm.
Break and Retest: Break Margin x ATR, Retest Tolerance x ATR, Retest Window (bars).
Visuals: Show Labels, Show Table, Line Width, Fade When Refit.
Recommended presets
Cleaner, fewer signals: Min Touches 4–5, Min Span Bars 100–150, Min W-Score 70–80, Break Margin 0.40–0.60 ATR, Retest Tolerance 0.10–0.15 ATR, Retest Window 8–12 bars.
Lines-only: keep defaults and uncheck the two plotshapes in Style.
Alerts
CB Long Retest: break above the red line and first retest holds.
CB Short Retest: break below the green line and first retest holds.
Use “Once per bar close” for consistency.
On-chart table (if enabled)
RES / SUP: W-Score and distance from price in ATR terms.
Status: “Waiting Long RT”, “Waiting Short RT”, or “Idle”.
Thresholds: MinScore and Retest bars for quick context.
Timeframes
Works well on 1h to 1D. On very low timeframes, raise Break Margin x ATR to reduce whipsaw effects. On higher timeframes, increase Min Touches and Min Span Bars.
Non-repainting policy
All logic uses confirmed pivots and confirmed bar closes.
Breaks and retests are validated on close; alerts reference only confirmed conditions.
No lookahead in any request.security call.
Original implementation focused on a median-based robust slope for auto trendlines, plus a transparent W-Score and a single retest gate.
Disclosure
This script is for education and charting. It does not guarantee outcomes, and past behavior does not imply future results. Always validate on historical data and practice risk management.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.