How to detect a New Bar in Muti Symbol ?

 

Before (Without Array ) :-

static datetime prevTime=0;
          datetime lastTime[1];
          if (CopyTime(_Symbol,_Period,0,1,lastTime)==1 && prevTime!=lastTime[0])
          {
               prevTime=lastTime[0];
              
               // ...
          }

It is working one symbol but I saw the MQL5 Forum Website  ( https://www.mql5.com/en/forum/5762/page2 )


After (With Array) :-

 static datetime prevTime[] ;
      
      ArrayResize(prevTime,NumOfSymbols);
      
      prevTime[i] = 0;
      
      datetime lastTime[1];
     
      int Copy_time[];
      
      ArrayResize(Copy_time,NumOfSymbols);
      
      Copy_time[i] = CopyTime(symbols[i], PERIOD_CURRENT,0, 1, lastTime);
      
      if( Copy_time[i] == 1 && prevTime[i] != lastTime[0] )
        {
         prevTime[i] = lastTime[0];
	//---------
        }

It doesn't work multi Trade to multiple symbol

Please solve this code 🙏

How to detect a new bar - How to detect new bars in MQ4?
How to detect a new bar - How to detect new bars in MQ4?
  • 2017.01.26
  • www.mql5.com
Bars would be a bad way to detect a new bar anyway. Why not simply using something like this : it should work in all cases (even when there is an error with copytime() it avoids a trap) i am just saying that when i used it years ago seriesinfointeger() was not really reliable
 
Vik 3001:

Before (Without Array ) :-

It is working one symbol but I saw the MQL5 Forum Website  ( https://www.mql5.com/en/forum/5762/page2 )


After (With Array) :-

It doesn't work multi Trade to multiple symbol

Please solve this code 🙏

Is your bar in another symbol closing in millisecond or second (which is not defined in PERIOD_CURRENT )? or Is your broker having time offsets in each symbol?

 
Why you set prevTime[i] to zero every time?
It's not clear where the loop is. Where the iteration is happening...
Please share your full source code.


 

I am sorry Sir/Madam..

It is working because I wronged this   "prevTime[i]" code 👇

 static datetime prevTime[] ;
      
      ArrayResize(prevTime,NumOfSymbols);
      
      prevTime[i] = 0;