• Skip to primary navigation
  • Skip to main content
  • Skip to footer
barmenteros FX logo

MetaTrader Programming Services | Programmers for MT4, MQL4, MT5, MQL5, Expert Advisor EA, Forex robots, Algo Trading | barmenteros FX

No matter if you need an MT4 programmer, EA programmer, Forex programmer, or MQL programmer. We are the best qualified team to develop your forex trading strategy. Highly skilled in MT4 programming, Expert Advisor EA programming, Forex programming, and MQL4 programming.

  • Home
  • Blog
  • Services
    • EA programming
    • MT4 Programming
    • MT5 Programming
    • EA Debugging and Code Review
    • TradingView Programming
    • NinjaTrader Programming
    • cTrader Programming
    • Forex Programming
    • Machine Learning For Trading
    • Deep Reinforcement Learning for Trading
  • Products
    • My Account
    • LicenseShield – MT4/MT5 License Protection
    • Latest Offers
    • MT4 Indicators
    • MT5 Indicators
  • Request Quote
  • Show Search
Hide Search
Home/Blog/How to Protect Your MT4 Programs: Simple Ways Even Without Being an MT4 Programmer
Padlock and shield icon representing MT4 program protection from unauthorized use

How to Protect Your MT4 Programs: Simple Ways Even Without Being an MT4 Programmer

If you’ve built an MT4 Expert Advisor, indicator, or script that you want to share or sell, you need a way to control who runs it. This guide covers five copy-paste MQL4 code methods — account binding, trial periods, demo-only restrictions, symbol restrictions, and how to combine them — plus MQL5 equivalents for each. No programming background required.

Explore LicenseShield — our MT4/MT5 license management product

Table of Contents

Toggle
  • Code Snippet to Bond a Program to a Single MT4 Forex Account
    • Download a Sample Expert Advisor with Account Protection
  • Code Snippet to Set a Trial Period
    • Download a Sample Indicator with a Trial Period
  • Limiting Use of Your MT4 Program to Demo Accounts Only
  • Binding to Multiple MT4 Accounts
  • Restricting Your MT4 Program to Specific Currency Pairs
  • Combining Multiple Restrictions
  • The Same Methods in MQL5
  • Adding an Extra Layer of Protection with MQL5 Cloud Protector
  • Advanced Protection: When Simple Measures Aren’t Enough
  • Enterprise License Management for MT4 & MT5
    • Choosing the Right Level of Protection
  • Frequently Asked Questions
    • Account Binding
    • MQL5 and Platform Compatibility
    • Troubleshooting
  • Protect Your MT4 Programs and Keep Them Safe
  • Connected Discoveries
    • Magic Number Collisions Are Quietly Eating Your Portfolio EA Account
    • Your EA’s Position Sizing Is Wrong When You Have More Than One Trade Open
    • DRL Agent Deployment: What Breaks Between Training and Live

Code Snippet to Bond a Program to a Single MT4 Forex Account

Here’s a simple way to limit the use of your MT4 program to a single MetaTrader account. By following these steps, you can send your Expert Advisor, Indicator, or Script to anyone you want, knowing that it won’t work on any other account except the one you authorized:

1. Open your MT4 program in MetaEditor by pressing F4 in the MetaTrader platform.

Opening MetaEditor in MetaTrader 4 by pressing F4 to edit MQL4 program source code

2. Copy the following code.

//--- code begin
int account_number = 0;
if(account_number > 0 && account_number != AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}
//--- code end

3. Modify the second line of the code by replacing ‘0’ with the number of the account authorized to use your MT4 program:

//--- code begin
int account_number = 52068425; // <-- WRITE HERE THE AUTHORIZED ACCOUNT NUMBER
if(account_number > 0 && account_number != AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}
//--- code end

4. Paste the code above between the brackets of ‘OnInit’ or ‘init’ (in old files) function of your MT4 program.

Account restriction code placed at the top of the OnInit function in MetaEditor

5. Ensure that the line of code (#property strict) is at the start of the program. If it’s missing, add it — this property enforces modern compiler standards on MT4 builds 600 and above. Without it, the account check may not compile correctly in newer MetaEditor versions.

Code placed at the beginning of the mt4 program

6. Compile the MT4 program.

Compiling the MT4 program in MetaEditor after adding account protection code

7. Share only the executable file (‘.ex4’).

Sharing only the compiled .ex4 executable file, not the .mq4 source code

Download a Sample Expert Advisor with Account Protection

The EA is linked by default to the fictitious MetaTrader 4 forex account 52068425. Change this number to the account you want to allow use of the program.

MACD SAMPLE – ACCOUNT PROTECTION

Code Snippet to Set a Trial Period

You can limit the use of your MT4 trading tool until a specific expiry date. The EA or indicator will run normally until that date, then stop executing permanently.

Follow the same steps above but replace steps 2 and 3 with the following:

2. Copy the following code.

//--- code begin
datetime trial_end_date = 0;
if(TimeCurrent() > trial_end_date)
{
    Print("Trial period has expired!");
    return(-1);
}
//--- code end

3. Replace `0` with your desired expiry date:

//--- code begin
datetime trial_end_date = D'31.12.2028'; // <-- SET PROGRAM EXPIRATION DATE
if(TimeCurrent() > trial_end_date)
{
    Print("Trial period has expired!");
    return(-1);
}
//--- code end

Download a Sample Indicator with a Trial Period

The indicator sample uses December 31, 2020 as its default expiry date — you must open the `.mq4` source file, update the `trial_end_date` line to your desired date, and recompile before distributing.

ATR – TRIAL PERIOD

Limiting Use of Your MT4 Program to Demo Accounts Only

If you want to distribute a free trial version that cannot run on live accounts, use this snippet to block live and contest account modes:

//--- code begin
if(AccountInfoInteger(ACCOUNT_TRADE_MODE) != ACCOUNT_TRADE_MODE_DEMO)
{
    Print("This program only works on demo accounts!");
    return(-1);
}
//--- code end

Binding to Multiple MT4 Accounts

If you need to authorize more than one account — for example, a client who runs both a personal and a funded account — use a combined condition. The key is the logic: deny access only when the current account matches neither of the authorized numbers.

//--- code begin
int AcctNbr1 = 52068425; // <-- authorized account 1
int AcctNbr2 = 26341416; // <-- authorized account 2
if(AcctNbr1 != AccountNumber() && AcctNbr2 != AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}
//--- code end

To authorize a third account, add `int AcctNbr3 = XXXXXXXX;` and extend the condition: `&& AcctNbr3 != AccountNumber()`.

Common mistake: Using two separate `if` blocks (one per account) will deny access to every account — no single account can simultaneously equal both numbers. The single combined condition above is the correct approach.

Restricting Your MT4 Program to Specific Currency Pairs

If you built an EA or indicator for a specific instrument and want to prevent misuse on incompatible pairs, add a symbol check inside `OnInit`.

For a single symbol:

//--- code begin
string allowed_symbol = "EURUSD";
if(Symbol() != allowed_symbol)
{
    Print("This program only works on EURUSD");
    return(-1);
}
//--- code end

For multiple symbols:

//--- code begin
string sym = Symbol();
if(sym != "EURUSD" && sym != "GBPUSD")
{
    Print("This program only works on EURUSD and GBPUSD");
    return(-1);
}
//--- code end

Broker naming note: Symbol names are broker-specific. “EURUSD” on one broker may appear as “EURUSDm” or “EURUSD.” on another. Verify the exact symbol name shown in your broker’s Market Watch before hardcoding it.

Combining Multiple Restrictions

You can stack any of the methods above inside the same `OnInit` function. The program checks each condition in sequence and stops at the first failure.

Example — require a specific account and enforce a trial period:

//--- code begin
int account_number  = 52068425; // <-- authorized account
datetime trial_end  = D'31.12.2028'; // <-- expiry date
if(account_number > 0 && account_number != AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}
if(TimeCurrent() > trial_end)
{
    Print("Trial period has expired!");
    return(-1);
}
//--- code end

Place all restriction blocks consecutively at the top of `OnInit`, before any initialization logic.

The Same Methods in MQL5

The code above is MQL4-specific. For MetaTrader 5 programs, three things change:

  • Remove `#property strict` — this property does not exist in MQL5.
  • Replace `AccountNumber()` with `AccountInfoInteger(ACCOUNT_LOGIN)` — this is the MQL5 equivalent.
  • Declare account numbers as `long` (not `int`) — MT5 account numbers can exceed the 32-bit integer range.
  • Return `INIT_FAILED` instead of `-1` — this is the MQL5 constant for initialization failure.

MQL5 — account binding:

//--- code begin
long account_number = 52068425; // use long, not int
if(account_number > 0 && account_number != AccountInfoInteger(ACCOUNT_LOGIN))
{
    Print("Account not allowed");
    return(INIT_FAILED);
}
//--- code end

MQL5 — trial period:

//--- code begin
datetime trial_end_date = D'31.12.2028';
if(TimeCurrent() > trial_end_date)
{
    Print("Trial period has expired!");
    return(INIT_FAILED);
}
//--- code end

MQL5 — demo-only restriction:

The `AccountInfoInteger(ACCOUNT_TRADE_MODE)` function and the `ACCOUNT_TRADE_MODE_DEMO` constant exist in both MQL4 and MQL5. No changes are needed for that snippet — paste it as-is.

Side-by-side comparison of MQL4 and MQL5 account restriction code showing the AccountNumber() to AccountInfoInteger(ACCOUNT_LOGIN) migration

Adding an Extra Layer of Protection with MQL5 Cloud Protector

The MetaTrader platform includes a tool that adds an additional layer of protection: MQL5 Cloud Protector. This free service encrypts your compiled `.ex4` or `.ex5` file at a level comparable to programs listed in the MQL5 Market.

It is advisable to use Cloud Protector whenever a high degree of protection is needed — particularly for programs you intend to sell commercially. From our experience building MT4/MT5 systems since 2011, Cloud Protector significantly reduces the practical need to use DLL-based protection schemes.

MQL5 Cloud Protector was introduced in MT5 build 1700 (late 2017) and was later made available for MT4.

Advanced Protection: When Simple Measures Aren’t Enough

Code-level restrictions work well for personal EAs and small-scale distribution. As your program gains more users or commercial value, you’ll reach limitations that embedded snippets cannot solve:

Decision flowchart comparing code-level MT4 protection methods versus enterprise license management for commercial distribution
  • You’re distributing to many clients and need centralized license control.
  • You want to issue updates only to licensed users.
  • You need usage analytics — who is running your program, on which account, and when.
  • You need to revoke access remotely without recompiling and redistributing.

These requirements are beyond what embedded MQL code can provide. Code-level protection cannot communicate with a server, cannot be updated without recompilation, and cannot be revoked without redistribution.

Enterprise License Management for MT4 & MT5

If you face those challenges, our Enterprise License Management for MetaTrader 4 & 5 service provides a server-side protection layer:

FeatureBenefit
Secure access control & account bindingPrevent unauthorized usage; bind licenses to authorized users or devices
Real-time usage analytics & dashboardsSee exactly who is using what — detect anomalies, make data-driven decisions
Flexible license modelsPer-user, per-instance, subscription-based, or custom enterprise licensing
Secure update pipelinesOnly licensed installations receive updates and patches

For an automated, code-integrated licensing product, see LicenseShield — our MT4/MT5 license management SaaS built specifically for commercial EA and indicator distribution.

Choosing the Right Level of Protection

ScenarioRecommended Approach
Personal EA or a handful of trusted clientsCode-level snippets (this guide)
Wider commercial distribution, up to ~20 clientsCode-level snippets + MQL5 Cloud Protector
Enterprise distribution: subscriptions, analytics, remote revocationEnterprise License Management

Frequently Asked Questions

Account Binding

Can I bind my MT4 program to multiple accounts at the same time?

Yes. Use a combined condition that denies access only when the current account matches neither of the authorized numbers:

int AcctNbr1 = 52068425;
int AcctNbr2 = 26341416;
if(AcctNbr1 != AccountNumber() && AcctNbr2 != AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}

Do not use two separate `if` blocks — that logic denies every account unconditionally.

Can I combine account restriction with a trial period?

Yes. Paste both restriction blocks consecutively at the top of `OnInit`. The program checks each condition in sequence — the first failure stops initialization. See the Combining Multiple Restrictions section above for the complete snippet.

MQL5 and Platform Compatibility

Does this code work in MQL5 / MetaTrader 5?

Yes, with three changes: remove `#property strict`, replace `AccountNumber()` with `AccountInfoInteger(ACCOUNT_LOGIN)`, and declare the account number as `long` instead of `int`. Return `INIT_FAILED` instead of `-1`. The MQL5 Equivalents section above has complete code for each method.

How do I restrict my program to specific currency pairs?

Use `Symbol()` inside `OnInit` to check the chart instrument against an allowed list. To restrict to one pair: `if(Symbol() != “EURUSD”) { Print(“Wrong symbol”); return(-1); }`. For multiple pairs, use a combined condition: `if(sym != “EURUSD” && sym != “GBPUSD”)`. Make sure the symbol string matches your broker’s exact naming.

Troubleshooting

Why does AccountNumber() return 0?

`AccountNumber()` returns 0 when the MetaTrader terminal is not yet connected to an account. This typically happens immediately after reopening MT4 before the connection is established. Wait for the terminal to reconnect and reload the indicator or EA — the account number will return correctly once the session is active.

Compilation gives errors after adding #property strict — why?

`#property strict` enforces modern compiler rules on code that previously compiled without them. It can surface type conversion warnings and undeclared identifier errors in older programs. Warnings labeled “possible loss of data due to type conversion” are generally safe to ignore and do not prevent compilation. Errors labeled as actual errors must be corrected before the file will compile.

If you cannot resolve the errors, omit `#property strict` and cast `AccountNumber()` explicitly:

extern int account_number = 52068425;
if(account_number > 0 && account_number != (int)AccountNumber())
{
    Print("Account not allowed");
    return(-1);
}
Can I use Alert() instead of Print() for the error message?

Yes. Replacing `Print(“Account not allowed”)` with `Alert(“Account not allowed”)` will show a visible popup dialog in MetaTrader instead of writing silently to the Journal tab. Both stop the program’s initialization — the difference is only in how the user is notified.

Is MQL5 Cloud Protector actually secure?

MQL5 Cloud Protector adds meaningful encryption, but no compiled binary is permanently unbreakable. Cloud Protector raises the difficulty significantly and makes casual reverse-engineering impractical. For commercial distribution requiring hard enforcement, combine Cloud Protector with a server-side licensing system — the code snippets in this guide alone provide modest protection that can be bypassed by anyone with a hex editor and patience.

Protect Your MT4 Programs and Keep Them Safe

Your MT4 programs are valuable intellectual property. Protecting them is critical to safeguarding both your business and your reputation.

The code methods in this guide cover the most common use cases: single-account binding, trial periods, demo restrictions, symbol restrictions, and any combination of these. When your distribution grows beyond a handful of clients, Enterprise License Management for MT4/5 provides infrastructure that embedded code cannot — remote revocation, usage analytics, and automated license control.

For professional help implementing any of these methods or building custom protection tailored to your setup, visit our MT4 programming services.

Alongside these measures: keep regular backups of your source `.mq4` files, share programs only with trusted partners, and never distribute the source file — only the compiled `.ex4`.

  • LinkedIn
  • Facebook
  • Telegram
  • Instagram
  • Mail
  • YouTube

Connected Discoveries


Unraveling Ideas That Inspire.


Two expert advisors with the same magic number colliding at a shared MetaTrader order pool — illustrating how unguarded OrderSelect loops act on positions they did not place

Magic Number Collisions Are Quietly Eating Your Portfolio EA Account

May 19, 2026

Three clients came to us this year with the same problem: a…

Continue Reading Magic Number Collisions Are Quietly Eating Your Portfolio EA Account

MQL5 code comparison showing AccountBalance() vs AccountEquity() for multi-position EA lot-size calculation

Your EA’s Position Sizing Is Wrong When You Have More Than One Trade Open

May 11, 2026

Three clients brought me the same EA rescue brief this year: a…

Continue Reading Your EA’s Position Sizing Is Wrong When You Have More Than One Trade Open

Diagram showing the structural gap between a DRL training pipeline and its production bridge deployment, representing the feature parity problem in live trading.

DRL Agent Deployment: What Breaks Between Training and Live

May 7, 2026

Most DRL agent deployment failures are not model failures — they are…

Continue Reading DRL Agent Deployment: What Breaks Between Training and Live

Written by:
barmenteros FX
Published on:
July 22, 2019
Last Updated:
April 29, 2026
Thoughts:
60 Comments

Categories: Blog

Reader Interactions

Comments

  1. Sky

    November 19, 2023 at 05:40

    Really appreciate you helping out the trading community. This code is very useful.

    It works for me however, I am having the issue whenever I restart Mt4, the indicators that I apply this code to get removed from all charts and I either have to drag the indicator back onto the chart or load the template I saved.

    Do you know what could be causing this issue?

    Reply
    • barmenteros FX

      November 19, 2023 at 11:58

      Thank you for your kind words and for reaching out with your concern. We’re glad to hear that the code has been useful to you.

      Regarding the issue you’re experiencing with indicators getting removed upon restarting MT4, it would be helpful if you could provide us with a screenshot showing how you’ve implemented the code and where exactly you’ve placed it. This will enable us to better understand the situation and assist you in resolving the issue more efficiently.

      Best regards

      Reply
      • Sky

        November 21, 2023 at 10:48

        Here’s the full code of one of my indicators with your code included:

        #property indicator_chart_window
        #property indicator_buffers 1
        #property indicator_color1 LightSeaGreen
        #property indicator_style1 1
        #property indicator_width1 2

        double TodayOpenBuffer[];
        extern double TimeZoneOfData=0;
        extern double Horizontaloffset=20;
        //+——————————————————————+
        //| Custom indicator initialization function |
        //+——————————————————————+
        int init()
        {

        //— code begin
        int account_number = 12345678; // 0 && account_number != AccountNumber())
        {
        Print(“Account not allowed”);
        return(-1);
        }
        //— code end

        SetIndexStyle(0,DRAW_LINE);
        SetIndexBuffer(0,TodayOpenBuffer);
        SetIndexLabel(0,”Open”);
        SetIndexEmptyValue(0,0.0);
        return(0);
        }
        //+——————————————————————+
        //| Custor indicator deinitialization function |
        //+——————————————————————+
        int deinit()
        {
        return(0);
        }
        //+——————————————————————+
        //| Custom indicator iteration function |
        //+——————————————————————+
        int start()
        {
        int counted_bars=IndicatorCounted();
        if(counted_bars 0) counted_bars–;
        int lastbar=Bars-counted_bars;
        if(counted_bars==0) lastbar-=1+1;

        DailyOpen(1,lastbar);
        return (0);
        }
        //+——————————————————————+
        //| DailyOpen |
        //+——————————————————————+
        int DailyOpen(int offset,int lastbar)
        {
        int shift;
        int tzdiffsec=TimeZoneOfData*3600;
        double barsper30=1.0*PERIOD_M30/Period();
        bool ShowDailyOpenLevel=True;
        // lastbar+= barsperday+2; // make sure we catch the daily open
        //lastbar=MathMin(Bars-20*barsper30-1,lastbar);

        for(shift=lastbar;shift>=offset;shift–)
        {
        TodayOpenBuffer[shift]=0;
        if(ShowDailyOpenLevel)
        {
        if(TimeDay(Time[shift]-tzdiffsec)!=TimeDay(Time[shift-1]-tzdiffsec))
        { // day change
        TodayOpenBuffer[shift]=Open[shift];
        TodayOpenBuffer[shift+1]=0; // avoid stairs in the line
        }
        else
        {
        TodayOpenBuffer[shift]=TodayOpenBuffer[shift+1];
        }
        }
        }
        return(0);
        }
        //+——————————————————————+

        Reply
        • barmenteros FX

          November 21, 2023 at 11:05

          // Issue in ‘init()’ function: Incorrect account validation logic
          // Current code:
          /*
          int account_number = 12345678; // 0 && account_number != AccountNumber())
          {
          Print(“Account not allowed”);
          return(-1);
          }
          */
          // Corrected version:
          int account_number = 12345678;
          if (account_number != 0 && account_number != AccountNumber())
          {
          Print(“Account not allowed”);
          return(-1);
          }
          // Ensure the ‘if’ statement is properly structured for account validation.

          Reply
          • Sky

            November 21, 2023 at 19:47

            Thank you, but the indicator no longer works for me with the new code. I’m not able to drag it onto the chart.

          • barmenteros FX

            November 23, 2023 at 17:32

            It seems that the issue might be related to other aspects of the indicator’s code, rather than the snippet we provided. We recommend compiling the indicator in the MetaTrader editor and addressing any errors or warnings that appear. This process should help identify and resolve any underlying problems. Best regards

  2. Alex

    July 9, 2023 at 03:30

    metaquotes – are russian freaks . Cloud protection garbage that can be easy decompiled, same as their MQLMarket are decompiles and resell now in Indian telegram channels …

    Reply
  3. Philip

    February 2, 2023 at 15:35

    Thank You for this, you have saved me a lot of time. I have not made an attempt yet, but I’m sure I can get the code provided to work.
    Thanks Again,
    Philip,
    Phil_GMT

    Reply
    • barmenteros FX

      February 2, 2023 at 17:00

      You’re welcome Philip! We’re glad we could help and that the information provided was useful to you. If you have any further questions or concerns, don’t hesitate to reach out.

      Reply
  4. Adam Ahmad

    September 12, 2022 at 05:24

    Big thanks for that simple code that you post and by the way, just one question if I change “{Print” to “{Alert”, the message will popup in the screen right?

    Reply
    • barmenteros FX

      September 12, 2022 at 09:12

      Yes Adam. That’s correct. Regards

      Reply
      • Adam Ahmad

        February 20, 2023 at 04:31

        Hi there, can you show the simple code to set the expert advisor only run on the demo account? For example ” This EA only works for Demo Account” Just wanna set for trial version without those 2 code that you provide. Hope to hear from you soon. Thx

        Reply
        • barmenteros FX

          February 22, 2023 at 22:39

          Hi Adam, we have updated the post to include your suggestion. Best regards

          Reply
  5. Robert Chen

    September 7, 2022 at 04:10

    Thanks for the great sharing.

    Wondering can you share also how to protect or lock a MT4 template to certain MT4 account number or name ?

    thanks in advance & hopefully can receive your reply

    Reply
    • barmenteros FX

      September 12, 2022 at 09:11

      Hi Robert. Not sure of getting what you mean. Can you explain more in detail with an example, please? Regards

      Reply
  6. Robert Chen

    September 7, 2022 at 04:07

    can you share also how to protect a MT4 template also ?

    Reply
  7. Abbey

    July 6, 2022 at 06:57

    Hi,

    Thanks for all you do. Is there a way to combine the two restrictions (bonding to one or two accounts and also setting a trial period)?

    Reply
    • barmenteros FX

      July 7, 2022 at 08:25

      Yes, Abbey. You can use a combination of the 2 restrictions. Best regards

      Reply
  8. Dave Waters

    April 26, 2022 at 14:56

    Very helpful article – thank you.

    Reply
    • barmenteros FX

      April 26, 2022 at 16:08

      Thanks for your comment, Dave. Really appreciate it!

      Reply
  9. Mathew Karanja

    March 13, 2022 at 15:48

    I have tried that code and did as instructed but an error msg keep popping up showing

    ‘{‘ – Function defination unexpected
    ‘}’ – not all control paths return a value

    Reply
    • barmenteros FX

      March 15, 2022 at 12:07

      Hi. Send us a screenshot showing the code you added. Thanks

      Reply
  10. Mike Rossi

    January 5, 2022 at 17:13

    Hello, how can I make an indicator work on 2 pairs only (EURUSD, GBPUSD).
    Indicator only not EA
    Thank you

    Reply
    • barmenteros FX

      January 10, 2022 at 13:59

      Hi. You must add a restriction in the code to limit the use of the indicator to only those pairs. You can send us the indicator and we’ll do it. Regards

      Reply
  11. JACK BE

    August 7, 2021 at 16:47

    I WANT TO USE THIS CODE IN MT5 BUT I DOES’T WORK CAN SOMEONE PROVIDE ME CODE FOR MQL5

    Reply
    • barmenteros FX

      August 9, 2021 at 12:34

      Hi Jack, can you send us a screenshot showing the code you used? Thanks

      Reply
  12. Tomi

    May 8, 2021 at 20:09

    Adding restriction or locking an indicator to a particular account number as you explained above clearly, is it the same with indicator on mt5 platform sir? I will like you to (if not too much to ask sir) help me on how to go about it with indicator on mt5 platform sir.
    Thanks

    Reply
    • barmenteros FX

      May 10, 2021 at 23:58

      Hi Tomi,

      Yes, basically it’s the same. Just dismiss ‘#property strict’ that’s not necessary in MQL5.

      Best regards

      Reply
  13. Micheal

    May 3, 2021 at 14:16

    Hello sir worked perfect , what if I want to use password or key ?

    Reply
    • barmenteros FX

      May 3, 2021 at 15:05

      Thanks for the feedback, Micheal. We’ll try to update the post to include password or key protection. Best regards

      Reply
  14. OPOH

    May 2, 2021 at 14:48

    The Codes is working perfectly and is so simple to implement

    Reply
    • barmenteros FX

      May 2, 2021 at 15:04

      Thank you for the feedback. Glad to hear it has been helpful to you.

      Reply
  15. John

    April 9, 2021 at 08:32

    Hello,

    Please I have an indicator in MT5 .mq5 , can you please assist me adding a code to lock the indicator to an account number?

    Thank you

    Reply
    • barmenteros FX

      April 12, 2021 at 18:19

      Hi John,

      Please, explain what step from the post you are not able to understand / implement.

      Thanks

      Reply
  16. Moe

    February 19, 2021 at 05:50

    I have tried Copied and pasted the code for my EA ,compile didn’t work

    Reply
    • barmenteros FX

      February 19, 2021 at 07:57

      Hi Moe. Please, send us a screenshot showing the code you added and the compilation error you get. You can send it to [email protected]
      Regards

      Reply
  17. Wongani Bulaya

    January 5, 2021 at 11:27

    hey guys, my software is working fine, but when i change the propety to strict thats when a number of erros are popping up
    like undeclared identifier and ‘if’ expressions not being allowedon a global space.
    what do i do?

    Reply
    • barmenteros FX

      January 5, 2021 at 12:52

      Hi Wongani, the strict property is used to give compatibility with programs developed before the recent MT4 versions (build 600+). It also implies that the old codes are checked according to the new compilers standards. That is why using the strict property may cause new errors and warnings to appear when compiling. In some cases the warnings can be ignored. Instead, the errors must be corrected so that the code can be compiled successfully. Regards

      Reply
  18. khoa le

    December 1, 2020 at 02:46

    hi,
    I pasted #property strict line in code but when compile got error :
    “possible loss of data die type conversion”
    Could you help me to solve it?
    thank you

    Reply
    • Barmenteros FX Staff

      December 1, 2020 at 09:07

      Hi,
      That’s not an error but a warning so you can compile the file properly. Anyway, send us a screenshot showing the line triggering the warning so we can take a look.
      Best regards

      Reply
  19. Chicco

    October 22, 2020 at 08:51

    Thank you! It works perfectly :) I really appreciate your wworks.
    What if I want to add 2 or more accounts. Should I use a comma or semi colon to separate multiple accounts?

    Reply
    • Barmenteros FX Staff

      October 23, 2020 at 09:22

      Hi Chicco,

      Find below a simple example:


      //--- code begin
      int AcctNbr1 = 52068425; // <-- write here the authorized account number if(AcctNbr1 > 0 && AcctNbr1 != AccountNumber())
      {Print("Account not allowed"); return(-1);}
      int AcctNbr2 = 26341416; // <-- write here the authorized account number if(AcctNbr2 > 0 && AcctNbr2 != AccountNumber())
      {Print("Account not allowed"); return(-1);}
      //--- code end

      Best regards

      Reply
      • Mohammed

        October 22, 2022 at 09:07

        hey dear thanks for your great efforts

        i just follow your instruction for single account it is working well but when i add second account EA not working even i follow same code you post
        {

        //— code begin
        int AcctNbr1 = 274282; // 0 && AcctNbr1 != AccountNumber())
        {Print(“Account not allowed”); return(-1);}
        int AcctNbr2 = 277166; // 0 && AcctNbr2 != AccountNumber())
        {Print(“Account not allowed”); return(-1);}
        //— code end

        }

        please need your advise

        thanks

        Reply
        • barmenteros FX

          October 23, 2022 at 13:17

          Hi. Your code does not have much to do with what we publish. In your case, use the following:

          //— code begin
          int AcctNbr1 = 274282;
          int AcctNbr2 = 277166;
          if(AcctNbr1 != AccountNumber() && AcctNbr2 != AccountNumber())
          {Print(“Account not allowed”); return(-1);}
          //— code end

          Reply
  20. Matimba

    September 20, 2020 at 17:55

    Hi, I did put the code as instructed but it gives me an error code ” onlnit- function already defined and has a body

    This is the code i was trying to put on my indicator and ea. please help me out on how to fix this issue
    int OnInit()
    {
    int AcctNbr = 21698831; // 0 &&
    AcctNbr != AccountNumber())
    {
    Alert(“Account not allowed”);
    return(-1);
    }
    return(INIT_SUCCEEDED);
    }

    Reply
    • Barmenteros FX Staff

      September 22, 2020 at 17:47

      Hi Matimba,

      You get that error because you already have a function in the code with the same name (‘OnInit’), so you should delete this new ‘OnInit’ function you created, search the ‘OnInit’ function already existing in your code, and copy the snippet inside it. In the other hand, your code won’t run since it contains error. Please, recheck your code and make sure it’s the same as the code we published in this post.

      Thanks

      Reply
      • jaison

        December 11, 2020 at 19:18

        hi i got an error like this…
        can u show me how to put that codes correctly..

        Reply
        • Barmenteros FX Staff

          December 12, 2020 at 09:36

          Hi Jaison,
          Please, tell us what’s not clear in our previous reply so we can provide a better explanation.
          Regards

          Reply
  21. Troc

    September 17, 2020 at 12:18

    Hello Bamenteros,

    Many thanks for your great help!
    Could you show us how to modify the code slightly so instead of checking for account number it validates against the name of the account?

    Many many thanks Barmenteros!
    You guys are great!

    Reply
    • Barmenteros FX Staff

      September 22, 2020 at 17:50

      Hi Troc,

      Please, send us a screenshot highlighting what do you mean by account name. If it’s what we think, you should notice that the name of the account is the same for all the accounts belonging to the same broker server, so it won’t be a valid verification method.

      Thanks

      Reply
  22. rosa

    August 25, 2020 at 15:11

    Alert(“acct numbr> ” + AccountNumber());
    //— code begin
    int AcctNbr = 452295; // 0 && AcctNbr != AccountNumber())
    {
    Alert(“No puedes usar este indicador. Contacta con [email protected]” + AcctNbr);
    return(-1);
    //— code end
    }

    Reply
    • Barmenteros FX Staff

      August 26, 2020 at 19:58

      Hi Rosa,

      Not sure what you are trying to do but your code is different from the code we posted here.

      Best regards

      Reply
  23. rosa

    August 25, 2020 at 13:11

    Hi,
    AccountNumber() returns “0” so it doesn´t work if you already have the indicator on your chart, close mt4 and reopen it.

    int OnInit() {
    //— code begin
    Alert(“accountnumber: ” + AccountNumber());
    int AcctNbr = XXXXXX; // 0 && AcctNbr != AccountNumber())
    {
    Alert(“not allowed: ” + AcctNbr );
    return(-1);
    //— code end
    }
    }

    Reply
    • Barmenteros FX Staff

      August 26, 2020 at 19:58

      Hi Rosa,

      Not sure what you are trying to do but your code is different from the code we posted here.

      Best regards

      Reply
  24. Francis

    July 23, 2020 at 16:17

    i tried to do this to restrict my indicator to a particular account but still its not working

    Reply
    • Barmenteros FX Staff

      July 24, 2020 at 14:18

      Hi. Please, send us a screenshot of the code you added and where you placed it. Thanks

      Reply
  25. Lito Lapis

    June 15, 2020 at 06:45

    Hi,
    Is it possible to create a code protector for MT4 that you can share to your client that will expire in an X amount of days or months?

    Thank you.
    Lito

    Reply
    • Barmenteros FX Staff

      June 15, 2020 at 10:21

      Hi Lito. Yes, it’s possible. Greetings

      Reply
  26. gary

    September 9, 2019 at 23:20

    I read somewhere on your blog abt using vmprotect for extra protection, but cant seemed to find the post. Can u share a little more on your experience of using that? Thank you.

    Reply
    • Barmenteros FX Staff

      September 10, 2019 at 11:25

      Hi Gary. Unfortunately, we don’t have any post related to VmProtect. Nevertheless, you can find a lot of related info on the web. Best regards

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

barmenteros FX

Avenida Principe Salman, 6, 5th
29603 Marbella (Malaga) — Spain

Copyright © 2026

Footer

COMPANY

  • Home
  • About barmenteros FX
  • Contact
  • Request Quote

SERVICES

  • EA Programming
  • MT4 Programming
  • MT5 Programming
  • MQL4 Programming
  • MQL5 Programming
  • EA Debugging and Code Review
  • TradingView Programming
  • NinjaTrader Programming
  • cTrader Programming
  • Forex Programming
  • Machine Learning For Trading
  • Python to MetaTrader Integration
  • Deep Reinforcement Learning for Trading
  • MetaTrader 4/5 License Management
  • All Services

PRODUCTS

  • My account
  • LicenseShield – MT4/MT5 License Protection
  • Latest Offers
  • MT4 Indicators
  • MT5 Indicators

LEGAL

  • Terms and Conditions
  • Privacy Policy
  • Cookies Policy
  • Risk Disclosure
  • Payments & Refunds Policy
  • Warranty & Support Policy
  • Intellectual Property Notice
  • General Disclaimer