Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
cryptex23
268
cryptex23 2015.06.13 08:49 

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
28701
Alain Verleyen 2015.06.13 08:55  
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 2015.06.13 09:33  
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
28701
Alain Verleyen 2015.06.13 10:47  
https://www.mql4.com/search#!keyword=new%20bar&module=mql4_module_forum
/
To add comments, please log in or register