efficiency in 2 different scenario of code structure

ezraluandre

Trader
Jun 17, 2020
20
0
17
29
Hi I have EA with code structure like this,

MQL4:
void OnTick()
{
   resetCounterVar(); //there's for loop
   CloseOrders(); //there's for loop
   UpdateAllOpenOrders(); //there's for loop
   SetSLTP(); //there's for loop  
   CheckPendOrder(); //there's for loop
   if(IsNewCandle() && pendingOrderCount<MaxPendingOrder)
      OpenOrders();  
  }

I want to make the for loop instead for every function into like this,

MQL4:
for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS) &&
         OrderSymbol() == Symbol()
        {
         resetCounterVar();
         CloseOrders();
         UpdateAllOpenOrders();
         SetSLTP();
         CheckPendOrder();
if(IsNewCandle() && pendingOrderCount<MaxPendingOrder)
  OpenOrders();

What I want to ask does the second code structure more efficient then the first one?
 
Last edited by a moderator:

ezraluandre

Trader
Jun 17, 2020
20
0
17
29
I've read the documentation for GetTickCount() and already tried it. I out it something like this,

MQL4:
OnTick()
{
   Uint start=GetTickCount();
   //This line is for my logic and all other code
   Uint time=GetTickCount()-start;
   Print("tick count: ", time);
}

On journal tab it returns value around 950-1050. What does it means? Does it means my code running from start to finish around 1 second? Does this value bad or not?
 

Enivid

Administrator
Staff member
Nov 30, 2008
16,994
1,020
144
Odessa
www.earnforex.com
I've read the documentation for GetTickCount() and already tried it. I out it something like this,

MQL4:
OnTick()
{
   Uint start=GetTickCount();
   //This line is for my logic and all other code
   Uint time=GetTickCount()-start;
   Print("tick count: ", time);
}

On journal tab it returns value around 950-1050. What does it means? Does it means my code running from start to finish around 1 second? Does this value bad or not?
Yes, that's 1 second. Whether it is good or bad is up to you to decide. My idea was that using GetTickCount() you can measure the speed of execution of your two proposed solutions and then choose the fastest one.