OPEN-SOURCE SCRIPT
Automated Trendline Breakout Engine

Overview
**Automated Trendline Breakout Engine ** automatically detects swing highs and swing lows to build dynamic support and resistance trendlines. The indicator continuously updates these trendlines as new pivots form and generates BUY and SELL signals whenever price breaks above resistance or below support.
The script is designed to provide traders with an objective method of identifying trendline breakouts without manually drawing trendlines.
Features
* Automatic swing high and swing low detection
* Dynamic resistance trendlines
* Dynamic support trendlines
* Real-time breakout detection
* BUY signals when price breaks above resistance
* SELL signals when price breaks below support
* Broken trendlines automatically change to dashed style
* Customizable swing length
* Customizable trendline colors
* Optional signal display
How It Works
1. Swing Detection
The indicator identifies pivot highs and pivot lows using the selected **Trendline Swing Length**.
Higher values:
* Detect stronger market swings
* Produce fewer but more reliable trendlines
Lower values:
* Detect more swings
* Generate more frequent signals
2. Trendline Construction
Resistance trendlines connect the two most recent pivot highs.
Support trendlines connect the two most recent pivot lows.
Only the latest valid trendline of each type is displayed.
3. Breakout Logic
A BUY signal is generated when:
* Price closes above the active resistance trendline
* Previous candle closed below or on the trendline
* The trendline has not already been broken
A SELL signal is generated when:
* Price closes below the active support trendline
* Previous candle closed above or on the trendline
* The trendline has not already been broken
Once broken, the trendline changes to a dashed line to indicate it has already produced its breakout signal.
Inputs
Trendline Swing Length
Controls pivot sensitivity.
Recommended values:
* 5–8 : Short-term trading
* 10–15 : Swing trading
* 20+ : Position trading
Show Trendline Breakout Signals
Enable or disable BUY/SELL labels.
Trendline Colors
Customize the appearance of:
* Resistance trendlines
* Support trendlines
Best Used On
Works well on:
* Stocks
* Forex
* Crypto
* Commodities
* Indices
Suitable for:
* 15 Minute
* 1 Hour
* 4 Hour
* Daily
Tips
For better accuracy, combine this indicator with:
* Volume confirmation
* Moving averages
* RSI
* MACD
* Higher timeframe trend analysis
* Support and resistance zones
Avoid trading every breakout without confirmation, especially during low-volatility or ranging markets.
Limitations
* Trendlines are based on confirmed pivot points, so they appear only after the required number of bars has completed.
* Breakout signals are generated after pivot confirmation, not before.
* False breakouts can occur in sideways markets.
* This indicator does not predict future price movement; it only reacts to confirmed price action.
Version Notes
Fixed version improvements:
* Accurate trendline price calculation using `line.get_price()`
* Reliable breakout detection
* Prevention of duplicate breakout signals
* Automatic dashed styling for broken trendlines
* Cleaner trendline management
Disclaimer
This indicator is provided for educational and informational purposes only. It should not be considered financial or investment advice. Always perform your own analysis and use proper risk management before making trading decisions.
**Automated Trendline Breakout Engine ** automatically detects swing highs and swing lows to build dynamic support and resistance trendlines. The indicator continuously updates these trendlines as new pivots form and generates BUY and SELL signals whenever price breaks above resistance or below support.
The script is designed to provide traders with an objective method of identifying trendline breakouts without manually drawing trendlines.
Features
* Automatic swing high and swing low detection
* Dynamic resistance trendlines
* Dynamic support trendlines
* Real-time breakout detection
* BUY signals when price breaks above resistance
* SELL signals when price breaks below support
* Broken trendlines automatically change to dashed style
* Customizable swing length
* Customizable trendline colors
* Optional signal display
How It Works
1. Swing Detection
The indicator identifies pivot highs and pivot lows using the selected **Trendline Swing Length**.
Higher values:
* Detect stronger market swings
* Produce fewer but more reliable trendlines
Lower values:
* Detect more swings
* Generate more frequent signals
2. Trendline Construction
Resistance trendlines connect the two most recent pivot highs.
Support trendlines connect the two most recent pivot lows.
Only the latest valid trendline of each type is displayed.
3. Breakout Logic
A BUY signal is generated when:
* Price closes above the active resistance trendline
* Previous candle closed below or on the trendline
* The trendline has not already been broken
A SELL signal is generated when:
* Price closes below the active support trendline
* Previous candle closed above or on the trendline
* The trendline has not already been broken
Once broken, the trendline changes to a dashed line to indicate it has already produced its breakout signal.
Inputs
Trendline Swing Length
Controls pivot sensitivity.
Recommended values:
* 5–8 : Short-term trading
* 10–15 : Swing trading
* 20+ : Position trading
Show Trendline Breakout Signals
Enable or disable BUY/SELL labels.
Trendline Colors
Customize the appearance of:
* Resistance trendlines
* Support trendlines
Best Used On
Works well on:
* Stocks
* Forex
* Crypto
* Commodities
* Indices
Suitable for:
* 15 Minute
* 1 Hour
* 4 Hour
* Daily
Tips
For better accuracy, combine this indicator with:
* Volume confirmation
* Moving averages
* RSI
* MACD
* Higher timeframe trend analysis
* Support and resistance zones
Avoid trading every breakout without confirmation, especially during low-volatility or ranging markets.
Limitations
* Trendlines are based on confirmed pivot points, so they appear only after the required number of bars has completed.
* Breakout signals are generated after pivot confirmation, not before.
* False breakouts can occur in sideways markets.
* This indicator does not predict future price movement; it only reacts to confirmed price action.
Version Notes
Fixed version improvements:
* Accurate trendline price calculation using `line.get_price()`
* Reliable breakout detection
* Prevention of duplicate breakout signals
* Automatic dashed styling for broken trendlines
* Cleaner trendline management
Disclaimer
This indicator is provided for educational and informational purposes only. It should not be considered financial or investment advice. Always perform your own analysis and use proper risk management before making trading decisions.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.