Mt4 End of support. - page 25

 
Artyom Trishkin:

You just need to write a function where the user asks: "is there a new bar on the M5?" and gets a yes/no answer.

For example:

Here is your function IsNewBar() and we will develop and twist/rotate it further with further extension of the task


It seems to me that this is not a good example to demonstrate the usefulness of OOP.
Here, for example, is a variant using only one function:

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
   IsNewBar(0,false); // режим сбора информации
   if(IsNewBar()) Print("Пришел новый бар текущего ТФ");  // режим считывания информации
   if(IsNewBar(PERIOD_H4)) Print("Пришел новый бар H4");  // режим считывания информации
   if(IsNewBar(PERIOD_D1)) Print("Пришел новый бар D1");  // режим считывания информации
   
  }
bool IsNewBar(ENUM_TIMEFRAMES tf=PERIOD_CURRENT,bool out=true)
  {
   static const ENUM_TIMEFRAMES TF[22]=
     {
      PERIOD_CURRENT,PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,
      PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,PERIOD_D1,PERIOD_W1,PERIOD_MN1
     };
   static bool newbar[22];
   static bool FirstTime=true;
   static int acb[22]; // array of current bars
   if(FirstTime)
     {
      for(int i=0;i<22;i++) acb[i]=Bars(Symbol(),TF[i]);
      FirstTime=false;
      return(false);
     }
   int curtf=0;
   while(TF[curtf]!=tf) curtf++;
   if(out) return (newbar[curtf]);
   for(int i=0;i<22;i++)
     {
      int CurBars=Bars(Symbol(),TF[i]);
      if(acb[i]<CurBars)
        {
         acb[i]=CurBars;
         newbar[i]=true;
        }
      else newbar[i]=false;
     }
   return(false);
  }

you can of course remove it fromOnTick and insert it intoOnTimer

 
Реter Konow:

About this question, I think you are wrong. Please check with Service Desk. Let them answer the question: whether new bars are formed in the platform regardless of the arrival of quotes, or not. If no, then on the event of a new bar check whether there was a quote on it. If it was, the new bar has been formed. We can do it this way. You don't need to change much.

Oh mama mia... Just read the information already. I'm very surprised you don't know that, and when they tell you about it, you have doubts too. I won't even look in the direction of Service Desk on such childish questions - they'll laugh you out of it. Then ask them yourself - you have a link to servicedesk in your profile.
 
Nikolai Semko:

It seems to me that this is not a good example to demonstrate the usefulness of OOP.
Here is, for instance, a variant using only one function:

you can, of course, remove it fromOnTick and insert it intoOnTimer

Didn't look at the logic, well let's assume that hypothetically it works correctly.

And by any random characters?

Imagine that the program uses a list of symbols from the Market Overview window, and the user can change the symbol sets at any time.

 
I personally did not see @Nikolai Semko' s OOP code.


Respectfully.

 

Artyom is a little bit behind on his question, but the question is this: write it in procedural style so that it works correctly

void OnTick()
 {
 
  if(IsNewBar("AUDCAD",PERIOD_H1)) {
   // задача №1
  }
 
  if(IsNewBar("GBPJPY",PERIOD_M15)) {
   // задача №2
  }
 
  if(IsNewBar("EURUSD",PERIOD_H4)) {
   // задача №3
  }

 }

// Функция "Новый бар"
bool IsNewBar(....) {
 здесь код, который нужно написать
}
 
Реter Konow:

Yes on a timer. A new bar appears without a quote. We are interested exactly in the event of bar appearance, while we can fix the quote in Optisk();

A bar will appear in any case.


Here we have the explanation of bars:

Time[i] bar open time is usually not the same as the tick arrival time. The opening time of a bar for any timeframe is always a multiple of the timeframe. Any first tick occurring within the timeframe is a bar forming one; if no tick has arrived within the timeframe, no bar will be formed within this timeframe either.

 
Vitaly Muzichenko:

Artyom didn't really cover the question, but the question is this: write it in procedural style, so that it works correctly

I wanted to gradually add tasks to make it fast, convenient, easy and simple for people to implement the task. To show later how it is easily done using OOP.

But the main rejector of OOP himself turned away from the solution of the problem :)

 
Artyom Trishkin:

I wanted to gradually add tasks to make it fast, convenient, easy and simple for people to implement the task. To show then how easy it is to do it with OOP.

But the main rejector of OOP himself has rejected the solution of the task :)

Yes I didn't exactly state it myself, I'll paraphrase:

Artem has not opened a little the question, and the question is this: to write in procedural style that it works correctly

Maybe he will come back and prove that it is very easy and simple

 
Vitaly Muzichenko:

I didn't really say it myself, so I'll rephrase it:

Artyom didn't really cover the question, and the question is this: write in procedural style, so that it works correctly

Maybe he will come back and prove that it is very easy and simple.

I had a goal of getting his procedural style code to work in such a loop in the end:

   ENUM_TIMEFRAMES array_timeframes[]=
      {
      PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M30,
      PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,PERIOD_D1,PERIOD_W1,PERIOD_MN1
      };
   int total=SymbolsTotal(true), total_tf=ArraySize(array_timeframes);
   for(int i=0; i<total; i++){
      string symbol_name=SymbolName(i,true);
      for(int j=0; j<total_tf; j++){
         if(IsNewBar(symbol_name,array_timeframes[j])){
            Print("Новый бар на ",symbol_name," ",EnumToString(array_timeframes[j]));
            }
         }
      }
 
Artyom Trishkin:

I had the goal that the end result would be that his procedural style code would work in such a loop:

Symbol loop, checking for a new bar opening on the arrival of a quote and so on, could easily be added to my solution. And what does OOP have to do with it?

You have chosen a wrong example. Think about something else at your leisure.

Reason: