OPEN-SOURCE SCRIPT

ATR SL Trailing

Introduction
This script is based on the average true range (ATR) and has been improved with the HHV or LLV. The script supports the trader to have his stoploss trailed. In this case, the stoploss is dynamic and can be adjusted with each candleclose.

█ What Does This Indicator Do?
The ATR SL Trailing Indicator helps you dynamically adjust your stop-loss levels based on market movements. It uses market volatility to calculate trailing stop-loss levels, ensuring you can secure profits or minimize losses. The indicator creates two lines:
  • A green/red line for long positions (when you’re betting on prices going up).
  • A green/red line for short positions (when you’re betting on prices going down).


█ Key Concepts: How Does the Indicator Work?
The Average True Range (ATR) measures market volatility, showing how much the price moves over a specific period.
  • A high ATR indicates a volatile market (large price swings), while a low ATR indicates a quiet market (smaller price changes).
  • Why is ATR important? ATR helps dynamically adjust the distance between your stop-loss and the current price. In volatile markets, the stop-loss is placed further away to avoid being triggered by short-term fluctuations. In quieter markets, the stop-loss is set closer to the price.


The HHV is the highest price over a specific period. For long positions, the indicator uses the highest price minus an ATR-based value to determine the stop-loss level.
  • Why is HHV important? HHV ensures the stop-loss for long positions only moves up when the price reaches new highs. Once the price starts falling, the stop-loss remains unchanged to lock in profits or minimize losses.


The LLV is the lowest price over a specific period. For short positions, the indicator uses the lowest price plus an ATR-based value to determine the stop-loss level.
  • Why is LLV important? LLV ensures the stop-loss for short positions only moves down when the price reaches new lows. Once the price starts rising, the stop-loss remains unchanged to lock in profits or minimize losses.


█How Does the Indicator Work?
  1. For Long Positions:

The indicator sets the stop-loss below the current price, based on:
  • Market volatility (ATR).
  • The highest price over a specific period (HHV).
  • The line turns green when the current price is above the stop-loss.
  • The line turns red when the price drops below the stop-loss, signaling you may need to exit the trade.


  1. For Short Positions:

The indicator sets the stop-loss above the current price, based on:
*Market volatility (ATR).
*The lowest price over a specific period (LLV).
*The line turns green when the current price is below the stop-loss.
*The line turns red when the price moves above the stop-loss, signaling you may need to exit the trade.

Advantages of the ATR SL Trailing Indicator
*Dynamic and adaptive: Automatically adjusts stop-loss levels based on market volatility.
*Visual clarity: Green and red lines clearly indicate whether your position is safe or at risk.
*Effective risk management: Helps you lock in profits and minimize losses without the need for constant manual adjustments.

When Should You Use This Indicator?
*If you practice trend-based trading and want your stop-losses to automatically adapt to market movements.
*In volatile markets, to avoid being stopped out by short-term fluctuations.
*When you want to implement efficient risk management without manually adjusting your positions.

Inputs
The user can set the indicator for both longs and shorts. This is particularly important because the calculation is different. The HHV is used for longs and the LLV for shorts. The user can therefore set the period/length for the ATR on the one hand and the HHV/LLV on the other. He also has a multiplier, which can also be customized. The multiplier multiplies the price change of each individual candle.

Color Change
If the SL is trailed and the price breaks a line, the color changes. In this case, it would have executed the SL on an open trade.
Portfolio managementTrend AnalysisVolatility

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Thông báo miễn trừ trách nhiệm