Mt4 End of support. - page 33

 
There's also a problem with the start time. Something doesn't register the start of the bar at the right time. I will figure it out later.
 
Nikolai Semko:

Peter, it's not working for me either.
Your programming style is strange. You may put all this stuff with all variables and loops from OnInit and OnTimer into one procedure. If someone wants to use it, because this code will get in the way. What if we have 20 or more procedures with the same contents? After all, it is implementedhere .


Peter is not looking for an easy way out...

 
Реter Konow:
There is also a problem with the start time. Something does not register the start of the bar at the right time. I will figure it out later.

The start of the bar is not always precisely timed.

Sometimes bars are skipped altogether.
 
Nikolai Semko:

Peter, it doesn't work for me either.
Your programming style is strange. You can put all these things with all variables and loops from OnInit and OnTimer into one procedure. If someone wants to use it, because this package will get in the way. What if there will be 20 or more procedures with the same contents? After all, this iswhere it's implemented.

On a minute it works, but it does not lock the beginning of the bar at the right time.

I haven't checked it on other timeframes, because it takes a long time to wait.

As for style, it doesn't matter now. We can take everything out of the timer and put it into a separate function. I was just thinking about the solution itself, not about future variants of its integration.

 
Vladimir Pastushak:

The start of the bar is not always exactly on time.

Yes, I noticed that, I'll fix it later.
 
Реter Konow:

I was thinking that if a person really has 600 instruments in the market overview and on every tick he checks the arrival of a new bar for each instrument and each timeframe, it may be expensive...

I myself don't trade, so I don't know exactly how many times this function should be called in practice.

The double loop on symbols and timeframes in the new bar function may increase the load only if the number of symbols and timeframes is very large and the function is called on each tick of hundreds of symbols. Perhaps Dmitry is right then.

I have shortened one loop in the function.

Just forget about it.

Here is an example of my class specifically for this action. Of course, it is not a masterpiece, but it is mine, and it understands me and works.

class CNewBar
{
protected:
  MqlRates newBarRates[];
public:
 bool newBar();
 bool newBar(ENUM_TIMEFRAMES timeframe, datetime & tOld);
};/********************************************************************/

bool CNewBar::newBar()
{
 static datetime timeLastBar;
  if(CopyRates(_Symbol, PERIOD_CURRENT, 0, 1, newBarRates) < 0)
   return(false);
  bool ret = timeLastBar != newBarRates[0].time;
   if(ret)
    timeLastBar = newBarRates[0].time;
   return(ret);
}/********************************************************************/

bool CNewBar::newBar(ENUM_TIMEFRAMES timeframe, datetime & tOld)
{
  if(CopyRates(_Symbol, timeframe, 0, 1, newBarRates) < 0)
   return(false);
    datetime tNew = newBarRates[0].time;
   bool ret = tOld != tNew;
   if(ret)
    tOld = tNew;
   return(ret);
}/********************************************************************/

If you want to determine only on the current TF, you have to call function without parameters.

Accordingly, if it is placed in .mqh, the library must be attached.

#include <путь_папка\имя_файла.mqh>
CNewBar newBar;

and it is called in OnTick().

if(newBar.newBar())
 Print("Новый бар на текущем ТФ");

If we need to define other TFs, we declare variables for each period and symbol, if necessary, at the level of global variables or static ones.

static datetime oldD1 = 0, oldH1 = 0;

if(newBar.newBar(PERIOD_H1, oldH1) && newBar.newBar(PERIOD_D1, oldD1)
 Print("Открылся новый день и новый час");

This approach is effective when working on the TF other than the required one and protects from problems with accidental switching of the chart on which the Expert Advisor works.

 
Nikolai Semko:

Peter, it doesn't work for me either. Although the algorithm is quite fast, it's a waste of time. But it's not working yet. No time to figure it out.
You have a strange programming style. You may put all this stuff with all variables and loops from OnInit and OnTimer into one procedure. If someone wants to use it, all this stuff will get in the way. What if there will be 20 or more procedures with the same contents? It is implementedhere .


Maybe you don't know what 'fast' means?

 
Alexey Viktorov:

Oh, spit it out...

Here's an example of my class specifically for this action. Of course, it's not a masterpiece, but it's mine and it works for me.

If you want to determine only on current TF, then function without parameters is called.

Accordingly, if it is placed in .mqh, the library must be connected.

and it is called in OnTick().

If I want to determine other TFs, then at the level of global variables or static ones, variables are declared for each period and symbol, if necessary.

This approach is effective when working on the TF other than the required one and protects from problems related to accidental switching of the chart on which the Expert Advisor operates.


You have no idea what idiocy you demonstrated, it's just absurd. But I will not show you exactly in what place, because you all are not interested in my opinion)))

 
Alexey Viktorov:

Oh, spit it out...

Here's an example of my class specifically for this action. Of course, it's not a masterpiece, but it's mine and it works for me.

If you want to determine only on current TF, then function without parameters is called.

Accordingly, if it is placed in .mqh, the library must be attached.

and it is called in OnTick().

If it is necessary to determine other TFs, then at the level of global variables or static variables are declared for each period and, if necessary, for the symbol.

This approach is effective when working on the TF other than the desired one and protects from problems with accidental switching of the chart on which the Expert Advisor works.

and what about other symbols? the task was to identify the change off on any symbol from market overview for anyf .

Regards.
 
Alexey Viktorov:

Oh, spit it out...

Here's an example of my class specifically for this action. Of course, it's not a masterpiece, but it's mine and it works for me.

If you want to determine only on current TF, then function without parameters is called.

Accordingly, if this is placed in .mqh then the library should be included

and it is called in OnTick().

If I want to determine other timeframes, then at the level of global variables or static variables are declared for each period and symbol, if necessary.

This approach is effective when working on the TF other than the desired one and protects from the problems with accidental switching of the chart on which the Expert Advisor works.

Does your solution work well? If well, then everything is fine.

How about the case of hundreds of instruments - won't there be any overlap?