EA Licensing · With Code

How to Add License Expiry to Your MT4/MT5 EA

Time-limit your Expert Advisor so a subscription actually ends when the payments do — the five-minute version, and the honest reason it isn't enough on its own.

June 30, 2026 6 min read MT4 + MT5

You sold your Expert Advisor as a monthly subscription. The payment stops in March — but the .ex4 sitting on your customer's machine keeps trading in April, May, and every month after, because nothing in the file knows the deal is over. An expiry date fixes that. Here's the simple version, and the reason it quietly fails once real money is involved.

01 / The ideaWhat an expiry check actually is

It's dead simple: the EA compares today's date to an end date, and refuses to run once that date has passed. The only real question is where the end date lives. You have two options — bake it into the compiled file, or keep it on a server the EA checks at startup. The first takes five minutes and works for a trial. The second is the one you actually want the moment you're charging people. We'll build both.

02 / The codeHardcoded expiry in OnInit()

Drop this straight into OnInit(). If the current server time is past your date, the EA alerts the user and refuses to initialise. It's identical on both platforms bar the boilerplate.

MQL4

// --- Hardcoded expiry (MQL4) ---
datetime ExpiryDate = D'2026.12.31 23:59';

int OnInit()
{
   if(TimeCurrent() > ExpiryDate)
   {
      Alert("This EA license has expired. Contact the vendor to renew.");
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

MQL5

// --- Hardcoded expiry (MQL5) ---
datetime ExpiryDate = D'2026.12.31 23:59';

int OnInit()
{
   if(TimeCurrent() > ExpiryDate)
   {
      Alert("This EA license has expired. Contact the vendor to renew.");
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

Compile, and the EA stops working after 31 December 2026. For a two-week trial you hand to one person, that is genuinely all you need.

03 / The catchWhy one date doesn't scale

Now the problems. That date is the same for every copy you ship — you can't give Customer A a March expiry and Customer B a June one without compiling a separate file for each, which falls apart past a handful of buyers. And the date is inside the file: TimeCurrent() reads the broker's server time, but a determined user can still run an old build, roll their machine back, or pay someone to patch the constant out of the .ex4 entirely.

The problemA hardcoded date gates your honest customers and barely slows down anyone willing to cheat. It's a padlock drawn on the door in marker — fine for a trial, useless as a subscription.

04 / What actually holdsMove the date to a server

The fix is to move the expiry off the file and onto a server. Instead of storing a date, the EA sends its license key on startup and asks one question: is this key still active? The server holds a separate expiry for every customer, so you set, extend, or cut anyone's access from a dashboard — no recompile, no reshipping. There's no date in the file to patch, and rolling back the clock does nothing, because the answer comes from your server's clock, not theirs.

On the EA side that's a single WebRequest call in OnInit() and a few lines to read the response. The heavy part isn't the EA — it's running the server, the database of keys and expiry dates, and the endpoint, reliably, forever.

The fixServer-issued expiry, one date per license key. The EA asks and obeys; you stay in control from a dashboard. A patched file or a rolled-back clock changes nothing, because the customer never held the expiry in the first place.

Skip the server-building

MTLicense tracks every customer's expiry for you

A hosted license system for MT4/MT5 sellers. Issue keys, set an expiry per customer, extend or revoke instantly — all from one dashboard. Your EA makes one check on startup; we hold the dates, so a rolled-back clock or a patched file changes nothing.

Start a free 14-day trial →

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

Hardcode a date when you're handing one person a time-limited trial. The moment you're running real subscriptions for real money, the expiry belongs on a server — not in a file your customer controls.