OPEN-SOURCE SCRIPT
Updated

ATR Stop-Loss & Targets

1 198
ATR and Supertrend-based SL/TP & Trailing System

This indicator combines Average True Range (ATR) and Supertrend logic to help traders define precise stop-loss, first target, and trailing stop-loss (TSL) levels.

⚙️ Key Features:
📏 ATR-based Stop-Loss & Target Lines:

Uses ATR (default period: 5) based on the previous day's candle for more stable risk management.

  • Traders can choose the price source: Close, Open, or enter a manual price.
  • SL and first target are calculated using multipliers:


Multiplier 1 = Stop Loss

Multiplier 2 = First Target

  • 📉 Supertrend for Trailing Stop:
  • Built-in Supertrend logic for trailing stop-loss management.


Uses ATR(10) with a multiplier of 2.1, based on HL2.

Supertrend can be toggled ON/OFF from the settings.
Release Notes
Overview: This free indicator combines ATR-based Stop Loss and Targets with a Supertrend-based Trailing Stop Loss, giving traders an all-in-one system for defining their risk, entry size, and managing trailing exits automatically.

It is designed to help traders quickly determine:

  1. Optimal Stop-Loss and Target levels based on volatility (ATR)
  2. Correct position size based on maximum loss they can afford
  3. Dynamic trailing stop-loss using a Supertrend


⚙️ How It Works:
1️⃣ ATR-Based Stop-Loss and Target Levels
  • The indicator calculates ATR (Average True Range) with a default period of 5.
  • You can choose if ATR is calculated based on the current candle or the previous candle.
  • Two multipliers are applied:


  • Multiplier 1: For Stop-Loss
  • Multiplier 2: For First Target


Input Options Available:

  • Price Source: Choose from Close, Open, or manually enter a custom price. Default value is Close
  • ATR Source Candle: Select Current or Previous. Default is Previous candle
  • ATR Period: Default is 5 (modifiable).
  • Multipliers: Set your desired levels for Stop-Loss and Target individually.




✨ Visualization:
  • Horizontal lines are drawn for both Stop-Loss and First Target levels.
  • Color and style of the lines are customizable (solid, dashed, dotted).
  • Labels at the end of each line show exact price values.


2️⃣ Maximum Loss Control (Position Size Calculation)
  • You can input a Max Loss Amount (default: 10,000).
  • The system automatically calculates:



  • Risk per share = difference between entry price and stop-loss.
  • Position Size = (Max Loss) ÷ (Risk per share).
  • Actual Calculated Loss = (Position Size × Risk per share).


✨ Visualization:
  • A floating label below the candles displays:
  • Position Size (rounded to nearest whole number)
  • Actual Calculated Loss (based on real size, not estimation)
  • Toggle ON/OFF the label using settings.


3️⃣ Supertrend Trailing Stop-Loss
  • Built-in Supertrend using:

ATR Period = 10
ATR Multiplier = 2.1
Source = HL2 (High + Low / 2)
  • You can choose to:

Enable or disable Supertrend
Highlight background based on trend direction
Show Buy/Sell Signals
  • Alerts are available when Supertrend switches direction.


✨ Visualization:
  • Uptrend = Green Supertrend Line
  • Downtrend = Orange Supertrend Line
  • Optional: Highlight background colors depending on trend.

snapshot

Release Notes
Overview: This free indicator combines ATR-based Stop Loss and Targets with a Supertrend-based Trailing Stop Loss, giving traders an all-in-one system for defining their risk, entry size, and managing trailing exits automatically.

It is designed to help traders quickly determine:

  1. Optimal Stop-Loss and Target levels based on volatility (ATR)
  2. Correct position size based on maximum loss they can afford
  3. Dynamic trailing stop-loss using a Supertrend


⚙️ How It Works:
1️⃣ ATR-Based Stop-Loss and Target Levels
  • The indicator calculates ATR (Average True Range) with a default period of 5.
  • You can choose if ATR is calculated based on the current candle or the previous candle.
  • Two multipliers are applied:


  • Multiplier 1: For Stop-Loss
  • Multiplier 2: For First Target


Input Options Available:

  • Price Source: Choose from Close, Open, or manually enter a custom price. Default value is Close
  • ATR Source Candle: Select Current or Previous. Default is Previous candle
  • ATR Period: Default is 5 (modifiable).
  • Multipliers: Set your desired levels for Stop-Loss and Target individually.




✨ Visualization:
  • Horizontal lines are drawn for both Stop-Loss and First Target levels.
  • Color and style of the lines are customizable (solid, dashed, dotted).
  • Labels at the end of each line show exact price values.

snapshot
2️⃣ Maximum Loss Control (Position Size Calculation)
  • You can input a Max Loss Amount (default: 10,000).
  • The system automatically calculates:



  • Risk per share = difference between entry price and stop-loss.
  • Position Size = (Max Loss) ÷ (Risk per share).
  • Actual Calculated Loss = (Position Size × Risk per share).


✨ Visualization:
  • A floating label below the candles displays:
  • Position Size (rounded to nearest whole number)
  • Actual Calculated Loss (based on real size, not estimation)
  • Toggle ON/OFF the label using settings.


3️⃣ Supertrend Trailing Stop-Loss
  • Built-in Supertrend using:

ATR Period = 10
ATR Multiplier = 2.1
Source = HL2 (High + Low / 2)
  • You can choose to:

Enable or disable Supertrend
Highlight background based on trend direction
Show Buy/Sell Signals
  • Alerts are available when Supertrend switches direction.


✨ Visualization:
  • Uptrend = Green Supertrend Line
  • Downtrend = Orange Supertrend Line
  • Optional: Highlight background colors depending on trend.

snapshot

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.