Features of the mql4 language, subtleties and techniques - page 27

 
Andrey Khatimlianskii:

The indicator is called with the wrong set of parameters

Yes, the indicator has quite a lot of parameters, is there any way to make sure that iCustom fills the memory? It takes about 2 hours to fill the memory, so testing an empty iCustom and adding one parameter at a time will take a long time. Any advice?
P.S. I will go through all the parameters visually as well.

 
Nauris Zukas:

Yes, the indicator has quite a few parameters, but is there any way to make sure that iCustom fills the memory exactly?

there will be a lot of indicator creation in the logs
 
TheXpert:
There will be a lot of indicators in the logs

Yes, I know what you mean, I have seen this in the strategy tester too, when a lot of indicators appear after a test. But everything works fine in the strategy tester here. And everything is displayed correctly in the logs.

 
Nauris Zukas:

Yes, the indicator has quite a few parameters, is there any way to make sure iCustom fills the memory? It takes about 2 hours to fill the memory, so testing an empty iCustom and adding one parameter at a time will take a long time. Any advice?
P.S. I will go through all the parameters visually as well.

Leave the call without parameters (then they will take the defaults), and observe. If the leak disappears, then that's what's wrong.

 
Nauris Zukas:

The EA eats up memory that builds up little by little.

How much is "a little"?

Maybe it really is a bit and this is the quote history that has appeared since the launch?

 
Andrey Khatimlianskii:

"Little by little" - how much?

Maybe it really is just a little, and it's the quote history that has appeared since the start?

I start MT4 with several EAs, enable memory logging. Where the arrow shows there is a crash, "not enough memory for EX4 file".


 
Andrey Khatimlianskii:

Leave the call without parameters (then they will take the defaults), and observe. If the leakage disappears, then that's what's wrong.

Ok, I'll do it this way.

 
Nauris Zukas:

I start MT4 with several EAs, enable memory recording. Where the arrow shows there is a crash, "not enough memory for EX4 file".

How much 40% of how much is being used?

It's growing linearly, looks like a crooked indicator call, yes.

 
Andrey Khatimlianskii:

40% of how much is used?

Grows linearly, looks like a curve indicator call, yes.

Seems to be a problem with the parameters. Thank you!

 

On MT4 this situation is possible (we will not talk about the reasons):

  • A position is open. The balance is equal to N.
  • From a certain moment the positions disappear. Equity and balance are equal to N. In the history of trades, there is no information about the position.
  • Terminal resetting does not help.
  • Several hours later the positions appear in the trading history (they closed under a certain condition). The balance and equity are adjusted accordingly.

This is a very rare situation that is caused by a confluence of many circumstances. But it can occur, even though the probability is about zero.

I suggest that all combat robots must have a mechanism for identifying such situations.

For this purpose, it is necessary to memorize the tickets of open orders and check their presence in the trade history in case of their disappearance. If they are not in the trading history, Alertim!


The function of such protection.

#define  TICKET_TYPE int

// Получаем все текущие тикеты.
int GetTickets( TICKET_TYPE &Tickets[] )
{
  int Amount = ArraySize(Tickets);
    
  for (int i = ArrayResize(Tickets, Amount + OrdersTotal()) - Amount - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS))
      Tickets[Amount++] = OrderTicket();
          
  return(ArrayResize(Tickets, Amount));
}

// Проверяет наличие потерянных тикетов.
int CheckTickets( void )
{
  static const bool IsTester = MQLInfoInteger(MQL_TESTER);
  int Amount = 0;
  
  if (!IsTester)
  {
    static TICKET_TYPE Tickets[];
    TICKET_TYPE BadTickets[];
    
    for (int i = ArrayResize(BadTickets, ArraySize(Tickets)) - 1; i >= 0; i--)
      if (!OrderSelect(Tickets[i], SELECT_BY_TICKET))
      {
        BadTickets[Amount++] = Tickets[i];
        
        Alert("Ticket " + (string)Tickets[i] + " is not found!");
      }
        
    ArrayResize(BadTickets, Amount);    
  
  #ifdef __MQL5__
    ArraySwap(Tickets, BadTickets);
  #else // __MQL5__
    ArrayFree(Tickets);
    
    ArrayCopy(Tickets, BadTickets);  
  #endif // __MQL5__
      
    GetTickets(Tickets);
  }
      
  return(Amount);
}
Call CheckTickets() at the beginning of OnTick.
Reason: