IsDemo() returns False with Demo Account

To add comments, please log in or register
Frédéric LEBRE
413
Frédéric LEBRE  

Hi, 

Please, could you help me ?



void OnTick()

{

Comment(IsDemo());



That returns "False" with my demo account

honest_knave
Moderator
2308
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?

   long trade_mode = AccountInfoInteger(ACCOUNT_TRADE_MODE);
   Comment(EnumToString((ENUM_ACCOUNT_TRADE_MODE)trade_mode));
Frédéric LEBRE
413
Frédéric LEBRE  
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

NomeX5cor
11
NomeX5cor  
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
whroeder1
17927
whroeder1  
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.
NomeX5cor
11
NomeX5cor  
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 ...

To add comments, please log in or register