Guide for EA sellers ยท with code

How to bind your MT4/MT5 EA to a specific account number

The working MQL4 and MQL5 code to lock an Expert Advisor to one account, and the honest reason this alone won't stop a determined client.

6 min read MQL4 & MQL5 Copy-paste ready

You want your EA to run on your client's account, and refuse to run anywhere else. That's account binding, and it's the most common first line of protection EA sellers reach for. Here's exactly how to do it in both MQL4 and MQL5, and an honest look at how far it actually gets you.

01 / The ideaCheck the account number on startup

Every MetaTrader account has a unique login number. Your EA can read it at runtime and compare it to a number you've authorized. If they don't match, the EA stops before it places a single trade. Simple, and it works as a first gate.

The function differs slightly between platforms. In MQL4 it's AccountNumber(); in MQL5 it's AccountInfoInteger(ACCOUNT_LOGIN).

02 / The codeMQL4 and MQL5, ready to paste

MQL4

// --- Account binding (MQL4) ---
long AllowedAccount = 123456;  // your client's account number

int OnInit()
{
   if(AccountNumber() != AllowedAccount)
   {
      Alert("This EA is not licensed for this account.");
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

MQL5

// --- Account binding (MQL5) ---
long AllowedAccount = 123456;  // your client's account number

int OnInit()
{
   if(AccountInfoInteger(ACCOUNT_LOGIN) != AllowedAccount)
   {
      Alert("This EA is not licensed for this account.");
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

Drop that into your EA, compile, and the robot will only initialize on the account you specified. For a single hand-delivered copy, that's a reasonable start.

03 / The catchWhy this isn't real protection

Here's the part most tutorials leave out, and it's the part that actually matters once you're selling to more than one person.

The problemThat account check lives inside the compiled .ex4/.ex5. Anything inside the file can be found and removed. A client who decompiles it, or pays someone $20 to, deletes the if check, and now your EA runs on any account, forever. The lock you just wrote is one line away from gone.

It gets worse with volume. Hardcoding AllowedAccount means you compile a separate copy of your EA for every single buyer. Ten customers, ten builds. Someone wants to switch brokers? Recompile and re-send. A trial expires? There's no expiry, you'd have to remember and manually chase it. It doesn't scale, and it doesn't hold.

04 / What actually holdsMove the check off the file

The fix is the same principle behind every serious EA license system: don't let the EA decide whether it's allowed to run, have it ask a server. Instead of a hardcoded number baked into the file, the EA sends the account number and a license key to a server you control, and the server answers.

Why it holdsThe buyer can copy the file all they want, but they can't copy your server's decision. You issue one key per buyer, bind it to their account, set an expiry, and revoke it the moment they refund, all without recompiling or re-sending a thing. One build, managed from a dashboard.

The technical move in MQL is the same OnInit hook you saw above, except instead of comparing to a hardcoded number, the EA makes a WebRequest to a validation server and acts on the response. Make the server return a value the EA actually needs to trade, not just true or false, so deleting the check breaks the EA instead of freeing it.

Skip the server-building

MTLicense is that server, you add one line

A hosted license system for MT4/MT5 sellers. Issue keys, bind them to account numbers, set expiry, and revoke instantly, from one dashboard. You add a single validation call to your EA; we run the server, so your account binding can't be patched out of the file.

Start a free 14-day trial →

No card to start · Plans from $19/mo · Integration docs on signup

Use the hardcoded version above if you're handing one EA to one trusted person. The moment you're selling to strangers, move the check off the file. That's the difference between a lock and a speed bump.