This TradingView indicator automatically detects and draws trend lines (support and resistance) based on recent pivot highs and pivot lows.
-
Automatic Trendline Detection
Finds recent support (ascending) and resistance (descending) lines using pivot points. -
Pivot-Based Logic
Lines are created using pairs of pivots that meet the trend criteria:- Support lines are drawn when higher lows form (uptrend).
- Resistance lines are drawn when lower highs form (downtrend).
-
Configurable Parameters
- Start Date: Choose the date from which the indicator starts drawing lines.
- Pivot Period: Controls how many bars are checked on each side to confirm a pivot.
- Number of Pivots: Defines how many pivot points are stored and compared.
- Colors: Customize the color of support (green) and resistance (red) lines.
-
Dynamic Line Updates
Trendlines are recalculated each bar, automatically removing invalidated ones. -
Optimized Performance
Uses fixed-size arrays and minimal loops for efficient real-time chart updates.
| Parameter | Description | Default |
|---|---|---|
| Start Year / Month / Day | Date to start analyzing data and drawing lines. | 2020 / 1 / 1 |
| Pivot Period | Number of bars on each side required to define a pivot high/low. | 20 |
| Pivot Points to Track | Number of recent pivots stored and checked for line creation. | 3 |
| Uptrend Color | Color for ascending (support) trendlines. | Lime |
| Downtrend Color | Color for descending (resistance) trendlines. | Red |
-
Pivot Identification:
The script continuously scans for pivot highs and lows usingpivothigh()andpivotlow(). -
Pivot Storage:
Detected pivots are pushed into arrays (keeping the most recent N pivots as defined bycheckCount). -
Trendline Validation:
For each pair of pivots:- Support lines are considered valid if price stays above the projected line.
- Resistance lines are valid if price stays below the projected line.
-
Drawing:
Once validated, the trendline is drawn between the two pivot points, using the specified colors.
- Green Lines → Uptrend (Support)
- Red Lines → Downtrend (Resistance)
- Lines automatically appear and adjust as new pivots form.
This indicator is based on open-source code licensed under the Mozilla Public License 2.0 (MPL 2.0).
You are free to modify and use this script for personal or commercial purposes, but you must retain:
- The license header at the top of the script
- The original attribution to the author (radinansari)
- Increasing the Pivot Period makes the trendlines smoother and less frequent.
- Reducing it creates more, shorter lines — useful for scalping or lower timeframes.
- Adjust Start Date if you want to analyze only recent chart history.
- Use different colors for easier visual distinction between supports and resistances.
- Open TradingView.
- Go to the Pine Editor tab.
- Paste the indicator code into the editor.
- Click Add to Chart or Save and Apply.
- Adjust the settings in the indicator’s configuration menu as desired.
Use this indicator to quickly visualize potential trendline bounces, breakouts, or trend reversals.
It’s especially useful when combined with oscillators or volume indicators to confirm setups.
Created and modified for educational and personal use.