Features of the mql5 language, subtleties and tricks - page 103

 
Nikolai Semko:

Just wanted to say that maybe using user32.dll instead of kernel32.dll may be faster for linking two terminals using WinAPI, because all implementations I've seen use kernel32.dll.

No way, I don't see why one library should import (or work) faster than another.

Perhaps, in current versions of MQL it is not relevant anymore, but as far as I remember from the old MQL4, these costs were quite significant and sometimes comparable to the speed of execution of functions.

 
fxsaber:

Yes.

Ahh..., well, consider it my whim.

Just like speed, because who is faster comes first, as well as less load on CPU, and thus more resources and time to make a decision.

 
fxsaber:
Quick Implementation of Multisymbol OnTick

When working with an empty Expert Advisor, using a spy on 50 symbols, the log starts to be bombarded with messages:

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

If I add a filter to the indicator for the frequency of sending castum events of 500 ms, the errors become less frequent, but they do not disappear.

Is it only me?


EA code:

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


Profiler shows 95% of iCustom time, OnChartEvent takes almost nothing. The processor (i5-3570) is 75% loaded.

 
Andrey Khatimlianskii:

When an empty Expert Advisor is working, using a spy on 50 tools, messages start pouring into the log:

Is it just me?

I caught a few of these errors in the beginning. I did not get them further.

The profiler shows 95% of iCustom time, OnChartEvent takes almost nothing. CPU (i5-3570) load 75%.

In Release-version CPU is ~3%.

 
fxsaber:

Caught several of these errors in the beginning. No further errors.

In Release-version CPU ~3%.

I built both indicator and Expert Advisor with "Optimize=1", errors keep appearing.

 

I added a second pause to the indicator:

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

Errors remain.

 

Indicator

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

Expert Advisor

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


Increasing the pause does not help much. It starts crashing at 3 seconds.

For unknown reasons, at one point, EventChartCustom stops working. It stalls for about 3 seconds and generates error 4001.

Files:
20181010.log  276 kb
 
Oleksii Chepurnyi:

Indicator

Expert Advisor


Increasing the pause does not help much. It started crashing at 3 seconds.

For some unknown reason, at one point, EventChartCustom stops working. Stalls for about 3 seconds and gives an error 4001.

Yes, that seems to be the problem.

Does anybody else have it?

 
Andrey Khatimlianskii:

Is it still playing?

It's not.

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


An hour of work - flight normal.

 
fxsaber:

It does not play.


An hour of work - the flight is normal.

How many instruments in the market review?

Reason: