Trend Lines
Feb 4, 2020

The Trend Lines indicator automatically identifies and plots dynamic support and resistance levels by connecting consecutive pivot points to highlight market structure shifts.
Usage
The Usage section describes how the script can be used to identify market trends and potential reversal points.
- Uptrend Identification: When the script detects a Pivot Low (PL) that is higher than the previous Pivot Low, it draws a bullish trend line. This signifies a potential uptrend or a period of ascending support.
- Downtrend Identification: When the script detects a Pivot High (PH) that is lower than the previous Pivot High, it draws a bearish trend line. This signifies a potential downtrend or a period of descending resistance.
- Trend Line Management: The script automatically manages active lines based on the angle of the price action. If a new trend line is formed with a steeper angle (indicating a shift in momentum), the script can stop extending the previous line to keep the chart focused on current market conditions.
- Visualizing History: Users can choose to display historical trend lines as dashed lines, providing a visual record of broken or old market structures while emphasizing the currently active levels.
Details
The script functions by first identifying Pivot Highs and Pivot Lows based on user-defined lookback (Left Bars) and lookforward (Right Bars) periods.
For bearish trend lines, the algorithm checks if the current PH is lower than the previous PH. If this condition is met, a line is drawn connecting them. To maintain clarity, the script compares the angle of the current line with the previous one; if the new angle indicates a stronger trend, the extension of the previous line is terminated.
For bullish trend lines, the algorithm checks if the current PL is higher than the previous PL. If a sequence of higher lows is detected, an uptrend line is generated. Similar to the bearish logic, the script evaluates the slope to determine whether to continue extending old lines or prioritize the most recent structure.
Settings
- Left Bars: Sets the number of bars required to the left of a high or low to confirm a pivot point.
- Right Bars: Sets the number of bars required to the right of a high or low to confirm a pivot point.
- Show Pivot Points: Toggles the visibility of "H" (High) and "L" (Low) labels on the chart.
- Show Old Line as Dashed: When enabled, previously active trend lines are converted to a dashed style once a new line is formed.
- Uptrend line color: Defines the color for bullish trend lines connecting higher lows.
- Downtrend line color: Defines the color for bearish trend lines connecting lower highs.
FAQ
How do I adjust the sensitivity of the trend lines? You can adjust the "Left Bars" and "Right Bars" settings. Lower values will result in more frequent, shorter-term trend lines, while higher values will identify more significant, long-term structural levels.
Why do some trend lines stop extending? The indicator automatically stops extending a line if a new trend line with a more relevant angle is formed, or if the price action dictates that the previous slope is no longer the primary trend.
How can I access this indicator? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.