Questions from Beginners MQL5 MT5 MetaTrader 5 - page 245

 
forexman77:

In the script, I've done this:

time=0

SymbolInfoTick on Monday.

You can check it with this code:

void OnStart()
{
  double ask;
  uint start=GetTickCount();
  for(int i=0;i<1000000;i++)
  {
    ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  }
  uint time=GetTickCount()-start;
  Print("SymbolInfoDouble = ",time," ms");
  
  MqlTick tick;
  start=GetTickCount();
  for(int i=0;i<1000000;i++)
  {
    SymbolInfoTick(Symbol(),tick);
  }
  time=GetTickCount()-start;
  Print("SymbolInfoTick = ",time," ms");
}

But you need ticks per symbol.

 
Fleder:

You can check it with this code:

But you need ticks per symbol.

Yes,"SymbolInfoTick", no check today.

Tried it, it won't work until the ticks come in.

void OnStart()
  {
uint start=GetTickCount();
double iask=0;
MqlTick latest_price;       // Будет использоваться для текущих котировок  
if(!SymbolInfoTick(_Symbol,latest_price)){iask=latest_price.ask;}
Alert("iask=",iask);
uint time=GetTickCount()-start;
Alert("time=",time);  
  }
iask=0
 
forexman77:

Yes, SymbolInfoTick, no check today.

Tried it, until the ticks go off nothing will work.

iask=0

This function is too fast.

To measure the performance, you need to apply multiple calls in a loop with a large number of iterations and measure the total execution time.

 
barabashkakvn:
All the more interesting, there is an example code. We are waiting for the result.
 
forexman77:
Thank you. It will come in handy.
 

To check a new bar in the EA I used functions based on "CopyTime", "CopyRates", which I found on the forums. I came to the conclusion that their calculation takes a lot of time.

Here is the check data (it's noteworthy that indicator call takes 171 ms):

datetime New_Time[];//буффер для проверки нового бара
void OnStart()
  {
uint start=GetTickCount();
for(int i=0;i<1000000;i++)
{
static datetime t;//записываем старое время  
ArraySetAsSeries(New_Time,true);//направление индексации
CopyTime(_Symbol,_Period,0,1,New_Time);//копируем время нового бара
t=New_Time[0];   
}
uint time=GetTickCount()-start;
Print("New_Time = ",time," ms");
  }

MqlRates rates[]; 
void OnStart()
  {
datetime t;  
uint start=GetTickCount();
for(int i=0;i<1000000;i++)
{
ArraySetAsSeries(rates,true);
int copied=CopyRates(Symbol(),Period(),0,1,rates);  
t=rates[0].time; 
}
uint time=GetTickCount()-start;
Print("t = ",time," ms");
  }

And here I got an idea, what if I try something else. For example, "TimeCurrent".

Made the following code for optimization:

void OnStart()
  {
int t;
int s;  
uint start=GetTickCount();
for(int i=0;i<1000000;i++)
{

MqlDateTime m;
TimeCurrent(m);
t=m.min;
s=m.sec;
}
uint time=GetTickCount()-start;
Print("time = ",time," ms");    
  }

Did the following code for optimization in Expert Advisor:

static double ind1;//записываю значения
static double ind2;// значения
static double indsmall;//индикаторов
MqlDateTime m;
TimeCurrent(m);
int MIN=m.min;
int SEC=m.sec;
if (MIN==0 && SEC==0)//проверка только в начале часа
{
Здесь копирую значения индикатора из буфферов
}

Result in single run without checking for a new bar, when indicator values are received at each tick: 817,196 ms

With check of a new bar: 735 904 ms

The difference is not particularly impressive, there is some improvement, but it's not enough.

I get the indicator as follows:

int TSIHandle;   // хэндл индикатора  TSI
double TSI[]; // динамические массивы для хранения численных значений TSI

int OnInit()
  {
TSIHandle=iCustom(NULL,0,"Blau_TSI",q,r,s,u,PRICE_CLOSE);
if(TSIHandle<0){Alert("Ошибка при создании индикаторов - номер ошибки: ",GetLastError(),"!!");return(-1);}
ArraySetAsSeries(TSI,true);
   return(0);
  }

void OnDeinit(const int reason)
  {
//--- освобождаем хэндлы индикаторов
   IndicatorRelease(TSIHandle);
   ArrayFree(TSI);
  }

void OnTick()
  {
MqlDateTime m;
TimeCurrent(m);
int MIN=m.min;
int SEC=m.sec;
static double tsismall;

if (MIN==0 && SEC==0)
{
//--- копируем значения индикаторов из индикаторных буферов
   if(CopyBuffer(TSIHandle,0,0,3,TSI)<0)
     {
      Alert("Ошибка копирования буферов индикатора Moving Average - номер ошибки:",GetLastError(),"!!");
      return;
     }
tsismall=TSI[1];
}
}

I tried to put code with calls of handles in block where check of new bar occurs, error appears if I

if(TSIHandle<0){Alert("Ошибка при создании индикаторов - номер ошибки: ",GetLastError(),"!!");return(-1);}

I put return returns nothing, no error, but EA does not work.

I suppose the hendle call, if it is possible and in general all the main code except the static variable should be placed inside the conditional statement checking for a new bar.

If I'm not mistaken, I read somewhere that even if we call a handle but don't request an indicator in buffers, it is still calculated.

 
Can someone tell me how to make an indicator to output the results of the formula buffer[i] = (1.3747-(MarketInfo("EURUSD", MODE_BID))+0.8835-(MarketInfo("USDCHF", MODE_BID)))*10000;
 
rus-lot:
Who can suggest how to make an indicator that displays the results of a single formula buffer[i] = (1.3747-(MarketInfo("EURUSD", MODE_BID))+0.8835-(MarketInfo("USDCHF", MODE_BID)))*10000;

You need to write a custom indicator. To make the process easier - take one of the simplest indicators -iMa and rewrite a bit. Here is another topic, where it talks about MarketInfo. Write the code, ask, if something does not work.

 
What happened to the static variables? Updated the old build of the terminal today and now there are errors when compiling:

unresolved static variable
 
sgreen:
What happened to static variables? Updated the old build of the terminal today and now there are errors when compiling:

unresolved static variable

The static members-data of the class must now be placed:

//+------------------------------------------------------------------+
//| Класс "Анализатор текстов"                                       |
//+------------------------------------------------------------------+
class СParser
  {
public:
   static int        s_words;
   static int        s_symbols;
   //--- конструктор и деструктор
                     Parser(void);
                    ~Parser(void){};
  };
...
//--- инициализация статических членов класса Parser на глобальном уровне
int CParser::s_words=0;
int CParser::s_symbols=0;
Reason: