Mt4 End of support. - page 26

 

Anyone who likes my solution, write to me in person. I will refine it and give it away.

Good luck to everyone.

 
Реter Konow:

A symbol cycle, checking for a new bar opening when a quote arrives and so on can 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.

And you do it. Given that characters can change - after all, it is true when reading characters.

 
Artyom Trishkin:

Do it. Given that characters can change - because when you read the characters is true.


Well, what if I do? What do you say then? I'll tell you a secret: for me, this kind of task is a total child's play. Do you really think I can't do it? That's just naive...

 
Реter Konow:

Well, what if I do? What do you say then? I'll tell you a secret: for me, this kind of task is a total child's play. Do you really think I can't do it? That's just naive...

Well, do it already.

 
Vitaly Muzichenko:

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

No question. Hedge to save comparison of string operations, well, if customer is a maniac and will trade on all symbols simultaneously.

But it seems there is nowhere else to save operations and memory - everything is minimal

void OnTimer(){

   Alert(Fn_new_bar("EURUSD", PERIOD_D1)); }

//+------------------------------------------------------------------+

uint Sp_Adler32(string line){

   ulong s1 = 1;

   ulong s2 = 0;

   uint buflength=StringLen(line);

   uchar char_array[];

   ArrayResize(char_array, buflength,0);

   StringToCharArray(line, char_array, 0, -1, CP_ACP);

   for (uint n=0; n<buflength; n++){

      s1 = (s1 + char_array[n]) % 65521;

      s2 = (s2 + s1)     % 65521;}

   return ((s2 << 16) + s1);}

//+------------------------------------------------------------------+

bool Fn_new_bar(string symb, ENUM_TIMEFRAMES tf){

   static datetime st_time[]; 

   static uint     st_id[];

   

   //---- set

   datetime new_time = iTime(symb, tf, 0);     if(new_time==0) return(false); 

   uint     new_id   = Sp_Adler32(StringConcatenate(symb,EnumToString(tf))); 

   datetime old_time = 0; 

   uint     old_id   = 0;

   

   //---- find

   int size = ArraySize(st_time); 

   for(int i=0; i<size; i++){

      if(st_id[i]!=new_id) continue; 

      old_id   = st_id  [i]; 

      old_time = st_time[i];

      break;}

   

   //----add new element

   if(old_time==0){

      ArrayResize(st_time, size+1); st_time[size]=new_time;

      ArrayResize(st_id,   size+1); st_id  [size]=new_id; }

   

   //----

   return(old_time>0 && old_time<new_time);}


 
Реter Konow:

I apologise for the slight delay.

Here is the first version of the function. You can refine and develop it further. If you notice an error, please give your comments.


The point is not in OOP but in the fact that your code is linear, though you will probably never learn it...

 
Galina Bobro:

No problem. Hedge to save comparison of string operations, well, if the customer is a maniac and will trade on all characters simultaneously.

But it seems there is nowhere else to save operations and memory - everything is minimum.


Forum on trading, automated trading systems and strategy testing

Mt4 End Support.

Artyom Trishkin, 2017.09.10 23:21

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

   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:


Named wrong out of habit -bool Fn_new_bar(string symb, ENUM_TIMEFRAMES tf) is the right function.

 
Artyom Trishkin:

Well, do it now.


OK. Your solution only works on ticks. Mine is on a timer. Do you think my method of timing with bar appearances has a drawback. Okay. Let it be like this. I will add a check for the arrival of a quote before setting a new bar flag. I will add another parameter to the function - a symbol. The user will choose the symbol by which they want to receive the new bar event and send it to the function. The function will check the time of the last quote of this symbol. Then we will compare the time of the bar formal appearance and the time of quotation and set the event flag.

I have only just started to study this subject, but I do not see any difficulties.

 
Galina Bobro:

It's not about OOP, it's about your code being linear, although you may never know...

Linear, non-linear... Are you talking about opera in programming again?
Reason: