OPEN-SOURCE SCRIPT
Trendline Breakout Strategy [KedArc Quant]

Description
A single, rule-based system that builds two trendlines from confirmed swing pivots and trades their breakouts, with optional retest, trend-regime gates (EMA / HTF EMA), and ATR-based risk. All parts serve one decision flow: structure → breakout → gated entry → managed risk.
What it does (for traders)
Draws Up line (teal) through the last two Higher Lows and Down line (red) through the last two Lower Highs, then extends them forward.
Long when price breaks above red; Short when price breaks below teal.
Optional Retest entry: after a break, wait for a pullback toward the broken line within an ATR-scaled buffer.
Uses ATR stop and R-multiple target so risk is consistent across symbols/timeframes.
Labels HL1/HL2/LH1/LH2 so non-coders can verify which pivots built each line.
Why these components are combined
Pure breakout systems on trendlines suffer from three practical issues:
False breaks in chop → solved by trend-regime gates (EMA / HTF EMA) that only allow trades aligned with the prevailing trend.
Uneven volatility across markets/timeframes → solved by ATR-based stop/target, normalizing distance so R-multiples are comparable.
First break whipsaws near wedge apices → mitigated by the optional retest rule that demands a pullback/hold before entry.
These modules are not separate indicators with their own signals. They are support roles inside one method.
The pivot engine defines structure, the breakout detector defines signal, the regime gates decide if we’re allowed to take that signal, and the ATR module sizes risk.
Together they make the trendline breakout usable, testable, and explainable.
How it works (mechanism; each component explained)
1) Pivot engine (structure, non-repainting)
Swings are confirmed with ta.pivotlow/high(L, R). A pivot only exists after R bars (no look-ahead), so once plotted, the line built from those pivots will not repaint.
2) Trendline builder (geometry)
Teal line updates when two consecutive pivot lows satisfy HL2.price > HL1.price (and HL2 occurs after HL1).
Red line updates when two consecutive pivot highs satisfy LH2.price < LH1.price.
Lines are extended right and their current value is read every bar via line.get_price().
3) Breakout detector (signal)
On every bar, compute:
crossover(close, redLine) ⇒ Long breakout
crossunder(close, tealLine) ⇒ Short breakdown
4) Regime gates (trend filters, not separate signals)
EMA gate: allow longs only if close > EMA(len), shorts only if close < EMA(len).
HTF EMA gate (optional): same rule on a higher timeframe to avoid fighting the larger trend.
These do not create entries; they simply permit or block the breakout signal.
5) Retest module (optional confirmation)
After a breakout, record the line price. A valid retest occurs if price pulls back within an ATR-scaled buffer toward that broken line and then closes back in the breakout direction.
This reduces first-tick fakeouts.
6) Risk module (position exit)
Initial stop = ATR(len) × atrMult from entry.
Target = tpR × (ATR × atrMult) (e.g., 2R).
This keeps results consistent across instruments/timeframes.
Entries & exits
Long entry
Base: close breaks above red and passes EMA/HTF gates.
Retest (if enabled): after the break, price pulls back near the broken red line (within the ATR buffer) and holds; then enter.
Short entry
Mirror logic with teal (break below & gates), optionally with a retest.
Exit
strategy.exit places ATR stop & R-multiple target automatically.
Optional “flip”: close if the opposite base signal triggers.
How to use it (step-by-step)
Timeframe: 1–15m for intraday, 1–4h for swing.
Start defaults: Pivot L/R = 5, EMA len = 200, ATR len = 14, ATR mult = 2, TP = 2R, Retest = ON.
Tune sensitivity:
Faster lines (more trades): set L/R = 3–4.
Fewer counter-trend trades: enable HTF EMA (e.g., 60-min or Daily).
Visual audit: labels HL1/HL2 & LH1/LH2 show which pivots built each line—verify by eye.
Alerts: use Long breakout, Short breakdown, and Retest alerts to automate.
Originality (why it merits publication)
Trades the visualization: many “auto-trendline” tools only draw lines; this one turns them into testable, alertable rules.
Integrated design: each component has a defined role in the same pipeline—no unrelated indicators bolted together.
Transparent & non-repainting: pivot confirmation removes look-ahead; labels let non-coders understand the setup that produced each signal.
Notes & limitations
Lines update only after pivot confirmation; that lag is intentional to avoid repainting.
Breakouts near an apex can whipsaw; prefer Retest and/or HTF gate in choppy regimes.
Backtests are idealized; forward-test and size risk appropriately.
⚠️ Disclaimer
This script is provided for educational purposes only.
Past performance does not guarantee future results.
Trading involves risk, and users should exercise caution and use proper risk management when applying this strategy.
A single, rule-based system that builds two trendlines from confirmed swing pivots and trades their breakouts, with optional retest, trend-regime gates (EMA / HTF EMA), and ATR-based risk. All parts serve one decision flow: structure → breakout → gated entry → managed risk.
What it does (for traders)
Draws Up line (teal) through the last two Higher Lows and Down line (red) through the last two Lower Highs, then extends them forward.
Long when price breaks above red; Short when price breaks below teal.
Optional Retest entry: after a break, wait for a pullback toward the broken line within an ATR-scaled buffer.
Uses ATR stop and R-multiple target so risk is consistent across symbols/timeframes.
Labels HL1/HL2/LH1/LH2 so non-coders can verify which pivots built each line.
Why these components are combined
Pure breakout systems on trendlines suffer from three practical issues:
False breaks in chop → solved by trend-regime gates (EMA / HTF EMA) that only allow trades aligned with the prevailing trend.
Uneven volatility across markets/timeframes → solved by ATR-based stop/target, normalizing distance so R-multiples are comparable.
First break whipsaws near wedge apices → mitigated by the optional retest rule that demands a pullback/hold before entry.
These modules are not separate indicators with their own signals. They are support roles inside one method.
The pivot engine defines structure, the breakout detector defines signal, the regime gates decide if we’re allowed to take that signal, and the ATR module sizes risk.
Together they make the trendline breakout usable, testable, and explainable.
How it works (mechanism; each component explained)
1) Pivot engine (structure, non-repainting)
Swings are confirmed with ta.pivotlow/high(L, R). A pivot only exists after R bars (no look-ahead), so once plotted, the line built from those pivots will not repaint.
2) Trendline builder (geometry)
Teal line updates when two consecutive pivot lows satisfy HL2.price > HL1.price (and HL2 occurs after HL1).
Red line updates when two consecutive pivot highs satisfy LH2.price < LH1.price.
Lines are extended right and their current value is read every bar via line.get_price().
3) Breakout detector (signal)
On every bar, compute:
crossover(close, redLine) ⇒ Long breakout
crossunder(close, tealLine) ⇒ Short breakdown
4) Regime gates (trend filters, not separate signals)
EMA gate: allow longs only if close > EMA(len), shorts only if close < EMA(len).
HTF EMA gate (optional): same rule on a higher timeframe to avoid fighting the larger trend.
These do not create entries; they simply permit or block the breakout signal.
5) Retest module (optional confirmation)
After a breakout, record the line price. A valid retest occurs if price pulls back within an ATR-scaled buffer toward that broken line and then closes back in the breakout direction.
This reduces first-tick fakeouts.
6) Risk module (position exit)
Initial stop = ATR(len) × atrMult from entry.
Target = tpR × (ATR × atrMult) (e.g., 2R).
This keeps results consistent across instruments/timeframes.
Entries & exits
Long entry
Base: close breaks above red and passes EMA/HTF gates.
Retest (if enabled): after the break, price pulls back near the broken red line (within the ATR buffer) and holds; then enter.
Short entry
Mirror logic with teal (break below & gates), optionally with a retest.
Exit
strategy.exit places ATR stop & R-multiple target automatically.
Optional “flip”: close if the opposite base signal triggers.
How to use it (step-by-step)
Timeframe: 1–15m for intraday, 1–4h for swing.
Start defaults: Pivot L/R = 5, EMA len = 200, ATR len = 14, ATR mult = 2, TP = 2R, Retest = ON.
Tune sensitivity:
Faster lines (more trades): set L/R = 3–4.
Fewer counter-trend trades: enable HTF EMA (e.g., 60-min or Daily).
Visual audit: labels HL1/HL2 & LH1/LH2 show which pivots built each line—verify by eye.
Alerts: use Long breakout, Short breakdown, and Retest alerts to automate.
Originality (why it merits publication)
Trades the visualization: many “auto-trendline” tools only draw lines; this one turns them into testable, alertable rules.
Integrated design: each component has a defined role in the same pipeline—no unrelated indicators bolted together.
Transparent & non-repainting: pivot confirmation removes look-ahead; labels let non-coders understand the setup that produced each signal.
Notes & limitations
Lines update only after pivot confirmation; that lag is intentional to avoid repainting.
Breakouts near an apex can whipsaw; prefer Retest and/or HTF gate in choppy regimes.
Backtests are idealized; forward-test and size risk appropriately.
⚠️ Disclaimer
This script is provided for educational purposes only.
Past performance does not guarantee future results.
Trading involves risk, and users should exercise caution and use proper risk management when applying this strategy.
オープンソーススクリプト
TradingViewの精神に則り、この作者はスクリプトのソースコードを公開しているので、その内容を理解し検証することができます。作者に感謝です!無料でお使いいただけますが、このコードを投稿に再利用する際にはハウスルールに従うものとします。
免責事項
これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、この作者はスクリプトのソースコードを公開しているので、その内容を理解し検証することができます。作者に感謝です!無料でお使いいただけますが、このコードを投稿に再利用する際にはハウスルールに従うものとします。
免責事項
これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。