OPEN-SOURCE SCRIPT

Trend Lines by Kris

13 890
This indicator is an automated tool designed to identify and draw valid trend lines directly on your chart, based on significant price swing points (pivots). It helps traders visualize the current trend structure without manually drawing lines.

How it works

The script detects pivot highs and pivot lows using a configurable sensitivity period. A pivot high is confirmed when its price is the highest point within the surrounding bars on both sides. A pivot low is confirmed symmetrically. Once two consecutive pivot highs form a descending sequence, the script attempts to draw a Supply (downtrend) line. Once two consecutive pivot lows form an ascending sequence, it attempts to draw a Demand (uptrend) line.
Before drawing, each candidate line goes through a strict validation process:

No candle body (open or close) may cross the line between the two pivot points
No candle body may cross the projected line from the second pivot up to the current bar
The line angle must fall within a realistic range to filter out near-vertical lines

This ensures that only clean, unbroken trend lines are displayed.

Unique Feature: Auto-Break Detection

The indicator continuously monitors price action against each active trend line. If a candle body closes beyond the line, the trend line is automatically fixed at the point of the break and stops extending. A new trend line will be drawn as soon as the next valid pivot structure forms. Up to 3 historical trend lines per side are kept on the chart so you can see recent structure at a glance.

Angle labels
Each trend line displays its angle in degrees at the starting point, normalized to the visible price range. This gives you a quick read on trend momentum — steeper angles indicate stronger, faster-moving trends.
Alerts
Two alert conditions are available:

Supply Line Break — fires when price closes above an active downtrend line
Demand Line Break — fires when price closes below an active uptrend line

Settings

Sensitivity: controls how significant a price swing must be to qualify as a pivot. Higher values produce fewer but more meaningful trend lines
Supply Lines / Demand Lines: toggle each direction independently
Line width: visual preference
Supply color / Demand color: customize to match your chart style

Usage

Use Supply lines as dynamic resistance and Demand lines as dynamic support. A confirmed body close beyond the line signals a potential trend change. Combine with your existing levels or imbalance zones for higher-confidence entries.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.