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.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.