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

 
Nauris Zukas:
Good afternoon!
One broker is constantly (once or twice a day) MarketInfo() flies off, gets value 0 ( specifically MODE_MARGINREQUIRED). It's kind of normal, but at the same time there is no attempt to reach the iCustom() indicator (connected through a resource). Even after MarketInfo() receives data, iCustom() remains silent. Only restarting the terminal helps. How to access the indicator without restarting the terminal, any ideas? Can the indicator disappear from a resource somewhere?

After a month of all sorts of tests I can already say quite confidently that there is a problem, only I can't tell if the resource is missing or if iCustom() is broken. The problem is detected only at one broker, which is very unpleasant for real trading. Before you throw around words like MT4 or MQL it's a bug, I will give you the latest and simplest code and test execution. I will also post the results. Maybe there is a bug in my code, that I don't know about. Once again I remind you that the problem is only detected with one broker (you will see in the logbook).

Indicator:

//+------------------------------------------------------------------+
//|                                               Test_Lost_Indi.mq4 |
//|                                                     Nauris Zukas |
//|                             https://www.mql5.com/ru/users/abeiks |
//+------------------------------------------------------------------+
#property copyright "Nauris Zukas"
#property link      "https://www.mql5.com/ru/users/abeiks"
#property version   "1.00"
#property strict
#property indicator_chart_window

double OutputBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   IndicatorBuffers(1);
   SetIndexBuffer(0,OutputBuffer,INDICATOR_CALCULATIONS);
   SetIndexEmptyValue(0,0.0);


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

   Print("-4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): ",TimeCurrent());
   OutputBuffer[0]=(double)TimeCurrent();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Expert:

//+------------------------------------------------------------------+
//|                                           Test_Lost_Resource.mq4 |
//|                                                     Nauris Zukas |
//|                             https://www.mql5.com/ru/users/abeiks |
//+------------------------------------------------------------------+
#property copyright "Nauris Zukas"
#property link      "https://www.mql5.com/ru/users/abeiks"
#property version   "1.00"
#property strict

#resource "\\Indicators\\Test_Lost_Indi.ex4"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   EventSetTimer(60);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   double Output1=iCustom(NULL,PERIOD_M1,"::Indicators\\Test_Lost_Indi.ex4",0,0);
   datetime ReceiveTime=(datetime)(int)Output1;
   if(TimeCurrent()>ReceiveTime+61)
      Print("-4002- INCORECT LAST INDICATOR TIME ReceiveTime: ",ReceiveTime, " TimeCurrent(): ",TimeCurrent());

   Print("-4003- OnTimer() ReceiveTime: ",ReceiveTime, " TimeCurrent(): ",TimeCurrent());
  }
//+------------------------------------------------------------------+

Receives the latest data from the indicator.
The indicator does not respond any more.
Expert log:

0       09:08:42.942    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:08:41
0       09:08:42.942    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:08:41 TimeCurrent(): 2020.10.27 09:08:41
0       09:09:42.955    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:09:42
0       09:09:42.955    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:09:42 TimeCurrent(): 2020.10.27 09:09:42
0       09:10:42.966    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:10:42
0       09:10:42.966    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:10:42 TimeCurrent(): 2020.10.27 09:10:42
0       09:11:42.979    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:11:42
0       09:11:42.979    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:11:42 TimeCurrent(): 2020.10.27 09:11:42
0       09:12:43.080    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:12:32
0       09:12:43.080    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:12:32 TimeCurrent(): 2020.10.27 09:12:32
0       09:13:43.010    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:12:48
0       09:13:43.010    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:12:48
0       09:14:43.012    Test_Lost_Resource GBPNZD,H1: -4002- INCORECT LAST INDICATOR TIME ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:14:42
0       09:14:43.012    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:14:42
0       09:15:43.025    Test_Lost_Resource GBPNZD,H1: -4002- INCORECT LAST INDICATOR TIME ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:15:42
0       09:15:43.025    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:15:42
0       09:16:43.039    Test_Lost_Resource GBPNZD,H1: -4002- INCORECT LAST INDICATOR TIME ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:16:42
0       09:16:43.039    Test_Lost_Resource GBPNZD,H1: -4003- OnTimer() Broker MarketInfo error ReceiveTime: 2020.10.27 09:12:48 TimeCurrent(): 2020.10.27 09:16:42
0

MT4 log at this time:

0       07:13:36.398    '21035322': login datacenter on RoboForex-Pro through DataCenter Europe #3 (ping: 53.56 ms)
0       07:13:36.802    '21035322': previous successful authorization performed from 87.110.24.238
1       09:12:42.982    '21035322': ping failed
0       09:12:43.690    '21035322': login on RoboForex-Pro through DataCenter Europe #3 (ping: 53.56 ms)
0       09:12:44.907    '21035322': login datacenter on RoboForex-Pro through DataCenter Europe #3 (ping: 53.56 ms)
0       09:12:45.317    '21035322': previous successful authorization performed from 87.110.24.238
1       09:12:58.925    '21035322': datacenter connecting failed [6]
0       09:12:59.475    '21035322': login on RoboForex-Pro through DataCenter Europe #3 (ping: 53.56 ms)
0       09:13:02.919    '21035322': ping to current access point DataCenter Europe #3 is 48.62 ms
0       09:13:59.826    '21035322': login datacenter on RoboForex-Pro
0       09:14:05.639    '21035322': login on RoboForex-Pro through DataCenter Europe #5 (ping: 68.86 ms)
0       09:14:06.482    '21035322': login datacenter on RoboForex-Pro through DataCenter Europe #5 (ping: 68.86 ms)
0       09:14:07.048    '21035322': previous successful authorization performed from 87.110.24.238
0       09:14:17.958    '21035322': ping to current access point DataCenter Europe #5 is 89.81 ms
1       11:12:31.864    '21035322': ping failed
1       11:12:31.864    '21035322': datacenter connecting failed [6]
 
Nauris Zukas:

After a month of all sorts of tests I can already say quite confidently that there is a problem, only I can't tell if the resource is missing or if iCustom() is broken. The problem is detected only at one broker, which is very unpleasant for real trading. Before you throw around words like MT4 or MQL it's a bug, I will give you the latest and easiest code and test execution. I will also post the results. Maybe there is an error in my code, that I don't know about. Once again I remind you that the problem is only detected with one broker (you will see in the logbook).

Indicator:

Expert:

Receives the latest data from the indicator.
The indicator does not respond any more.
Expert log:

MT4 log at this time:

TimeCurrent() in the indicator called by iCustom stops working when re-logging?

Why do you needTimeCurrent() in the indicator?

Are timeseries (time[], open[], etc.) updated?

 
Andrey Khatimlianskii:

Does TimeCurrent() in an indicator called by iCustom stop working when re-logging?

What isTimeCurrent() forin the indicator?

Are the timeseries (time[], open[], etc.) updated?

Everything stops working, as if there is no indicator anymore. TimeCurrent() just to check, last time to see. Nothing (not time[], open[], etc.) works because indicator just doesn't respond anymore. This is the last print from indicator, there is no more:

0       09:13:43.010    Test_Lost_Indi.ex4 GBPNZD,M1: -4005- - - - OnCalculate() Broker MarketInfo error  Broke indicator next TimeCurrent(): 2020.10.27 09:12:48
 
To get around the MQL4 limitation, you have to write like this.
#property strict

class A
{
protected:
  template <typename T>
  void f( const T* ) {}
};

class B : public A
{
public:
  void f( const B* b )
  {
  #ifdef __MQL5__
    this.A::f(b);
  #else
    this.f((const A*) b); // Обходим Stack overflow.
  #endif
  }  
};

void OnStart()
{  
  B b;
  
  b.f(&b);
}
 
fxsaber:
To get around the MQL4 limitation, I have to write it this way.

Religion is certainly a good thing (I mean explicitly this.*), but it is better to leave it to the church.

class A
{
protected:
  template <typename T>
  void f( const T* ) {Print(typename(T));}
};

class B : public A
{
public:
  void f( const B* b )
  {
    A::f(b);
  }  
};

void OnStart()
{  
  B b;
  
  b.f(&b);
}

I think it would be more succinct.

 
Vladimir Simakov:

Religion is certainly a good thing (I mean explicitly this.*), but it is better to leave it to the church.

I think it would be more succinct.

class A
{
protected:
  static void f( const A* ) { Print(__FUNCSIG__); }
  
  template <typename T>
  void f( const T* ) {Print(typename(T));} // Почему B?
};

class B : public A
{
public:
  void f( const A* a )
  {
    A::f(a); // как вызвать static-метод?
  }  
};

void OnStart()
{  
  B b;
  
  b.f(&b); // deprecated behavior, hidden method calling will be disabled in a future MQL compiler version
}
It's under an A.
 
fxsaber:
This is under 5.

Ask the developers: why is the template method from the protected zone called?

UPD: it's the one the compiler substitutes in the call, not B::f(const A*)

 

Help bypass an MQL4 compiler bug that is no longer being developed.

class A
{
public:
  static bool f() { return(true); }
};

template <typename T>
void g( )
{
  bool Res = T::f(); // '::' - unexpected token, 'f' - function not defined.
  
  T::f(); // OK
}

void OnStart()
{
  g<A>();
}

Search string: Oshibka 021.

 
fxsaber:

Help get around an MQL4 compiler bug that is no longer being developed.

this is how MQL4 compiles :

class A
{
public:
  static bool f() { return(true); }
};

template <typename T1, typename T2>
void g( )
{
  
  T1 tmp;
  T2 res = tmp.f(); // OK
}

void OnStart()
{
  g<A,bool>();
}
//+------------------------------------------------------------------+

UPD:

Basically compiles without typename T2 too

 
Igor Makanu:

This is how it compiles in MQL4 :

UPD:

Basically compiles without typename T2 too

Thank you!