Trend Lines with Labels

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.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.