How to LOCK/Encrypt EA - page 12

 
fxwealth:
Hi, can anyone please show me how to do the following: I need to add some code to an EA which will allow it to trade with accounts starting with certain numbers only. For example I only want EA to trade with account numbers starting with 16*** The account number starts with 16 and is a five digit number...the remaining three numbers can be any numbers. Any help appreciated...Best rgds

if (StringSubstr(AccountNumber(),0,2) != '16') return;

 

Hi beckham.is.619, Many thanks

I tried your suggestion but get the following errorwhen i do a backtest: the first parameter for StringSubstr function must be a string

Any help appreciated

 
fxwealth:
Hi beckham.is.619, Many thanks

I tried your suggestion but get the following errorwhen i do a backtest: the first parameter for StringSubstr function must be a string

Any help appreciated

Ugly hack, but it should do the trick.

if (StringSubstr(DoubleToStr(AccountNumber(),0),0,2) != '16') return;

 
fxwealth:
Hi, can anyone please show me how to do the following: I need to add some code to an EA which will allow it to trade with accounts starting with certain numbers only. For example I only want EA to trade with account numbers starting with 16*** The account number starts with 16 and is a five digit number...the remaining three numbers can be any numbers. Any help appreciated...Best rgds

int f = AccountNumber() / 1000;

if(f!=16) return;

 

Hi beckham and Michel

Thank you both so much. Both your codes work and i am very appreciative of your help....All the best to you both

Best rgds

 

Hi beckham and michel

If I wanted to add another account number say 21 to the code how would i do that? I tried the else if option but doesnt work....your help is appreciated.

Best rgds

 
fxwealth:
Hi beckham and michel

If I wanted to add another account number say 21 to the code how would i do that? I tried the else if option but doesnt work....your help is appreciated.

Best rgds

int f = AccountNumber() / 1000;

if(f!=16 && f!=21) return;

Maybe easier to understand:

if(f == 16 || f == 21) // "||" is the logical "or" operator

{

// Do your stuff here

}

 

This code is in my EA: put it below int init() {

string ls_0 = "2010.04.18"; // Date when EA will expire

int str2time = StrToTime(ls_0);

if (TimeCurrent() >= str2time) {

Alert("Demo license expired!"); // Text that will pop-up when expired

return (0);

}

if (AccountNumber() != 100762) { // Account number for this EA

Alert("This EA is not licensed to your account number!");

return;

}

 

Hi michel, thank you so much...works like a charm. Dimaxx thanks to you as well

All the best to you...

 

Hi Michel

Would you be able to show me how to do the following: I do not want an EA to trade on a Sunday night. How can I prevent it from doing so?

Best rgds

Reason: