Summary
This article shows how to build a simple range breakout strategy.
The idea:
Find the highest price of the last 20 closed candles
Store that level in a variable
Buy when price crosses above it
Only allow the buy if RSI is above 50
Prevent duplicate trades with Count Trades
Also known as: range breakout, highest high breakout, 20-candle breakout, RSI breakout filter.
This is an educational example, not investment advice. Always export and test in MT5 Visual Mode.
What the strategy does
The EA first finds the highest high from the last 20 closed candles.
It stores that price level in a variable, for example:
Highest_Price
Then, during the trading session, it checks:
Price crosses above Highest_Price RSI > 50 No buy trade is open
If all conditions are true, the EA opens a buy trade.
Trading logic
1. Create a variable
Create a variable called:
Highest_Price = 0
This variable stores the breakout level.
2. Store the highest price of the last 20 candles
Use Run at Time if you only want to calculate the level once per day.
Example:
Run at Time: 01:00
Then add Modify Variables:
Highest_Price = Highest Candle High from Candle ID 1 to Candle ID 20
Use Candle ID 1 to 20 because these are closed candles.
Do not use Candle ID 0 for this logic, because Candle ID 0 is still forming.
3. Check for the breakout
Use Run in Session for the time window where the EA is allowed to trade.
Example:
Run in Session: 01:00 to 21:00
Then add a Trade Rule:
Bid price crosses above Highest_Price
You can also use Ask price depending on how you want to define the breakout.
4. Check that no buy trade is open
Add Count Trades before execution:
Buy trades = 0
This prevents repeated buy entries.
5. Add RSI filter
Add another Trade Rule:
RSI Candle ID 1 > 50
This means the last closed candle had RSI above 50, which is often used as a simple momentum filter.
6. Open the buy trade
If all rules are true, connect to:
Buy Now
Example structure:
Run in Session → Count Trades: Buy trades = 0 → Trade Rule: Bid crosses above Highest_Price → Trade Rule: RSI Candle ID 1 > 50 → Buy Now
Main blocks used
Run at Time
Calculates the breakout level once per day.
Modify Variables
Stores the highest price into Highest_Price.
Run in Session
Limits when the EA is allowed to trade.
Trade Rule
Checks the breakout and RSI condition.
Count Trades
Prevents duplicate buy trades.
Buy Now
Opens the buy trade when all conditions are true.
Important timeframe note
The example above works best when you want to calculate the 20-candle high once per day.
If you want the EA to update the highest high every candle, replace Run at Time with Run per Candle:
Run per Candle → Modify Variables: Highest_Price = Highest Candle High from Candle ID 1 to 20
Use this if you are building a rolling 20-candle breakout on lower timeframes.
Make it your own
You can adjust:
The candle range, for example 10, 20, or 50 candles
The RSI threshold, for example 50, 55, or 60
The session time
The stop loss and take profit
The price source, for example Bid or Ask
A sell version using the lowest low of the last 20 candles
Draw on Chart to visualize the breakout level
For a sell setup, reverse the logic:
Lowest_Price = Lowest Candle Low from Candle ID 1 to 20 Bid price crosses below Lowest_Price RSI Candle ID 1 < 50 Sell trades = 0 Sell Now
Conclusion
This range breakout setup buys when price breaks above the highest high of the last 20 closed candles and RSI confirms momentum above 50.
The key logic is:
Store highest high → Wait for breakout → Confirm RSI > 50 → Check no buy trade is open → Buy Now
Export and test in MT5 Visual Mode to confirm the stored level, breakout trigger, and RSI filter behave as expected.
