Two reusable MetaTrader 5 include modules that split one normal strategy entry into smaller positions. Position one stays in control; the module opens the remaining legs after a delay and closes them sequentially when the controlling position exits.
Use this when your EA uses market orders, trades one symbol per chart, has one long entry path and one short entry path, and does not need pending-order support.
Symbol-aware lot alignment.
Broker-aware filling mode selection.
Separate entry and close timers.
Optional split end-of-day close.
Production bias
Advanced
Use this when your EA uses pending orders, needs stronger ticket and position tracking, or you want a stuck-chain failsafe.
Pending-order registration.
Pending-to-position fallback detection.
Position identifier tracking.
Force-close cleanup and chain timeout.
Manual install
The integration is deliberately small: include the file, initialise it, run the manager every tick, adjust your lot size before the first order, then register the first position after your EA opens it.
Simple market-order integration
#include "OrderSplitting_Simple.mqh"
int OnInit()
{
OS_Init();
return INIT_SUCCEEDED;
}
void OnTick()
{
OS_Manage(); // keep this before new entry logic
double lots = CalculateLots();
lots = OS_AdjustLots(lots);
ulong ticket = OpenBuyOrSell(lots);
if(ticket > 0 && OS_UseSplitEntry)
OS_RegisterLong((ulong)ticket); // use OS_RegisterShort for sells
}
Put the include file beside your EA, or inside your MetaTrader MQL5/Include folder.
Call the manager early in OnTick(). It needs to keep running so existing split positions can close and clean themselves up.
Register the controlling position. The first ticket returned by your EA is position one; the module manages positions two through N.
Compile and demo test the final EA. A clean module compile does not prove your strategy integration is correct.
Adding it with an AI agent
If you use an AI coding agent, give it the module and a narrow integration brief. The module has a small public surface area, which makes this a good fit for assisted implementation.
Prompt for an AI coding agent
Please integrate OrderSplitting_Advanced.mqh into this MQL5 EA.
Requirements:
- include the module
- call OSA_Init() from OnInit()
- call OSA_Manage() early in OnTick(), before new entries
- pass the strategy lot size through OSA_AdjustLots() before entry orders
- register buy market entries with OSA_RegisterMarketLong(ticket)
- register sell market entries with OSA_RegisterMarketShort(ticket)
- if the EA uses pending orders, register them with OSA_RegisterPendingLong/Short(orderTicket, sl, lots)
- do not wrap OSA_Manage() inside entry filters
- preserve all existing strategy logic
After editing, compile the EA in MetaEditor and run a backtest or demo test.
Safety notes
The trade-off: splitting can reduce immediate market impact and make larger position sizes more practical, but delayed entries can worsen your average fill if price moves against you before every leg is open.
Test on a demo account before using live.
Use a hedging account where possible, because each split leg is intended to exist as its own position.
Confirm your broker allows multiple positions on the same symbol.
Check that the symbol minimum lot size supports your chosen SplitCount.
Keep SplitCount and SplitDelaySeconds practical. More splitting is not automatically better.
Single-symbol chart EAs are the intended default. Multi-symbol, multi-gate, or netting-account EAs need adaptation.
Personal commentary and education, not investment advice or a solicitation. Code is provided as-is, with no warranty. Test on demo before using live. Capital at risk. Past performance is not indicative of future results.