OPEN-SOURCE SCRIPT
Donchian Breakout with ATR Trailing Stop (Trend Following)

A simple, transparent trend-following strategy: a classic Donchian
(turtle) channel breakout with a single ATR-based trailing stop.
It was deliberately built to be robust across markets rather than
curve-fit to one — the same code and settings held up on both an
equity index (DAX/GER40, 1h) and Bitcoin (BTCUSD, 4h), and across
trailing multipliers of 2.5–3.5.
HOW IT WORKS
- Entry: goes long when price closes above the highest high of the
last N bars (default 20) while above the 200 EMA trend filter.
Short side is optional and off by default.
- Exit: one ATR-based trailing stop (distance = ATR × multiplier,
default 2.5, fixed at entry). It serves as both the initial
protective stop and the trailing exit — cutting losses and letting
winners run, fully automatically. No separate exit signal needed.
- Risk: size is derived from a fixed % risk per trade against the
stop distance (compounding), with optional risk and leverage caps.
- Optional weekend-flat close for instruments with gap risk.
HOW TO USE
- Best on genuinely trending markets. Try it on your own instrument
and timeframe.
- Tune the risk % to your own drawdown tolerance, and the ATR
multiplier to taste (2.5–3.5 behaved similarly — a good sign the
edge isn't fitted to one value).
- Built-in alerts: the entry alert gives you the trailing-stop
distance to set on your broker; the trailing stop handles the exit.
WHAT TO EXPECT — READ THIS
- It's a breakout system, so win rate is LOW: ~40–45% is normal.
The edge is that winners are bigger than losers, not that you're
right often. Judge it by profit factor and drawdown, not win rate.
- Expect long flat/drawdown periods in choppy, range-bound markets.
It performs when markets trend.
- COSTS DECIDE EVERYTHING. Set your own broker's spread/commission
in the properties before trusting any result. Something that looks
great at zero cost can be break-even or worse once real spreads —
and, for leveraged CFDs, overnight financing — are included.
Results vary a lot by broker and instrument.
NOTES
- No repainting: entries use the prior bar's channel; the trailing
stop only ratchets in the trade's favor.
- Not financial advice. Past backtest results do not guarantee
future performance. Always test on your own market, timeframe and
broker costs, and only risk what you can afford to lose.
(turtle) channel breakout with a single ATR-based trailing stop.
It was deliberately built to be robust across markets rather than
curve-fit to one — the same code and settings held up on both an
equity index (DAX/GER40, 1h) and Bitcoin (BTCUSD, 4h), and across
trailing multipliers of 2.5–3.5.
HOW IT WORKS
- Entry: goes long when price closes above the highest high of the
last N bars (default 20) while above the 200 EMA trend filter.
Short side is optional and off by default.
- Exit: one ATR-based trailing stop (distance = ATR × multiplier,
default 2.5, fixed at entry). It serves as both the initial
protective stop and the trailing exit — cutting losses and letting
winners run, fully automatically. No separate exit signal needed.
- Risk: size is derived from a fixed % risk per trade against the
stop distance (compounding), with optional risk and leverage caps.
- Optional weekend-flat close for instruments with gap risk.
HOW TO USE
- Best on genuinely trending markets. Try it on your own instrument
and timeframe.
- Tune the risk % to your own drawdown tolerance, and the ATR
multiplier to taste (2.5–3.5 behaved similarly — a good sign the
edge isn't fitted to one value).
- Built-in alerts: the entry alert gives you the trailing-stop
distance to set on your broker; the trailing stop handles the exit.
WHAT TO EXPECT — READ THIS
- It's a breakout system, so win rate is LOW: ~40–45% is normal.
The edge is that winners are bigger than losers, not that you're
right often. Judge it by profit factor and drawdown, not win rate.
- Expect long flat/drawdown periods in choppy, range-bound markets.
It performs when markets trend.
- COSTS DECIDE EVERYTHING. Set your own broker's spread/commission
in the properties before trusting any result. Something that looks
great at zero cost can be break-even or worse once real spreads —
and, for leveraged CFDs, overnight financing — are included.
Results vary a lot by broker and instrument.
NOTES
- No repainting: entries use the prior bar's channel; the trailing
stop only ratchets in the trade's favor.
- Not financial advice. Past backtest results do not guarantee
future performance. Always test on your own market, timeframe and
broker costs, and only risk what you can afford to lose.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.