Loading…

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

SettingDefaultWhat it does
Session start hour8Opening range starts at this broker server hour
Session start minute0Opening range starts at this minute past the hour
Range minutes30Length of the opening range window, in minutes
Order lifetime min120Minutes after the window closes that an unfilled pending stays live (0 = no expiry)
Stop loss pips0Extra stop-loss buffer beyond the opposite range edge, in pips (0 = stop exactly at opposite edge)
Take profit pips0Take profit distance, in pips (0 = none)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260610Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Breakout · Trading Sessions · Pending Orders · Time Filter · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria