Mt4 End of support. - page 35

 
Реter Konow:

This variant of the function has no New_bar() function at all;

This is the most resource-saving option I've provided. In addition, it has another advantage: The new bar event is saved all the time the user code is executed on a timer or tick event.

Previously, you could only get this event once and the flag was cleared with New_bar(). The special function now clears the "event_new_bar[][]" array once a minute and is called only after the execution of custom code.

Custom functions can directly access the array and retrieve new bar event information all the time the code is executed on a timer or tick event.

This saves resources even more.

The last code also doesn't work, it took 7 minutes for the print to arrive

//+------------------------------------------------------------------+
//Пример использования событий нового бара в пользовательском функционал.
//Просто обращаемся к глобальному массиву "События_нового_бара[a1][a2]" напрямую
//и используем событие в наших торговых алгоритмах.
//+------------------------------------------------------------------+
void Моя_стратегия_торговли_на_новых_барах()
{
  for(int a1 = 0; a1 < Всех_символов; a1++)
   {
    string Этот_символ    = Символы[a1];
    //----------------------------------
    for(int a2 = 0; a2 < Всех_таймфреймов; a2++)
      {
       bool   Новый_бар      = События_нового_бара[a1][a2];
       int    Этот_таймфрейм = Таймфреймы[a2];
       //----------------------------------
       if(Новый_бар && Этот_символ == "EURUSD" && Этот_таймфрейм == PERIOD_M5)
         {
          Print("M5");
         }
       //---------------------------------- 
       if(Новый_бар && Этот_символ == "EURUSD" && Этот_таймфрейм == PERIOD_M1)
         {
          Print("M1");
         }
       //----------------------------------        
      }
   }
}
 
Vitaly Muzichenko:

The last code also doesn't work, it took 7 minutes for the print to arrive.

This function should be called from OnTick or from a timer.

There might be a small problem, but I haven't been able to locate it yet. Have a look at the code yourself and look for an error. It is as simple as a 3 kopecks. And with comments too.

If you don't understand it, ask. I have other things to do.

 
Реter Konow:

This variant of the function has no New_bar() function at all;

This is the most resource-saving option I've provided. In addition, it has another advantage: The new bar event is saved all the time the user code is executed on a timer or tick event.

Previously, you could only get this event once and the flag was cleared with New_bar(). The special function now clears the "event_new_bar[][]" array once a minute and is called only after the execution of custom code.

Custom functions can directly access the array and retrieve new bar event information all the time the code is executed on a timer or tick event.

Resources are saved even more.


I don't understand the humour. Why - the debugger does not understand Russian? Or it's just me who has such a glitch? Sees variables in Latin, but not in Cyrillic.

Peter, then how do you use the debugger, or don't you use it?

 

Anyone interested can look for a bug in the code.

The gist of the code:

1. Declare global arrays:

  • one-dimensional array for symbol names "Symbols[]"
  • one-dimensional array for timeframes "Timeframes[]"
  • A two-dimensional array where we write the current number of bars "Number_bars[][]".
  • two-dimensional array "New Bar Events[][]" where we will write the flags of the new bar event of each symbol and each timeframe. Those that are in arrays "Symbols[]" and "Timeframes[]". This array will be filled in the loop by symbols and timeframes on the timer event, once per minute. After that it will be cleared. In the interval between filling and clearing this array will be called by the user functionality and informed about the new bars.

2. On initialization, set the size of the array of symbols and write there the names of symbols from the market review.

3. Set the size of the first dimension of the "Number_bars[][]" array which equals to the number of symbols, and the second dimension equals the number of timeframes. This array is like a table. It will record the current number of bars of each symbol and each timeframe. The number is returned by the iBars function.

4. Set the size of the first dimension of "Events_new_bar[][]" array, which is equal to the number of symbols, and the second dimension equals the number of timeframes. This array is like a table. It will record the event flags of new bars of each symbol on each timeframe.

5. Inside the timer, we count down the minute and do a double (nested) loop on the symbols (which are in the array Symbols[]) and timeframes (which are in the array Timframes[]). We call the iBars function and get the current number of bars of each symbol and each timeframe from the Symbols and Timeframe arrays. First, we compare the current number of bars with the number already stored in the array. If these values are not equal, we set the flag of the new bar event in the "Event_new_bar[][]" array. We then write the current number of bars in place of the previous one.


The global array "events_new_bar[][]" is available at any point in the program and is automatically filled every minute, and also automatically cleared. During the period when the array is being filled, the user functionality receives fresh data about new bars. The array is then automatically cleared.


That's it.

 
Реter Konow:

This function should be called from OnTick or from a timer.

There might be some small problem, but I haven't been able to localise it yet. Have a look at the code yourself and look for an error. It is as simple as a 3 kopecks. And with comments on top of that.

If you don't understand it, just ask. I have other things to do.


professional answer

 
Nikolai Semko:

I don't understand the humour. What - the debugger doesn't understand Russian? Or is it just me who has such a glitch? It sees variables in Latin, but not in Cyrillic.

Peter, then how do you use the debugger, or you do not use it?

Nikolai, to my shame I have no idea how to use the debugger. I've never used it. ((
 
Galina Bobro:

professional response

And this is professional trolling.
 
Реter Konow:

This function should be called from OnTick or from a timer.

There might be some small problem, but I haven't been able to localise it yet. Have a look at the code yourself and look for an error. It is as simple as a 3 kopecks. And with comments too.

If you don't understand, just ask. I've got other things to do.

It is so complex and twisted that you cannot make it out.

I'm sorry, but it's also completely unreadable.

 
Vitaly Muzichenko:

It's so complicated and twisted that it's a mess.

I'm sorry, but it's also completely unreadable.

You know what they say about "you can't... don't torture..."? I think it's a good one.

 
Реter Konow:

You know the saying about "you can't... don't torture..."? I think it's a good one.

That's right, that's how you got on with the task conclusively, well, or I failed to get your solution right.

Reason: