OPEN-SOURCE SCRIPT
업데이트됨 Swing Trade Defender

You're in a trade. Defender watches it for the five ways swing trades fail — plus an ATR trailing stop — and shows one status: OK, CAUTION, or EXIT.
Finding the trade is the easy half. The hard half is admitting when it stops working — and doing it before a small loss becomes a big one. Swing Trade Defender watches your open trade bar by bar and does the admitting for you.
Set your direction (long or short) and, if you want, your entry price. It handles the rest — it works on its own, nothing else required.
Why five flags instead of one exit signal?
Every one of these signals fires false alarms by itself — an RSI dip, a single heavy-volume red bar, a wick through the 20 EMA.
Real trade failure rarely announces itself through one signal; it shows up as agreement between independent ones: trend, structure, momentum, participation, and volatility.
So Defender treats them as a vote. One or two flags is a warning to pay attention; three is a failed trade by definition — enough independent evidence that the odds have flipped. The one exception is the ATR trail, which triggers EXIT on its own, because a stop is a stop. The voting logic — not any individual component — is the tool.
The five failure flags — each worth 1 point
- Trend break — price closes through the 20-EMA (the trend's home line) the wrong way.
- Structure break — price takes out the prior swing low (for a long), the first crack in the pattern.
- Momentum rollover — RSI falls back through 50 and keeps dropping.
- Distribution — a down bar on 1.5× average volume or more: big sellers showing their hand.
- Trail hit — price closes through the ATR trailing stop (a chandelier-style stop that ratchets up behind price, 2.5 × ATR-14 by default; ATR = average bar range).
All five flip automatically for shorts — there a close above the MA, a break of the prior swing high, rising RSI, and heavy buying (accumulation) are the danger signs.
How the status reads
- OK — no flags. Let it work.
- CAUTION (1–2 flags) — an orange triangle marks the bar. Hover it and a tooltip lists exactly which flags are up.
- EXIT — 3 or more flags (you can set the threshold), or any trail hit on its own. A red ✕ marks the bar, with a box listing what failed.
Markers sit above the bar for longs and below it for shorts, so they never crowd the side your risk is on.
The status panel
One table shows the whole picture: status, flag count (x/5), each flag's own line (hold/break), the live ATR trail price, your entry, and open P/L when you've set an entry price.
Alerts
Two built-in alert conditions — "Exit signal" and "Caution" — so TradingView can ping your phone instead of you watching the screen.
Settings — defaults work out of the box
Tuned for swing trades held days to weeks:
- Trend MA length (20), swing lookback (8 bars), RSI length (14) and rollover level (50), volume spike multiple (1.5×).
- ATR trail — length (14) and multiple (2.5).
- Flags needed for EXIT (3 by default, 1–5).
- Panel position/size, marker history on/off, optional background shading, dark/light theme, colors.
⚠ Educational risk-management tool. EXIT means the trade has failed by these rules — whether to act is always your decision. It does not place orders, and a flag is not a prediction. Not financial advice.
릴리즈 노트
v1.1 — display fix: the Open P/L percentage was printed wrongThe Open P/L row was formatted with the wrong pattern. In a Pine format
string only # and 0 act as digit placeholders — any other digit is printed
literally, and the number is rounded to a whole number first. The panel used
"#.1", so:
a true +2.4% was printed as "+2.1%"
a true -0.75% was printed as "-1.1%"
Every open P/L reading ended in .1 regardless of the actual figure.
The P/L calculation itself was never wrong, and no signal, flag, status or
alert used the printed text — the EXIT and CAUTION logic is unaffected by
this update. Only the number shown in that one row changes, and it now
matches what your position is actually doing.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.