Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy – including backtests – does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The candle range theory strategy is a price-action reversal method that uses a three-candle pattern and no indicators. One candle sets a range, the next pushes past one side of it and fails, and the trade aims back at the opposite side. The code uses only the high, low and close of the two most recently completed candles.
Candle Range Theory (CRT) is popular in ICT-style (Inner Circle Trader) and "smart money" circles. Its core idea is liquidity, meaning the resting orders clustered at obvious price levels. Many traders place stop-losses just beyond a prominent candle's high or low. When price moves past that level, triggers those orders and then closes back inside the range, CRT reads the move as a stop raid rather than a real breakout. It expects price to swing toward the other end of the range next.
This Expert Advisor (EA, an automated trading program for MetaTrader) turns that discretionary idea into fixed rules. That makes it a useful way to study candle range theory trading with every decision defined in advance. You will learn how often the pattern appears, how wide its stops tend to be and how much each threshold changes the outcome. Treat it as something to study and backtest, not as a finished trading system.
How It Works
The EA checks for a setup once per completed bar. When a new candle opens, it gives each of the last two closed candles a role.
How the Candle Range Theory Strategy Reads Three Candles
- Candle 1, the range candle: this is the candle two bars back. Its high and low define the range, and the distance between them is the range height that every other threshold is measured against.
- Candle 2, the sweep candle: this is the candle that just closed. It must trade beyond exactly one side of the range and then close back inside it.
- Candle 3, the entry candle: this is the candle now opening. If candle 2 qualified, the strategy signals a market entry here.
Entry Conditions
For a short (sell) signal:
- Candle 2's high rises above candle 1's high, so the buy-side liquidity is swept.
- Candle 2's low stays at or above candle 1's low, so only one side was raided.
- Candle 2 closes back inside candle 1's range.
- The sweep depth, meaning how far candle 2 went past candle 1's high, must fall between
MinSweepFractionandMaxSweepFractionof the range height. By default that is 3% to 60%.
The rules for a long (buy) signal are the mirror image, with the sweep happening below candle 1's low instead.
A very shallow sweep may just be noise. A very deep one looks more like a real breakout that pulled back. An outside bar breaks both the high and the low, so it gives no clear direction, and the EA ignores it.
Stop-Loss and Take-Profit Logic
- Stop-loss: the stop goes beyond the sweep candle's high (for shorts) or low (for longs). It gets extra room equal to
StopBufferFractionof the range height, 5% by default. - Take-profit: the target is the opposite end of the range.
- Filters: reward-to-risk (R) compares the distance to the target with the distance to the stop. The EA skips the trade if the target is less than
MinRewardRisktimes the risk (1.5R by default). It also skips the trade if candle 3 gaps past the stop or target, or if either level is closer than the broker's minimum stop distance. In practice, the R filter favors sweep candles that close well back inside the range. - Time exit:
MaxHoldBars(default 3) closes the trade at market if neither level has been hit after that many bars, because CRT expects the move within a candle or two. A value of 0 turns the time exit off. - The EA holds one position at a time, marked with a magic number (an ID tag that separates its trades from yours and from other EAs').

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
MinSweepFraction |
0.03 | 0.00 | 0.30 | The smallest distance candle 2 must trade beyond the range edge, as a fraction of the range height. It filters out tiny pokes. |
MaxSweepFraction |
0.60 | 0.10 | 1.50 | The largest allowed sweep depth, as a fraction of the range height. Deeper moves count as real breakouts and are skipped. |
StopBufferFraction |
0.05 | 0.00 | 0.30 | Extra room added beyond the sweep candle's extreme when the stop is placed, as a fraction of the range height. |
MinRewardRisk |
1.5 | 1.0 | 3.0 | The smallest reward-to-risk ratio needed to take a trade. |
MaxHoldBars |
3 | 0 | 10 | The number of bars after which an open trade is closed at market. 0 turns this off. |
Lots |
0.10 | 0.01 | 1.0 | The fixed order size, rounded to the broker's volume step and limits. |
The MQL5 version also has a Magic input (default 240617). It identifies the EA's trades and is not meant to be optimized.

Recommended Chart Settings
- Timeframe: the EA was built for H4 or D1. It runs on whatever timeframe the chart uses, but on lower timeframes the spread takes up a bigger share of each range.
- Symbol: no instrument is hard-coded. As a candle range theory forex strategy, it is usually studied on liquid, tight-spread markets such as EUR/USD, GBP/USD, gold (XAUUSD) and major indices.
- Broker server time: the time zone of your broker's server decides where H4 and D1 candles begin and end. Some brokers also show a short Sunday candle, which can act as a misleading range candle.
Results will vary across market conditions. Trending, ranging and news-driven periods can behave very differently, so test across several years.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
Before you trade the candle range theory MT5 version live, run it in the Strategy Tester with "Every tick based on real ticks" modeling, then forward-test it on a demo account. For every trade, the Experts log records the swept level, entry, stop, target and R.
What to Consider Before Using This EA
Strengths
- Transparent rules: you can see exactly why each trade was taken or skipped.
- No indicator lag: the logic reacts directly to the latest candles.
- Defined risk at entry: the stop and target are known before the order is sent.
- Thresholds that scale: every distance is a fraction of the range height, so the settings adjust somewhat to different symbols and volatility levels.
Limitations
- No trend or context filter: in a strong trend, a sweep may only be a pause before the trend continues. Discretionary traders usually add higher-timeframe levels, session timing or lower-timeframe confirmation. The candle range theory strategy coded here leaves all of that out, so its results are not a verdict on every candle range theory ICT variant.
- Wide stops on D1: because the lot size is fixed, the amount of money at risk changes from trade to trade.
- Few signals: the pattern is fairly rare on H4 and D1, so backtest samples can be small.
- Gaps and spreads: weekend gaps and news can jump price past the stop. Entries at the D1 open often land near the daily rollover, when spreads widen.
- One interpretation: other traders define CRT with different rules.
The approach may underperform during sustained breakouts, in very quiet markets and around major economic announcements.
Risk Management Tips
- Size positions by risk: work out what each stop distance means in your account currency. A common formula is: lot size = (balance × risk %) ÷ (stop in pips × pip value per lot).
- Limit risk to 1-2% per trade: small, consistent risk keeps any single loss manageable.
- Understand drawdown: drawdown is the fall in account equity from a peak to a low. At 1% risk per trade, ten losses in a row cost about 9.6% of the account. At 5% per trade, the same streak costs about 40%.
- Use a demo account first: it shows how fills, spreads and gaps behave with your broker.
- Avoid over-optimization: settings tuned closely to past data often fail on new data. Keep some data aside for out-of-sample testing.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: CandleRangeTheory.ex5 (0 downloads)
- Source Code: CandleRangeTheory.mq5 (0 downloads)
- Documentation: CandleRangeTheory.pdf (0 downloads)