Download MetaTrader 5

Understanding OnTick()

To add comments, please log in or register
cryptex23
268
cryptex23  

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
Alain Verleyen
Moderator
33486
Alain Verleyen  
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.

cryptex23
268
cryptex23  
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?
Alain Verleyen
Moderator
33486
Alain Verleyen  
https://www.mql4.com/search#!keyword=new%20bar&module=mql4_module_forum
To add comments, please log in or register