OPEN-SOURCE SCRIPT
ATR SL

### ๐ **์คํฌ๋ฆฝํธ ์ค๋ช โ ATR ๊ธฐ๋ฐ ์คํ๋ก์ค ํ์๊ธฐ (ATR SL)**
์ด ์คํฌ๋ฆฝํธ๋ **์บ๋ค ์ ๊ฐ(low)์ ATR(ํ๊ท ์งํญ ์งํ)** ๋ฅผ ํ์ฉํด
ํธ๋ ์ด๋ฉ ์ **๋์ ์ธ ์คํ๋ก์ค ๋ผ์ธ๊ณผ ๋ผ๋ฒจ**์ ์๋์ผ๋ก ํ์ํด์ฃผ๋ ์ธ๋์ผ์ดํฐ์ ๋๋ค.
---
#### ๐ง **๊ธฐ๋ณธ ๋ก์ง**
* **๊ฐ ๋ด๋ณ ATR(10)** ์ ์ด์ฉํ์ฌ ๋ณ๋์ฑ ๊ธฐ๋ฐ ์คํ๋ก์ค ๊ณ์ฐ
โ `ATR SL = ์ ๊ฐ - ATR(10) ร Multiplier`
* **์ค๋ ๋ด(์ค์๊ฐ)** ์ ๋ณ๋์ฑ์ด ์๊ฒ ์กํ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด
`์ค๋ ATR`๊ณผ `์ ์ผ ATR` ์ค **๋ ํฐ ๊ฐ**์ ์ฌ์ฉ
* ๊ณผ๊ฑฐ ๋ด๋ค์ ํด๋น ์์ ์ **๊ทธ๋ ATR**๋ก ๊ณ์ฐ๋์ด ๊ณ ์ ๋จ
---
#### ๐ฏ **ํ์ ์์**
| ํญ๋ชฉ | ์ค๋ช |
| --------------------- | ----------------------------------- |
| **ํํฌ ๋ผ์ธ** | ๊ฐ ๋ด๋ณ ์คํ๋ก์ค ๋ผ์ธ (`์ ๊ฐ - ATR ร m`) |
| **์ค๋ ์คํ ๋ผ๋ฒจ** | ํ์ฌ ์บ๋ค ์์ ํ์๋๋ ์ค๋ ๊ธฐ์ค ์คํ ๊ฐ๊ฒฉ |
| **์ต๊ทผ 5์ผ ์ค ๋งฅ์๋ฉ ์คํ ๋ผ๋ฒจ** | ์ต๊ทผ 5์ผ๊ฐ ๊ฐ์ฅ ๋์ ์คํ๋ก์ค ๊ฐ์ด ๋ฐ์ํ ๋ด ์์ 1๊ฐ ํ์ |
---
#### โ๏ธ **์ฃผ์ ์ค์ ๊ฐ**
| ์ด๋ฆ | ์ค๋ช | ๊ธฐ๋ณธ๊ฐ |
| ------------ | -------------------------------- | ---- |
| `Length` | ATR ๊ณ์ฐ ๊ธฐ๊ฐ | 10 |
| `Smoothing` | ATR ๊ณ์ฐ ๋ฐฉ์ (RMA/SMA/EMA/WMA ์ค ์ ํ) | RMA |
| `Multiplier` | ATR ๋ฐฐ์ (๋ฆฌ์คํฌ ์ฌ์ ์กฐ์ ) | 1.01 |
| `Long Base` | ๊ธฐ์ค๊ฐ (๋ณดํต ์ ๊ฐ low ์ฌ์ฉ) | low |
| `Lookback` | ์ต๊ทผ N๋ด ์ค ์ต๊ณ ์คํ ํ์ ๊ตฌ๊ฐ | 5 |
---
#### ๐จ **์์**
* ๋ผ์ธ: ์ฐํํฌ (`rgba(255,105,180,0.3)`)
* ๋ผ๋ฒจ: ์งํ ํํฌ (`rgba(255,105,180,0.1)`)
* ํ ์คํธ: ํฐ์
---
#### ๐ **ํ์ฉ ์์**
* **์คํ๋ก์ค ์ค์ :**
ATR ๊ธฐ๋ฐ์ ๋ณ๋์ฑ ๋์ํ ์คํ๋ผ์ธ์ ์ฆ์ ์๊ฐํ
* **๋ฆฌ์คํฌ ๊ด๋ฆฌ:**
๋ณ๋์ฑ์ด ์ค์ด๋ค ๋๋ ์ง๋์น๊ฒ ์ข์ ์คํ์ ๋ฐฉ์ง (์ค๋ ๋ด์ `max(์ค๋ATR, ์ ์ผATR)` ์ ์ฉ)
* **ํธ๋ ์ผ๋ง ์คํ ์ฉ๋:**
์์น ์ถ์ธ์์ ์ต๊ทผ 5์ผ ์ค ์ต๊ณ ์คํ ๋ผ๋ฒจ ์ฐธ๊ณ ๊ฐ๋ฅ
---
#### ๐ง **์ฃผ์์ฌํญ**
* ๋ผ๋ฒจ์ ํญ์ **2๊ฐ๋ง ํ์๋จ**
โ ์ค๋ ์คํ 1๊ฐ + ์ต๊ทผ 5์ผ ๋งฅ์๋ฉ ์คํ 1๊ฐ
* ํ๋จ ๋ณด์กฐ์ฐฝ์ด ์๋๋ผ **๋ฉ์ธ ์ฐจํธ ์(`overlay=true`)** ์ ํ์
* ๋ฉํฐ๋ผ์ธ ๋ฌธ๋ฒ ์ค๋ฅ ๋ฐฉ์ง๋ฅผ ์ํด ๋ชจ๋ `label.new()`๋ **ํ ์ค๋ก ์์ฑ๋จ**
---
#### ๐ฌ **์์ฝ**
> ATR SL = ๋ณ๋์ฑ์ ๋ฐ์ํ ์ค์ ์ฉ ์คํ๋ก์ค ํ์๊ธฐ
> โ ์ค์๊ฐ ATR ๋ณด์ (`max(์ค๋, ์ด์ )`)์ผ๋ก ์ฅ ์ด๋ฐ ์๊ณก ๋ฐฉ์ง
> โ ์ต๊ทผ 5์ผ ์ต๊ณ ์คํ๊ณผ ์ค๋ ์คํ์ ํจ๊ป ์๊ฐํํด ์ถ์ธ ํ์ ์ฉ์ด
---
ํ์ํ๋ฉด ์ ๋ชฉ ์๋์ ์ด๋ฐ ๋ฌธ๊ตฌ๋ฅผ ์ถ๊ฐํด๋ ์ข์๐
> โBy turtlekim ๐ข โ ๋ณ๋์ฑ ๊ธฐ๋ฐ ๋ฆฌ์คํฌ ๋งค๋์ง๋จผํธ์ฉ Pine Scriptโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ ATR SL โ ๋ณ๋์ฑ ๊ธฐ๋ฐ ์คํ๋ก์ค ํ์๊ธฐ (by turtlekim)
//
// This script visualizes a **volatility-based stop loss** line
// using each candle's **Low** and **ATR(10)** value.
// Designed for traders who want adaptive, risk-adjusted stop levels.
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ง ๊ธฐ๋ณธ ๋ก์ง / Core Logic
// - ATR SL = Low - ATR(10) ร Multiplier
// - For historical candles โ uses that day's ATR(10)
// - For the current (realtime) candle โ uses max(Todayโs ATR, Previous ATR)
// to prevent unrealistically small stops when volatility is low early in the session.
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ฏ ํ์ ์์ / Display Elements
// โข Pink line โ ATR-based stop line per candle
// โข Pink label โ Todayโs stop (current candle)
// โข Pink label โ Highest stop over the past 5 bars (1 label only)
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// โ๏ธ ์ฃผ์ ์ค์ ๊ฐ / Key Parameters
// Length : ATR period (default = 10)
// Smoothing : Type of ATR averaging (RMA/SMA/EMA/WMA)
// Multiplier : Adjusts distance from Low (default = 1.01)
// Long Base : Reference price (usually Low)
// Lookback : Number of bars for max stop check (default = 5)
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐จ ์์ / Color Scheme
// โข Line : Light pink (rgba(255,105,180,0.3))
// โข Labels : Solid pink (rgba(255,105,180,0.1))
// โข Text : White
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ ํ์ฉ ์์ / How to Use
// - Set your stop-loss visually at the pink line (ATR-based distance).
// - For position sizing, use this stop level to calculate volatility risk.
// - Track both todayโs stop and the 5-bar max stop to monitor trailing support.
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ง ์ฃผ์์ฌํญ / Notes
// โข Only two labels are shown: Todayโs stop + 5-bar max stop.
// โข Works only on main chart (overlay=true).
// โข All label.new() statements are written in a single line
// to avoid syntax errors in Pine Script.
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ฌ ์์ฝ / Summary
// ATR SL = Dynamic, volatility-adjusted stop loss visualizer
// โ Prevents premature stopouts in early low-volatility periods
// โ Highlights both current and recent 5-bar maximum stops
//
//โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.