Understanding OnTick()

 

Hello everyone,

I was little clarity on how OnTick()  works. I am trying to check if a new bar is forming 

void OnTick()
  {
//---
  int m_nLastBars=0;
  int m_bNewBar;
  int nBars=Bars(Symbol(),PERIOD_M15);
if(m_nLastBars!=nBars)
  {
   m_nLastBars=nBars;
   m_bNewBar=true;
   
//////run my logic hereafter
 
cryptex:

Hello everyone,

I was little clarity on how OnTick()  works. I am trying to check if a new bar is forming 

 

OnTick() is run each time a tick is received, what do you want to understand ?

To detect a new bar don't rely on Bars, always use time.

 
angevoyageur:

OnTick() is run each time a tick is received, what do you want to understand ?

To detect a new bar don't rely on Bars, always use time.

Could you throw some more light on this? I thought that by using bars i could avoid any mismatch in time. Can you kindly suggest how you propose on doing it using time?
 
https://www.mql4.com/search#!keyword=new%20bar&module=mql4_module_forum
Reason: