← Back to Blog
Protection Guide

MT4 EA License Protection: How to Add License Keys to Your Expert Advisor

April 7, 2026 · 10 min read · By MTLicense Team

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.

Why MT4 EAs Are So Easy to Pirate

MetaTrader 4 compiles your MQL4 source into an .ex4 binary. The problem is structural:

The Four Approaches to MT4 EA License Protection

1. Hardcoded Account Number (Do Not Do This)

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.

2. Encrypted Local License Files

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.

3. MetaQuotes Marketplace

Good protection but you are locked into their platform with a 30% commission cut and no ability to sell directly.

4. Server-Side License Validation (The Only Real Solution)

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.

Adding MTLicense to Your MT4 EA: Step by Step

Step 1: Create Your Free Account

Sign up at mtlicense.com. No credit card required. You get immediate dashboard access, an API key, and the SDK files.

Step 2: Add Your EA as a Product

Click Add Product in the dashboard. Give your EA a name. Copy the Product ID you receive.

Step 3: Download the MT4 SDK

Download LicenseManager4.mqh and place it in your MetaEditor Include folder: MQL4/Include/LicenseManager4.mqh

Step 4: Add Two Lines to Your EA

#include <LicenseManager4.mqh>

int OnInit() {
  if(!LicenseCheck("YOUR_API_KEY", "YOUR_PRODUCT_ID")) {
    return INIT_FAILED;
  }
  return INIT_SUCCEEDED;
}

Step 5: Compile and Distribute

Compile as normal. The .ex4 output is your protected binary. Distribute exactly as you do today.

Step 6: Activate Customer Licenses

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.

Protect your EA in the next 10 minutes

Free account. No credit card. Two lines of code.

Start Free Join 75+ EA developers already protecting their software

Comparing MT4 License Protection Methods

MethodPiracy ProtectionSetup TimeRevoke AccessCost
Hardcoded accountNone5 minNoFree
Local license fileWeak2-4 hrsHardFree
MQL5 MarketplaceGoodDaysYes30% cut
MTLicenseStrong10 minInstantFrom $19/mo

Common Questions

Does the license check slow down my EA?

No. The check happens only on initialization by default. Your EA tick processing is not affected.

What if the license server goes down?

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.

Can customers run on multiple accounts?

Yes. You can authorize multiple account numbers per customer. Each is a separate license entry you can revoke individually.

Does this work for MT5?

Yes. MTLicense provides LicenseManager5.mqh for MT5. Same two lines, same dashboard.

The Business Case

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.

Stop giving your EA away for free

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

Read next

What actually stops clients copying your EA →Bind your MT4 EA to an account number — the code →