OPEN-SOURCE SCRIPT
Auto Trend [theUltimator5]

The Auto Trend indicator was designed to be a unique pattern detection indicator without the use of standard pivot point logic or high/low lines. It is a study in pattern detection by using iterative best-fit logic.
The indicator automatically identifies and draws trend channels by analyzing price action across configurable lookback periods. It finds optimal high and low trendlines that contain price movement, with a middle line marking the trend's center.
Key Features:
How It Works:
The indicator divides the lookback period into thirds, finds the highest and lowest closes in the first and last thirds, then draws trendlines connecting these points. It can automatically search through different lookback periods to find the one with the fewest price violations (closes outside the channel).
Settings:
Use Cases:
The indicator supports up to 5000 bars of historical data for comprehensive trend analysis.
The indicator automatically identifies and draws trend channels by analyzing price action across configurable lookback periods. It finds optimal high and low trendlines that contain price movement, with a middle line marking the trend's center.
Key Features:
- Automatic Pattern Detection - Intelligently searches for the best lookback period where price stays within the channel boundaries
- Dual Pattern Modes - Choose between Short (20-66 bars) for quick patterns or Long (50-500 bars) for extended trends. Note - the long pattern is fully configurable and can be set anywhere up to 5000 bars.
- Smart Caching - Optimized performance that only recalculates when necessary
- Customizable Starting Point - Click directly on the chart to set where the trend channel begins
- Flexible Lookback Range - Set minimum and maximum lookback periods to match your trading style
- Visual Debugging - Optional label displays the active lookback period and violation count
How It Works:
The indicator divides the lookback period into thirds, finds the highest and lowest closes in the first and last thirds, then draws trendlines connecting these points. It can automatically search through different lookback periods to find the one with the fewest price violations (closes outside the channel).
Settings:
- Use Auto Lookback - Enable automatic optimal lookback detection
- Pattern Length - Short (faster, 1-bar increments) or Long (broader, 5-bar increments)
- Min/Max Lookback - Define the search range for the Long pattern
- Manual Lookback - Override auto-detection with a fixed period
- Custom Colors - Personalize the high, low, and middle line colors
- Starting Point - Select where the trend analysis begins
Use Cases:
- Identify dominant trend channels across different timeframes
- Spot potential support and resistance levels
- Determine trend strength and consistency
- Time entries and exits based on channel position
The indicator supports up to 5000 bars of historical data for comprehensive trend analysis.
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.