Características del lenguaje mql5, sutilezas y técnicas - página 103

 
Nikolai Semko:

Sólo quería decir que tal vez el uso de user32.dll en lugar de kernel32.dll puede ser más rápido en la vinculación de dos terminales utilizando WinAPI, porque todas las implementaciones que he visto utilizan kernel32.dll.

Bueno, no veo ninguna razón por la que deba ser más rápido importar desde una biblioteca que desde otra.

Tal vez, no sea relevante en las versiones actuales de MQL, pero por lo que recuerdo del antiguo MQL4, estos costes eran bastante significativos y a veces incluso comparables a la velocidad de ejecución de las funciones.

 
fxsaber:

Sí.

Ahh... bueno, piensa que es mi capricho.

Simplemente me gusta la velocidad, porque quien es más rápido es el primero, y además hay menos carga en la CPU, lo que significa más recursos y tiempo para tomar una decisión.

 
fxsaber:
Implementación rápida multisímbolo OnTick

Cuando se ejecuta un Asesor Experto vacío utilizando un espía en 50 símbolos, los mensajes comienzan a acumularse en el registro:

2018.10.09 22:49:24.730 Spy (AUDNZD,W1) indicator is too slow, 4281 ms. rewrite the indicator, please

Si añado un filtro al indicador para la frecuencia de envío de eventos castum de 500 ms, los errores se vuelven menos frecuentes, pero no desaparecen.

¿Sólo soy yo?


Código EA:

#define  ForEach(index,array)   for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)

string Symbols[];

int OnInit()
{
   ArrayResize( Symbols, SymbolsTotal(true) );

   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);

      if( Symbols[i] != _Symbol )
         iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i );
   }
   return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   if( id == CHARTEVENT_CUSTOM )
      OnTickMS( Symbols[ (int)lparam ] );
}

void OnTick()
{
   CheckSignal( _Symbol );
}

void OnTickMS(const string &Symb)
{
   CheckSignal( Symb );
}

void CheckSignal(const string symbol)
{
   //Comment( symbol, ": ",
   //                   DoubleToString( SymbolInfoDouble( symbol, SYMBOL_BID ), 5 ), " / ",
   //                   DoubleToString( SymbolInfoDouble( symbol, SYMBOL_ASK ), 5 ) );
   return;
}


El Profiler muestra el 95% del tiempo de iCustom, OnChartEvent no tarda casi nada. El procesador (i5-3570) está cargado al 75%.

 
Andrey Khatimlianskii:

Cuando se ejecuta un EA vacío utilizando un espía en 50 herramientas, los mensajes comienzan a verterse en el registro:

¿Soy yo?

He detectado varios de estos errores al principio. No los conseguí más.

El perfilador muestra que el 95% del tiempo de iCustom, OnChartEvent no toma casi nada. La carga de la CPU (i5-3570) es del 75%.

En la versión de lanzamiento la CPU es de ~3%.

 
fxsaber:

Se han detectado algunos de estos errores al principio. No hay más choques.

La versión de lanzamiento tiene una CPU de ~3%.

Construí tanto el indicador como el Asesor Experto con "Optimize=1", los errores siguen ocurriendo.

 

Se ha añadido una segunda pausa al indicador:

int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
   static datetime prev = 0;
   if ( TimeCurrent() <= prev ) return(rates_total);
   prev = TimeCurrent();

Sigue habiendo errores.

 

Indicador

#property indicator_chart_window
#property indicator_plots 0

input long Chart = 0; // идентификатор графика-получателя события
input int  Index = 0;

ulong timer = GetMicrosecondCount();
//===================================================================
//| 
//+------------------------------------------------------------------
int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
   if( GetMicrosecondCount() - timer < 1 e6 ) return( rates_total );
   
   timer = GetMicrosecondCount();
   
   if( prev_calculated )
   {
      ResetLastError();
      
      if( EventChartCustom( Chart, 0, Index, 0, NULL ))
         Print( GetMicrosecondCount() - timer );
      else
         Print( (string)_LastError +" "+ (string)(GetMicrosecondCount() - timer) );
   }
   
   return( rates_total );
}
//+------------------------------------------------------------------

EA

#property strict
//+------------------------------------------------------------------
#define  ForEach(index,array)               for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)
//+------------------------------------------------------------------
string Symbols[];

//===================================================================
//| Expert initialization function
//+------------------------------------------------------------------
int OnInit()
{
   ArrayResize( Symbols, SymbolsTotal(true) );
   
   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);
      
      if( Symbols[i] != _Symbol )
         iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i ); // MQL5\Indicators\Spy.ex5
   }
   
   return(INIT_SUCCEEDED);
}
//===================================================================
//| Expert deinitialization function
//+------------------------------------------------------------------
void OnDeinit(const int reason)
{
   ArrayFree( Symbols );
}
//===================================================================
//| ChartEvent function
//+------------------------------------------------------------------
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
}
//===================================================================
//| Expert tick function
//+------------------------------------------------------------------
void OnTick()
{
}
//+------------------------------------------------------------------


Aumentar la pausa no ayuda mucho. Empieza a desmoronarse incluso a los 3 segundos.

Por razones desconocidas, en un momento dado, EventChartCustom deja de funcionar. Se detiene durante unos 3 segundos y genera el error 4001.

Archivos adjuntos:
20181010.log  276 kb
 
Oleksii Chepurnyi:

Indicador

EA


Aumentar la pausa no ayuda mucho. Comenzó a desmoronarse incluso a los 3 segundos.

Por alguna razón desconocida, en un momento dado, EventChartCustom deja de funcionar. Se detiene durante unos 3 segundos y da el error 4001.

Sí, ese parece ser el problema.

¿Alguien más lo tiene reproducido?

 
Andrey Khatimlianskii:

¿Sigue sonando?

No lo es.

#define  ForEach(index,array)   for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)

string Symbols[];
int Counter[];

int OnInit()
{
   ArrayResize(Counter, ArrayResize( Symbols, SymbolsTotal(true) ));   
   ArrayInitialize(Counter, 0);

   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);

      if( Symbols[i] != _Symbol )
         if (iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i ) == INVALID_HANDLE)
          Alert(Symbols[i]);
   }
   return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   static int Count = 0;
   
   if( id == CHARTEVENT_CUSTOM )
   {
     Counter[(int)lparam]++;
     
     string Str = (string)Count++ + "\nMarketWatch:";
     
     for (int i = 0; i < ArraySize(Counter); i++)
      Str += "\n" + (string)i + ": " + Symbols[i] + " " + (string)Counter[i];
      
     Comment(Str);
   }
}


Una hora de trabajo - vuelo es normal.

 
fxsaber:

No hay reproducción


Una hora de trabajo - vuelo normal.

¿Cuántos instrumentos hay en la revisión del mercado?

Razón de la queja: