AccountInfoDouble(ACCOUNT_EQUITY) returns 0 in Demo Account

To add comments, please log in or register
Martin Bittencourt
1027
Martin Bittencourt  

Hi,

I have an EA I developed and have used it for a lot of months in real time account, when it worked fine.

Recently I decided to do some changes in the setups used and that lead to me to test it in the Demo account, something I normally didn't do before. And now, surprisingly, it is finishing trading before the configured end of period because AccountInfoDouble(ACCOUNT_EQUITY) is returning 0 during operation, all this when the Demo account has almost 10 million R$ available.

The code is called after every new tick inside OnTick() function. For some time, everything works fine with the current equity being returned and some positions are open and closed. But then, after some random amount of minutes (and trades), I get equity = 0. Since this is part of a security algorithm against 'too much loss today', all open positions are closed.

So, what could  be making this function suddently give a wrong result? 

William Roeder
22709
William Roeder  
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

    Fix your broken code.

    With the information you've provided — we can only guess. And you haven't provided any information for that.

  2. 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.
Vladimir Karputov
Moderator
207337
Vladimir Karputov  
Martin Bittencourt :

Hi,

I have an EA I developed and have used it for a lot of months in real time account, when it worked fine.

Recently I decided to do some changes in the setups used and that lead to me to test it in the Demo account, something I normally didn't do before. And now, surprisingly, it is finishing trading before the configured end of period because AccountInfoDouble( ACCOUNT_EQUITY ) is returning 0 during operation, all this when the Demo account has almost 10 million R$ available.

The code is called after every new tick inside OnTick() function. For some time, everything works fine with the current equity being returned and some positions are open and closed. But then, after some random amount of minutes (and trades), I get equity = 0. Since this is part of a security algorithm against 'too much loss today', all open positions are closed.

So, what could  be making this function suddently give a wrong result? 

To collect statistics, check (and print) some other parameters: Margin, Free Margin, TERMINAL_CONNECTED. Does this moment fall into clearing?

MetaQUANT
179
MetaQUANT  
I am experiencing the same bug. Started after the latest release for 10th July 2020.
   double equity=AccountInfoDouble(ACCOUNT_EQUITY);
   if(equity<=EquitySL && equity>0)   
     {
      CloseAllTrades();
      ExpertRemove();
      return;
     }

I have excluded the zero values and detaching of the EA to avoid situations for opening and closing of trades.

This code is running within OnTick.

Vladimir Karputov
Moderator
207337
Vladimir Karputov  

Today I'll put the code:

//+------------------------------------------------------------------+
//|                                         Check ACCOUNT_EQUITY.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double equity=AccountInfoDouble(ACCOUNT_EQUITY);
   if(equity<=0.0)
      Alert(__FILE__," ",__FUNCTION__,", ERROR: ACCOUNT_EQUITY returned ",DoubleToString(equity,8));
  }
//+------------------------------------------------------------------+

to the following configuration:

2020.07.30 07:09:20.679 Terminal        MetaTrader 5 x64 build 2563 started for MetaQuotes Software Corp.
2020.07.30 07:09:20.679 Terminal        Windows 10 build 19041, Intel Core i7-9750H  @ 2.60GHz, 24 / 31 Gb memory, 1690 / 1861 Gb disk, IE 11, UAC, GMT+2
2020.07.30 07:09:20.679 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
2020.07.30 07:09:28.756 Network '32113828': authorized on MetaQuotes-Demo through Access Point EU 2 (ping: 64.53 ms, build 2563)

and in:

2020.07.30 07:29:34.240 Terminal        MetaTrader 5 x64 build 2560 started for MetaQuotes Software Corp.
2020.07.30 07:29:34.240 Terminal        Windows 10 build 19041, Intel Core i7-9750H  @ 2.60GHz, 24 / 31 Gb memory, 1690 / 1861 Gb disk, IE 11, UAC, GMT+2
2020.07.30 07:29:34.240 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\431DCBD444D0C6CA1C175FACFD0E248D
2020.07.30 07:29:37.494 Network '51010': authorized on Just2Trade-MT5 through MT5.AccessServer #6 (ping: 45.50 ms, build 2470)



terminal and server have old build.

Please enter your data (terminal build, operating system type, server build).

Vladimir Karputov
Moderator
207337
Vladimir Karputov  
On two terminals, two tests have been going on for more than three hours - there are no errors. I have never gotten the Equity value equal to zero.
MetaQUANT
179
MetaQUANT  

Вот значения, отображаемые с помощью Alert (AccountInfoDouble ( ACCOUNT_EQUITY ));


Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
, then each symbol positions will be closed in the same order, in which they are opened, starting with the oldest one. In case of an attempt to close positions in a different order, the trader will receive an appropriate error. There are several types of accounts that can be opened on a trade server. The type of account on which an MQL5 program...
Vladimir Karputov
Moderator
207337
Vladimir Karputov  
MetaQUANT :

Вот значения, отображаемые с помощью Alert (AccountInfoDouble ( ACCOUNT_EQUITY ));


Please take the data from the "Journal" tab. Required fields are required:

2020.08.07 08:52:52.287 Terminal        MetaTrader 5 x64 build 2567 started for MetaQuotes Software Corp.
2020.08.07 08:52:52.318 Terminal        Windows 10 build 19041, Intel Core i7-9750H  @ 2.60GHz, 24 / 31 Gb memory, 1680 / 1861 Gb disk, IE 11, UAC, GMT+2
2020.08.07 08:52:52.318 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\431DCBD444D0C6CA1C175FACFD0E248D
2020.08.07 08:53:02.241 Network '51010': authorized on Just2Trade-MT5 through MT5.AccessServer #6 (ping: 46.29 ms, build 2470)
Fernando Souza
42
Fernando Souza  

Hi Martin,


I can see that you is Brazilian, like me. Look into the journal log and check if terminal lost the connection right before you receive the wrong information.


I was having a similar behavior in my expert advisor, my EA read open position to check if the trade still valid or the user closed it manually and clean global variables once the trade is not active, however, when the terminal lost the connection the open positions can't be read and EA understood that it is not valid anymore.


I add a check if the connection still valid and if it is not skip the code. It happens very often with DEMO account of two brokers I'm using.

Vladimir Karputov
Moderator
207337
Vladimir Karputov  
Fernando Souza :

Hi Martin,


I can see that you is Brazilian, like me. Look into the journal log and check if terminal lost the connection right before you receive the wrong information.


I was having a similar behavior in my expert advisor, my EA read open position to check if the trade still valid or the user closed it manually and clean global variables once the trade is not active, however, when the terminal lost the connection the open positions can't be read and EA understood that it is not valid anymore.


I add a check if the connection still valid and if it is not skip the code. It happens very often with DEMO account of two brokers I'm using.

By the way, I previously advised almost the same thing:

Forum on trading, automated trading systems and testing trading strategies

AccountInfoDouble(ACCOUNT_EQUITY) returns 0 in Demo Account

Vladimir Karputov, 2020.07.24 12:21

To collect statistics, check (and print) some other parameters: Margin, Free Margin, TERMINAL_CONNECTED. Does this moment fall into clearing?


To add comments, please log in or register