You built a profitable MT4 Expert Advisor. You spent weeks refining the logic until it worked. Then you started selling it. And then someone shared it on Telegram. Or a forum. Now your EA is running on accounts that never paid you a cent — and you have no way to stop it.
This guide covers every method to add license key protection to your MT4 EA, why most approaches fail, and the one that actually works: server-side account binding.
Skip to what matters: Jump to Server-Side License Protection — it is the only method that actually prevents piracy long-term.
MetaTrader 4 compiles your MQL4 source into an .ex4 binary. The problem is structural:
The most common beginner approach: check the account number inside OnInit() and fail if it does not match.
int OnInit() {
if(AccountNumber() != 12345678) {
Print("Unauthorized");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
Why this fails: Anyone with a decompiler can find and remove that check in minutes. Zero real protection.
More work to implement, but still fails because the validation logic is inside the EA. A pirate can patch the binary to skip the check, or copy a valid license file between machines.
Good protection but you are locked into their platform with a 30% commission cut and no ability to sell directly.
Your EA makes an HTTPS call to a remote server on startup. The server checks whether that MT4 account number is authorized. If not, the EA stops. There is no local file to copy. There is no check to patch. The authorization lives on a server the pirate cannot access.
This is what MTLicense does. Two lines of code in your EA. Every license check happens server-side. Revoke any license in one click — takes effect on the next tick.
Sign up at mtlicense.com. No credit card required. You get immediate dashboard access, an API key, and the SDK files.
Click Add Product in the dashboard. Give your EA a name. Copy the Product ID you receive.
Download LicenseManager4.mqh and place it in your MetaEditor Include folder: MQL4/Include/LicenseManager4.mqh
#include <LicenseManager4.mqh>
int OnInit() {
if(!LicenseCheck("YOUR_API_KEY", "YOUR_PRODUCT_ID")) {
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
Compile as normal. The .ex4 output is your protected binary. Distribute exactly as you do today.
When a customer pays, add their MT4 account number in your dashboard. They are live in seconds. Chargeback? Click Revoke — their EA stops on the next tick.
Free account. No credit card. Two lines of code.
Start Free Join 75+ EA developers already protecting their software| Method | Piracy Protection | Setup Time | Revoke Access | Cost |
|---|---|---|---|---|
| Hardcoded account | None | 5 min | No | Free |
| Local license file | Weak | 2-4 hrs | Hard | Free |
| MQL5 Marketplace | Good | Days | Yes | 30% cut |
| MTLicense | Strong | 10 min | Instant | From $19/mo |
No. The check happens only on initialization by default. Your EA tick processing is not affected.
MTLicense runs at 99.9% uptime. The SDK has a configurable grace period — you choose whether the EA fails safe or keeps running temporarily. Most developers use a 24-hour grace window.
Yes. You can authorize multiple account numbers per customer. Each is a separate license entry you can revoke individually.
Yes. MTLicense provides LicenseManager5.mqh for MT5. Same two lines, same dashboard.
Without protection you are selling a product once. With server-side license protection you can sell monthly subscriptions. One customer who would have paid $200 once now pays $49 per month — that is $588 per year — and you can revoke access the moment they stop paying. This is the difference between building a product and building a business.
Set up server-side license protection in 10 minutes. Free trial, no card required.
Protect My EA Now 14-day free trial · No credit card · Cancel anytime