MT5 Expert Advisor Development
You write the rules. We implement them in MQL5 as a working Expert Advisor that runs on your own MetaTrader 5 terminal, …
Read moreTwo EAs on one account without a magic-number scheme is not a configuration. It is two programs quietly closing each other's trades.
An integer you attach to every order your EA sends. The server stores it with the resulting position, and it is the only reliable way for an EA to tell "my position" from "someone else's position" — whether that someone is another EA or you, trading by hand.
MqlTradeRequest request = {};
request.magic = MagicNumber; // stamped on the order
request.symbol = _Symbol;
request.volume = lots;
// ...
An EA with no magic filter loops over every open position and manages all of them. Attach two such EAs and the first one trails the stop on the second one's trade, then closes it on its own exit condition. Add a manual trade and it gets managed too.
Nothing errors. The log looks normal. You only notice from the account history, usually after a few days.
int CountMyPositions()
{
int n = 0;
for(int i = PositionsTotal()-1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket == 0) continue;
if(PositionGetInteger(POSITION_MAGIC) != MagicNumber) continue;
if(PositionGetString(POSITION_SYMBOL) != _Symbol) continue;
n++;
}
return n;
}
Magic alone is not enough once the same EA runs on several charts. Two instances sharing a magic number will each think the other's positions are their own.
Pick a structure before you need one, because renumbering later means reconciling live positions:
| Digits | Meaning | Example |
|---|---|---|
| 1–2 | Strategy ID | 12 = your breakout EA |
| 3–4 | Symbol ID | 01 = XAUUSD |
| 5–6 | Timeframe ID | 15 = M15 |
So 120115 is "breakout EA, XAUUSD, M15". Readable in the terminal at a glance,
and it never collides.
Two things to avoid: do not generate magic numbers randomly at startup, because after a restart the EA no longer recognises its own positions; and do not derive them from the symbol name at runtime unless the derivation is stable, because a broker suffix change will silently produce a different number.
Magic numbers isolate ownership. They do not isolate margin. Every EA on the account draws on the same free margin, so three EAs each sized "safely" on their own can combine into something that is not.
If you run several, one of them should hold an account-level ceiling — total exposure across all magics, not just its own:
double TotalLots() // every position, every magic
{
double v = 0.0;
for(int i = PositionsTotal()-1; i >= 0; i--)
if(PositionGetTicket(i) > 0)
v += PositionGetDouble(POSITION_VOLUME);
return v;
}
And remember the account-level stop: margin level, daily drawdown or equity floor apply to the whole account regardless of which EA caused them.
OnInit() so the Experts log says what is running whereIf you are commissioning several EAs over time, tell each developer the scheme. Two builds
that both default to 12345 is the most common collision we are asked to untangle.
You write the rules. We implement them in MQL5 as a working Expert Advisor that runs on your own MetaTrader 5 terminal, …
Read moreSoftware you already own, fixed or extended — and deployed on a VPS so it keeps running when your own machine is o…
Read moreSend your rules, your script or your existing file on WhatsApp and we will reply with a written scope, price and timeline.