Skip to content

RadinAnsari/autoTrendLine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

📈 Auto trend line

Overview

This TradingView indicator automatically detects and draws trend lines (support and resistance) based on recent pivot highs and pivot lows.

🔧 Features

  • 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.


⚙️ Inputs Explained

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

🧮 How It Works

  1. Pivot Identification:
    The script continuously scans for pivot highs and lows using pivothigh() and pivotlow().

  2. Pivot Storage:
    Detected pivots are pushed into arrays (keeping the most recent N pivots as defined by checkCount).

  3. 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.
  4. Drawing:
    Once validated, the trendline is drawn between the two pivot points, using the specified colors.


🖼️ Visual Output

  • Green Lines → Uptrend (Support)
  • Red Lines → Downtrend (Resistance)
  • Lines automatically appear and adjust as new pivots form.

⚖️ License Notice

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)

💡 Tips

  • 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.

📘 How to Use

  1. Open TradingView.
  2. Go to the Pine Editor tab.
  3. Paste the indicator code into the editor.
  4. Click Add to Chart or Save and Apply.
  5. Adjust the settings in the indicator’s configuration menu as desired.

🧾 Example Use Case

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published