OPEN-SOURCE SCRIPT

Trend Lines with Labels

200
This Pine Script indicator, titled "Trend Lines with Labels", is designed to automatically detect and plot uptrend and downtrend lines on the chart based on recent price action over a user-defined lookback period. The user can adjust the lookback value (default is 40) to control how far back the script searches for significant highs and lows.

The script identifies the highest high and lowest low within the lookback window, along with the bars on which they occur (highest_bar, lowest_bar). If a new high or low is detected compared to the previous bar, it calculates the slope (or gradient) of the trend line and uses line.new() to draw a new trend line from the past pivot point to the current one. Each new line replaces the old one to keep the chart clean.

Additionally, the script places dynamic labels on the chart when a new uptrend or downtrend level is detected. These labels show the type of trend and the corresponding price value. The labels are color-coded for clarity—green for uptrend and red for downtrend—and are automatically deleted and redrawn to prevent clutter.

This tool is useful for visually identifying short-term trend reversals.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.