Caratteristiche del linguaggio mql4, sottigliezze e tecniche - pagina 33

 
Nauris Zukas:
Buon pomeriggio!
Un broker è costantemente (una o due volte al giorno) MarketInfo() vola via, ottiene il valore 0 ( specificamente MODE_MARGINREQUIRED). È abbastanza normale, ma allo stesso tempo non c'è nessun tentativo di raggiungere l'indicatore iCustom() (collegato attraverso una risorsa). Anche dopo che MarketInfo() riceve i dati, iCustom() rimane in silenzio. Solo il riavvio del terminale aiuta. Come accedere all'indicatore senza riavviare il terminale, qualche idea? L'indicatore può sparire da qualche parte da una risorsa?

Dopo un mese di test di ogni tipo posso già dire con sicurezza che c'è un problema, solo che non posso dire se la risorsa manca o se iCustom() è rotto. Il problema viene rilevato solo in un broker, il che è molto spiacevole per il trading reale. Prima di buttare in giro parole come MT4 o MQL è un bug, vi darò l'ultimo e più semplice codice ed esecuzione di test. Pubblicherò anche i risultati. Forse c'è un bug nel mio codice, che non conosco. Ancora una volta vi ricordo che il problema viene rilevato solo con un broker (vedrete nel registro).

Indicatore:

//+------------------------------------------------------------------+
//|                                               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);
  }
//+------------------------------------------------------------------+

Esperto:

//+------------------------------------------------------------------+
//|                                           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());
  }
//+------------------------------------------------------------------+

Riceve gli ultimi dati dell'indicatore.
L'indicatore non risponde più.
Diario dell'esperto:

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

Log di MT4 in questo momento:

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:

Dopo un mese di test di ogni tipo posso già dire con sicurezza che c'è un problema, solo che non posso dire se manca la risorsa o se iCustom() è rotto. Il problema viene rilevato solo in un broker, il che è molto spiacevole per il trading reale. Prima di buttare in giro parole come MT4 o MQL è un bug, vi darò l'ultimo e più semplice codice ed esecuzione di test. Pubblicherò anche i risultati. Forse c'è un errore nel mio codice, che non conosco. Ancora una volta vi ricordo che il problema viene rilevato solo con un broker (vedrete nel registro).

Indicatore:

Esperto:

Riceve gli ultimi dati dell'indicatore.
L'indicatore non risponde più.
Diario dell'esperto:

Registro MT4 in questo momento:

TimeCurrent() nell'indicatore chiamato da iCustom smette di funzionare quando si rifà il login?

Perché avete bisogno diTimeCurrent() nell'indicatore?

Le serie temporali (time[], open[], ecc.) sono aggiornate?

 
Andrey Khatimlianskii:

TimeCurrent() in un indicatore chiamato da iCustom smette di funzionare quando si rifà il login?

A cosa serveTimeCurrent() nell'indicatore?

Le serie temporali (time[], open[], ecc.) sono aggiornate?

Tutto smette di funzionare, come se non ci fosse più un indicatore. TimeCurrent() solo per controllare, l'ultima volta per vedere. Niente (non time[], open[], ecc.) funziona perché l'indicatore non risponde più. Questa è l'ultima stampa dell'indicatore, non ce ne sono altre:

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
 
Per aggirare la limitazione di MQL4, dovete scrivere così.
#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:
Per aggirare la limitazione di MQL4, devo scriverlo in questo modo.

La religione è certamente una buona cosa (intendo esplicitamente questo.*), ma è meglio lasciarla per la chiesa.

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);
}

Penso che sarebbe più sintetico.

 
Vladimir Simakov:

La religione è certamente una buona cosa (intendo esplicitamente questo.*), ma è meglio lasciarla per la chiesa.

Penso che sarebbe più sintetico.

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
}
È sotto una A.
 
fxsaber:
Questo è sotto i 5 anni.

Chiedete agli sviluppatori: perché viene chiamato il metodo template della zona protetta?

UPD: è quello che il compilatore sostituisce nella chiamata, non B::f(const A*)

 

Aiuta a bypassare un bug del compilatore MQL4 che non è più in fase di sviluppo.

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>();
}

Stringa di ricerca: Oshibka 021.

 
fxsaber:

Aiuta ad aggirare un bug del compilatore MQL4 che non viene più sviluppato.

questo è il modo in cui MQL4 compila:

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:

Fondamentalmente compila anche senza typename T2

 
Igor Makanu:

Ecco come si compila in MQL4 :

UPD:

Fondamentalmente compila anche senza typename T2

Grazie!