IsDemo() returns False with Demo Account

 

Hi, 

Please, could you help me ?



void OnTick()

{

Comment(IsDemo());



That returns "False" with my demo account

 

I have seen some brokers incorrectly setting the demo / real flags. Not a lot you can do about it other than

1. Speak to your broker

2. Change servers (if possible)

3. Change brokers

Makes life hard when you're trying to limit the usage of your EA.

Out of interest, what does this show?

   long trade_mode = AccountInfoInteger(ACCOUNT_TRADE_MODE);
   Comment(EnumToString((ENUM_ACCOUNT_TRADE_MODE)trade_mode));
 
honest_knave:

I have seen some brokers incorrectly setting the demo / real flags. Not a lot you can do about it other than

1. Speak to your broker

2. Change servers (if possible)

3. Change brokers

Makes life hard when you're trying to limit the usage of your EA.

Out of interest, what does this show?

Thanks for you time,


That returns : ACCOUNT_TRADE_MODE_REAL

 
Frédéric LEBRE:

Thanks for you time,


That returns : ACCOUNT_TRADE_MODE_REAL

This is also problem with the MQL4, try this code ( indicator ):


int OnInit(){
   
   if (IsDemo())
    Print("DEMO: ",UninitializeReason()," ",AccountInfoInteger(ACCOUNT_TRADE_MODE)," == ",ACCOUNT_TRADE_MODE_REAL);
   else
    Print("NO DEMO: ",UninitializeReason()," ",AccountInfoInteger(ACCOUNT_TRADE_MODE)," == ",ACCOUNT_TRADE_MODE_REAL);
   return INIT_FAILED;
}

void OnTick(){;}

int OnDeinit(int reason){ Print("Reason: ",reason);return reason;}

get 2 different output.

first if the indicator attached in a chart. But if restarted platform MT4, IsDemo function return false


Milan 

Files:
_isdemo.jpg  55 kb
_isNdemo.jpg  63 kb
 
int OnInit(){
   if (IsDemo())
Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 
whroeder1:
Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

Thank's,

you are true, save for me many hours ...

 
Hello everyone,

Could anyone assist me with the issue below please ? 

We are creating an EA and trying to set it for free on a demo server and so i chose "true" for ISDEMO(), but when we run the expert on my broker demo server, it turns into "false" and asks for a license key.

Your assistance would be greatly appreciated.

Thanks