← Back to Blog
Security

How to Protect Your MT4 EA from Piracy (Complete Guide)

March 25, 2026 · 8 min read · By MTLicense Team

You spent months building your Expert Advisor. You tested it, refined it, and finally started selling it. Then one day you find your EA running on a forum for free, shared by a customer who decided everyone else should get it at no cost.

This happens to almost every EA developer without license protection. Every shared copy is a recurring customer you will never have. This guide covers exactly how to stop it.

Why MT4 EAs Are Easy to Pirate

MetaTrader 4 compiles Expert Advisors into .ex4 files. While compiled, they are not tied to any account or machine. Once a customer has your file, they can share it with anyone and it runs on any platform.

The built-in MT4 protection options are weak. You can hardcode account numbers in your MQL4 code, but this is trivially bypassed by a decompiler. What you need is a server-side license check where the EA calls a remote API on every startup and your server decides whether to allow it.

How Hardware-Bound Licensing Works

  1. Your EA includes a license check in its OnInit() function
  2. On startup, the EA sends the trader's account number to your license server over HTTPS
  3. The server checks whether that account has an active license for your product
  4. If yes, the EA runs. If no, it stops with a clear error message
  5. You control which accounts are authorized from a dashboard, in real time

A customer cannot copy your .ex4 file and share it. The EA refuses to run on any account without an active license. You can add licenses when customers pay and revoke them instantly if they chargeback.

💡 Key advantage

Because the check happens on your server, you can revoke access at any time even after the customer has your file. No decompiler can bypass a server-side check.

Setting Up EA License Protection with MTLicense

Step 1: Create your free account

Sign up at mtlicense.com. You get an API key and dashboard access immediately with no credit card required.

Step 2: Add your EA as a product

Click New Product, name your EA, and copy the Product ID that is generated.

Step 3: Add two lines to your EA

Download LicenseManager4.mqh and place it in your MetaEditor includes folder. Add these two lines:

#include <LicenseManager4.mqh>

// In OnInit():
if(!LicenseManager::Check("YOUR_API_KEY", "YOUR_PRODUCT_ID")) return INIT_FAILED;

Compile your EA. The license check is now live.

Step 4: Issue licenses to customers

When a customer pays, add their account number in your dashboard. They run your EA immediately. To revoke, one click and they are done.

Common Questions

Does the license check require internet?

Yes, the EA needs to reach the MTLicense API on startup. Most traders on VPS or live accounts have permanent internet so this is rarely an issue.

Will this slow down my EA?

No. The check only happens in OnInit() once when the EA starts. The API call completes in under 200ms and has zero effect on trading performance.

The Numbers Make It Obvious

MTLicense starts at $19/month. If your EA sells for $50/month and even one pirated copy becomes a paying customer, you have covered your cost many times over.

Ready to stop the piracy?

Setup takes under 10 minutes. Free to start, no credit card required.

Protect My EA — Start Free →