OPEN-SOURCE SCRIPT
Cập nhật

ATR SL

88


### 📘 **스크립트 설명 — 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
//
//──────────────────────────────────────────────────────────────
Phát hành các Ghi chú
📘 ATR SL — Volatility-Based Stop (ATR10, RMA)

English

What it does
Draws a thin stop line per bar using ATR(10) and your chosen multiplier:
Stop = Low − ATR(10) × m.
To avoid undersizing volatility early in the session, the indicator uses a conservative ATR used:

Intraday (bar not confirmed): ATR used = max( ATR(10), ATR(10)[1] )

After close (bar confirmed): ATR used = ATR(10) (today’s confirmed value)

Key terms

ATR(10): 10-period Average True Range with RMA (Wilder) smoothing on the chart’s timeframe.

ATR used: the ATR value actually used to compute today’s stop, per the rules above.

Formulae

TrueRange = max( high−low, |high−close[1]|, |low−close[1]| )

ATR(10) = RMA(TrueRange, 10)

Stop (long) = Low − ATR used × m

Inputs

Length: ATR period (default 10)

Smoothing: RMA / SMA / EMA / WMA (RMA recommended)

Multiplier (m): stop distance factor (e.g., 1.01)

Long Base: usually Low (you can change the base)

Lookback: bars to scan for the recent max stop label (default 5)

Show Price Line: toggle the plotted stop line

Outputs

Stop line (thin, on-chart) computed from Low − ATR used × m

Today label: shows today’s stop value above the current bar

5-bar Max label: shows the highest stop over the recent lookback

Notes

Works on any timeframe; ATR is computed on the current chart timeframe by default.

If you prefer a daily-ATR model (same as your Risk Sizer), you can swap ATR with request.security(…, "D", …).



한국어

무엇을 하나요?
각 봉의 ATR(10) 과 배수를 이용해 얇은 스탑 라인을 그립니다:
스탑 = 저가 − ATR(10) × m.
장 초반 변동성 과소평가를 피하기 위해 보수적인 ATR used 규칙을 적용합니다.

장중(미확정 봉): ATR used = max( 오늘 ATR(10), 전일 ATR(10) )

마감 후(확정 봉): ATR used = 오늘 ATR(10) (확정값)

용어

ATR(10): 차트 타임프레임 기준, RMA(윌더) 스무딩의 10기간 ATR.

ATR used: 위 규칙에 따라 실제 스탑 계산에 사용하는 ATR 값.

계산식

TrueRange = max( 고−저, |고−전일종가|, |저−전일종가| )

ATR(10) = RMA(TrueRange, 10)

롱 스탑 = 저가 − ATR used × m

입력값

Length: ATR 기간(기본 10)

Smoothing: RMA / SMA / EMA / WMA (권장: RMA)

Multiplier (m): 스탑 거리 배수(예: 1.01)

Long Base: 보통 저가(원하면 다른 기준으로 변경 가능)

Lookback: 최근 맥시멈 스탑 라벨 탐색 기간(기본 5)

Show Price Line: 스탑 라인 표시 토글

출력

스탑 라인: 저가 − ATR used × m 기반 얇은 라인

오늘 라벨: 현재 봉 위에 오늘 스탑 값

5봉 맥스 라벨: Lookback 구간 내 최고 스탑 값

비고

기본은 현재 차트 타임프레임 ATR.

항상 일봉 ATR을 원한다면 request.security(…, "D", …)로 손쉽게 전환 가능합니다.

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

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.