OPEN-SOURCE SCRIPT

Automated Trendline Breakout Engine

4 567
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.

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.