
Combining Donchian + ATR: High-precision configuration
The Donchian channel is an iconic tool for trend-following strategies. It plots the upper and lower bounds by taking the highest and lowest points of a given period (often twenty sessions) in order to identify range breaks. This simple visual reference allows breakouts to be detected, but it can also generate many false signals when the market is flat or not very volatile.The Average True Range (ATR), on the other hand, measures average volatility and serves as a barometer for assessing the real energy of a movement. When these two indicators are combined, the result is a more robust algorithmic trading configuration: the channel identifies opportunities and the ATR verifies that the market is dynamic enough to exploit them.
Purpose of this article: To explain how to configure an MT5 Expert Advisor by combining Donchian and ATR in order to filter out false breakouts and adapt money management according to volatility. This article is aimed at real traders, particularly those targeting FTMO challenges or prop firm accounts. The idea is to automate a strategy that remains simple, pragmatic, and thoroughly tested.
1 | Understanding the Donchian Channel
Richard Donchian popularized this approach in the 1950s. Specifically, the channel displays:
- The upper band: The highest reached on the last N candles
- The lower band: The lowest point reached on the last N candles
- The median band: Average of the two limits
The default setting is often 20 periods because it filters out minor fluctuations while remaining fairly responsive. However, there is nothing to prevent you from using a shorter channel (10 periods) for scalping or a longer one (30–50 periods) for swing trading. This choice will depend on market volatility and the average duration of trades.
Advantages:
- Clear structure of breakout levels, ideal for programming automatic entry
- Strong signal when the price closes above the upper limit (buy) or below the lower limit (sell)
- Simplicity of calculation, which limits the risk of errors in the code and facilitates maintenance
Limits:
- Delays: The channel is a backward-looking indicator; it confirms the trend rather than predicting it.
- False signals in a flat market: Successive breakouts may be short-lived surges.
- Need for a volatility filter to assess signal quality
2 | The ATR: Volatility Barometer
TheAverage True Range calculates the average daily range (highs minus lows) over a given period. Unlike Bollinger Bands, ATR does not predict a reversal but quantifies the magnitude of movementsOn MT5, the function iATR() returns this value in real time. A few points to remember:
- The ATR is a pure volatility indicator: it increases when the market accelerates and decreases when the market contracts.
- It allows dynamic stopsto be adjusted: A stop set at 1.5 × ATR or 2 × ATR automatically adjusts to current volatility.
- It is used to calibrate position sizes based on risk, as a high ATR implies that each pip represents a larger movement.
The ATR does not give directional signals. It therefore perfectly complements a trend or breakout indicator such as the Donchian channel.
3 | Why combine Donchian and ATR?
In an automated approach, combining the channel and ATR offers two major advantages:
- Filter breakouts by volatility: Specialized articles point out that when a channel breakout occurs while the ATR is high, there is a greater chance that the movement will become a lasting trend. Conversely, breakouts on a low ATR are often just market noise, hence the importance of avoiding them.
- Adjusting stop and position size: ATR serves as a gauge for setting realistic stops and targets. Trading guides recommend using dynamic stops at 1.5× or 2× the ATR. This allows you to stick to your risk tolerance based on volatility: tight stops when the market is calm, wider stops when it is nervous.
Integrating these principles into an MT5 robot improves the robustness of the system: it avoids taking positions when the market is too calm and automatically adapts to changing conditions.
4 | High-precision settings for an EA MT5
4.1 Choosing the channel period
The choice of the number of candles in your Donchian channel depends on your trading horizon:
- Scalping: 10-period channel on M5 or M1 to capture rapid breakouts
- Swing trading: 20- to 50-period channel on H1, H4, or D1, as used by the Turtle Traders.
- Long term: 100 or 200-period moving average on D1 or W1 to track major trends
It is recommended to backtest several settings (10, 20, 50, 100) and then perform a forward test on a demo account before selecting a final configuration. This prevents you from overfitting the EA to a limited data set and reduces the risk of over-optimization.
4.2 Volatility and orientation filter
To avoid false signals, it is necessary to combine two filters:
- Volatility filter: Only activate entries if the ATR exceeds a certain value or a moving average, indicating that the market is moving. When a breakout occurs and the ATR is low, the EA ignores the signal.
- Trend filter: Algorithmic trading guides recommend using a long moving average (200 SMA/EMA) as a regime filter. Buy breakouts are only taken if the price is above the long-term average, and sell breakouts are only taken if the price is below it. This simple rule significantly improves the success rate.
4.3 Dynamic stop-loss and take-profit
Risk management is crucial, especially for an FTMO challenge. Instead of placing a fixed stop, it is calculated based on the ATR:
- Measure the ATR in pips at the time of entry.
- Multiply it by a factor: 1.5 for a moderate approach, 2 for more margin.
- Place the stop at this distance below the low (for a buy) or above the high (for a sell).
The target can be set as a multiple of the risk (2R or 3R), or by using the median band as the partial profit-taking level.
4.4 Position sizing
Combining Donchian and ATR involves calculating position size based on percentage risk. For example, if you risk 0.5% of your capital per trade and your stop is 40 pips (calculated using ATR), the formula lot = (capital × 0.005)/(stop in pips × pip value) gives the position size. Thus, in periods of high volatility (high ATR), the lot size automatically decreases and vice versa.
4.5 Multi-symbol and mutex management
If your robot processes multiple pairs, consider implementing a global mutex to prevent two strategies from conflicting on the same symbol. This approach is detailed in our article on the MT5 global mutex, which ensures that only one instance of the EA opens a position at a time.
5 | Implementation in an MT5 Expert Advisor
Here is a programming diagram to be adapted in MQL5:
- Initialization: Declare the channel and ATR periods, as well as the stop factors. Read the parameters from the EA interface to test them easily.
- Calculation of indicators: With each new candle, call
iDonchianChannel()(or code the highest/lowest) andiATR()to obtain the current values - Check the trend filter: Compare the price to the long moving average (200 SMA/EMA)
- Check the volatility filter: Ensure that the ATR is above a threshold (e.g., the 14-period average) to validate a breakout.
- Entry position: Trigger a buy stop order above the upper band or a sell stop order below the lower band.
- Placing stop-loss and take-profit orders by multiplying the ATR by the defined factor
- Exits: Exit when the price crosses the opposite band (reversed stop), or according to a predefined risk/reward ratio.
- Multiple position management: Use a mutex to avoid duplicate orders and manage overall exposure
This architecture can be enhanced with logging functions, push alerts, and a settings interface to adjust sensitivity in real time.
6 | Testing, optimization, and robustness
The effectiveness of an EA depends on the quality of the tests and optimization. Here are a few tips:
- Long-term backtesting: Use at least three years of data and several hundred trades to ensure that the results are statistically significant. Testing over a single month artificially inflates performance and leads to over-optimization.
- Out-of-sample samples: Separate the data into an optimization segment and a validation segment. A robot that runs only on optimization data is likely to be overfitted.
- Forward testing: After optimization, run the EA on a demo account or with small amounts to check its behavior in real time.
- Multi-pair and multi-timeframe testing: A robust system must work across multiple assets. For example, test the configuration on EUR/USD, GBP/USD, AUD/USD, and USD/JPY. Avoid correlating multiple trades on pairs that are too similar (see our article on Forex correlation to understand which pairs to avoid).
- Monte Carlo or stress testing: Simulate random changes in trade order or spreads to measure the sensitivity of the system.
- Documentation: Record EA versions, parameters used, and results in order to track improvements over time.
To learn more about these concepts, check out our articles on optimizing MT5 breakouts, managing stop-losses based on volatility, automated money management for FTMO, and defining an MT5 Expert Advisor. These resources show you how to structure a consistent algorithmic approach that complies with the FTMO framework.
7 | Conclusion and outlook
The Donchian + ATR combination is a powerful method for filtering breakouts and adapting risk to market conditions. By using a channel to signal breakouts and ATR to measure volatility, traders can automate a strategy that addresses both momentum and risk management. Studies show that breakouts validated by high volatility are more likely to be successful, while those on low ATRs are often false starts. In addition, the use of a dynamic stop based on 1.5 × or 2 × ATR is widely recommended.
Before launching your EA on a live account or prop firm challenge, take the time to test, optimize, and document your configuration. With rigorous money management and a volatility filter, this approach can become a pillar of your algorithmic arsenal on MT5.
Frequently Asked Questions (FAQ)
1. Why is ATR a better filter than simple volume?
The volume on the currency market is not centralized, which makes it difficult to interpret. ATR directly measures the magnitude of price movements and better reflects market nervousness. A breakout with high ATR signals real conviction among market participants.
2. Which ATR period should be used?
The classic period is 14 candles, but there is no reason not to try 10 or 20. The important thing is to keep the same scale between the ATR and the Donchian channel so that the stop-losses are consistent.
3. Should other indicators be combined?
Yes. The articles recommend adding an oscillator (RSI, MACD) to confirm the strength of the trend or identify overbought/oversold conditions. A trend filter (200 SMA/EMA) remains essential.
4. Can this approach be used in markets other than Forex?
Absolutely. The principles of breakouts and volatility also apply to indices, commodities, and crypto assets, provided you have high-quality data.
5. How can you avoid over-optimizing the EA?
Don't multiply parameters: Test a few variables at a time and check robustness on out-of-period data. Our article onEA overfitting explains how to maintain the reliability of your system.