PROTECTED SOURCE SCRIPT

Auto Trendlines

53
**Overview**
- Automatically draws uptrend and downtrend lines by connecting the latest two pivot highs and pivot lows within a symmetric window.
- Designed for clean, reactive trend visualization with minimal user configuration.

**Features**
- Auto-detection of swing pivots and dynamic line updates on new confirmations.
- Optional right extension for forward projection.
- Built-in line styles: `Solid`, `Dashed`, `Dotted`.
- Customizable colors and line width.
- Lightweight and fast for intraday or higher timeframes.

**Inputs**
- `Calculation Period (odd)`: Window size for pivot detection; must be odd to ensure a unique center bar.
- `Uptrend Line Color`: Color for lines drawn from pivot highs.
- `Downtrend Line Color`: Color for lines drawn from pivot lows.
- `Line Style`: `Solid`, `Dashed`, or `Dotted`.
- `Line Width`: Thickness of the trendlines.
- `Extend Right`: Toggle to extend lines into the future.

**How It Works**
- Uses `ta.pivothigh` and `ta.pivotlow` with symmetric left/right bars derived from the chosen period.
- An odd period guarantees a single center bar (`left = right`), aligning the pivot’s time anchor precisely.
- Once a pivot is confirmed (after the required right bars), the script updates or redraws the uptrend and downtrend lines to connect the last two pivots.

**Notes**
- Larger periods produce smoother, more reliable lines; smaller periods react faster but may be noisier.
- Pivot confirmation requires future bars; lines update when new pivots form, reflecting the most recent structure.
- This script focuses on visual analysis and does not include alerts.

**Compatibility**
- Pine Script v6
- Overlay on price chart (`overlay=true`)
- Optimized for TradingView publication with minimal performance overhead.

**Keywords**
- Trendlines, Auto Trendlines, Pivots, Swing High/Low, Technical Analysis, Pine Script v6

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.