Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1264

 
Roman:

Can you please tell me how to measure the minimum sampling rate, one iteration of a while loop?
Trying this code, but I'm not sure I'm measuring correctly.


void OnStart()
{
   ulong time[]; 
   ulong t = 0;  
   int   i = 0;
   ArrayResize(time, 30);      
   ulong startTime=GetTickCount64();
   uint iterations=0;
   while(i < 30 && !_StopFlag )
   {
      //t = GetMicrosecondCount();
      //t = GetMicrosecondCount() - t;      
      iterations++;
      
      ArrayFill(time, i, 1, t);
      i++;   
   }
   if (iterations) {
      ulong endTime=GetTickCount64();
      ulong avgTime=(startTime-endTime)/iterations; // среднее время 1-й итерации
   }
   ArrayPrint(time);
}
 
Maxim Kuznetsov:

Ah, I get the point.
I wrote it a little differently.

void OnStart()
{   
   uint  iterations = 1;   
   ulong startTime  = GetMicrosecondCount();   
   
   while(iterations == 1 && !_StopFlag )
   {            
      iterations++;         
   }
   
   ulong endTime = GetMicrosecondCount() - startTime;
   
   Print(IntegerToString(fabs(endTime)));
}

It turns out to be 0 or 1 microsecond.
Below microseconds it cannot be checked.

 
Roman:

Ah, I get the point.
I wrote it a little differently.

It turns out to be 0 or 1 microsecond.
Below microseconds it is impossible to check.

It's better to count the number of iterations. Of course it will be less than a microsecond with today's CPU frequencies. For example, between ticks)

void OnStart()                                  // Спец. функция OnStart()
  {
   int i, Count;                             // Объявление переменных
   for (i=1; i<=5; i++)                      // Покажем для 5 тиков
     {
      Count=0;                               // Сброс счётчика
      while(RefreshRates()==false)           // До тех пор, пока..
        {                                   //..придёт новый тик
         Count = Count+1;                    // Счётчик итераций 
        }
      Alert("Тик ",i,", циклов ",Count);     // После каждого тика
     }
   return;                                   // Выход из start()
  }
//--------------------------------------------------------------------
 
Valeriy Yastremskiy:

It is better to count the number of iterations. Of course it will be less than a microsecond with today's CPU frequencies. For example between ticks)

Probably better, but that's not the point.
We have to go down to nanoseconds, so I think we should write a dll with its own functions of time checks.
I'm just curious about the discreteness of the loop.

 

How do I determine which order was closed last?

Or what was the profit on the last 5 orders closed?


OrdersHistoryTotal()-1 - returns the position of the order in the history with the maximum ticket.


If a trade with the ticket 100 closed, and one hour later, a trade with the ticket 99 closed, thenOrdersHistoryTotal()-1 will point to #100, but how can we obtain information about the #99 order?

---

The most stupid thing that comes to mind - to save history to an array, sort it by close time and read what I need from the array. But that's super sub-optimal.

 
Roman:

Probably better, but that's not the point.
If we need to go down to nanoseconds, I think we need to write a dll with its own time check functions.
I'm just curious about the sampling rate at which the loop cycles.

with the frequency of a free core multiplied by the number of free cores. 2 - 10 gigahertz should be somewhere, if there are no other tasks and the loop only counts. The speed depends on CPU and memory load, priority of external actions at the moment of loop execution, as well as on internal actions in loop. Besides, addition and assignment operations are faster than reading and writing to/from array as far as I understand.

 
Valeriy Yastremskiy:

with the free core frequency multiplied by the number of free cores. 2 - 10 gigahertz somewhere, if there are no other tasks and the loop only counts. Furthermore addition and assignment operations are faster than reading or writing to/from array.

Thank you. Got it.

 
Who can help write a trading robot?
 
paradisehell1:
Who can help write a trading robot?

of these robots, so many have already been written - I don't believe there isn't one you want.

 

Good Morning All!


Question: what is the easiest way to determine the high and low times of a bar?

Baropen/close time is not interesting.

On MT4.

Thank you!

Reason: