Opening Range Breakout EA
Every other breakout EA in this catalogue waits for a bar to close beyond a level before sending a market order, which costs up to one whole bar of slippage on a fast opening-range break. This one places genuine pending stop orders instead - the textbook opening-range-breakout mechanism - so the order sits at the range edge and fills the instant price trades through it. The range is measured from InpSessionStartHour:InpSessionStartMinute for InpRangeMinutes minutes of broker server time. Once the window closes, a buy-stop is placed at the range high and a sell-stop at the range low, each with its own stop loss at the opposite range edge. Whichever side fills first cancels the other resting order - without that, a sharp move that later reverses could fill both sides and leave the account flat having paid the spread twice for nothing. Unfilled pendings expire automatically after InpOrderLifetimeMin minutes, and any leftover resting order is cleared at the start of the next calendar day regardless. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to each side's stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - One bracket (a buy-stop and a sell-stop) per calendar day. Once one side fills, the other resting order is deleted the same tick it is noticed. - If the range is inside the broker's minimum stop distance, the bracket is skipped for the day rather than sending an invalid order. - Pending order deletion, like closing, retries against transient broker errors and gives up on permanent ones; a delete that keeps failing can leave a stale resting order until the next day's cleanup removes it. - Uses genuine pending stop orders (OP_BUYSTOP/OP_SELLSTOP on MQL4, ORDER_TYPE_BUY_STOP/ORDER_TYPE_SELL_STOP on MQL5), so broker execution and requote behaviour for pending orders applies here, which differs from a market order EA. - Requires AutoTrading enabled and IsTradeAllowed() true (MQL4) or the equivalent terminal/account/expert checks (MQL5); if trading is disabled the bracket for that day is skipped and logged. - On a netting MQL5 account, the bracket is not placed while a foreign-magic position already sits on the chart symbol - see the differences section above.
Expert advisor · MT4 · v1.0 · Free
About Opening Range Breakout EA
Opening Range Breakout EA is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders, trades only in the hours you set (time filter) and can size trades from your balance and risk percent. It has 13 settings, such as Session start hour, Session start minute and Range minutes. MQL source code included.
Files in the download: OpeningRangeEa.ex4, OpeningRangeEa.mq4, OpeningRangeEa.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Session start hour | 8 | Opening range starts at this broker server hour |
| Session start minute | 0 | Opening range starts at this minute past the hour |
| Range minutes | 30 | Length of the opening range window, in minutes |
| Order lifetime min | 120 | Minutes after the window closes that an unfilled pending stays live (0 = no expiry) |
| Stop loss pips | 0 | Extra stop-loss buffer beyond the opposite range edge, in pips (0 = stop exactly at opposite edge) |
| Take profit pips | 0 | Take profit distance, in pips (0 = none) |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260610 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Breakout · Trading Sessions · Pending Orders · Time Filter · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code