Download MetaTrader 5

How do we detect the beginning of a new bar/candle in MQL5 ?

To add comments, please log in or register
All activity at MQL5.community is clearly visible. Have a look at the Wall!
ukpipcatcher
10
ukpipcatcher 2010.01.12 20:38 

Hi MQL5 Folks

 

In MQL4 it was possible to detect the beginning of a new bar/candle by examining the Time[0] element

and looking for it to change. But how can I detect the beginning of a new bar in MQL5 as we do not have

a Time[] array available ?

 

Any suggestions  ?

 

Thanks

ukpipcatcher 

Paul
784
Paul 2010.01.13 05:16  
ukpipcatcher   :

Hi MQL5 Folks

 

In MQL4 it was possible to detect the beginning of a new bar/candle by examining the Time[0] element

and looking for it to change. But how can I detect the beginning of a new bar in MQL5 as we do not have

a Time[] array available ?

 

Any suggestions  ?

 

Thanks

ukpipcatcher 


Take a look at the MQL5=>MQL4 conversion functions listed here.  Time[0] doesn't exist, but iTime() is listed in mt4timeseries_2

I've always used Bars rather than Time[0], but the principle is exactly the same.  The following code in OnTick() will set m_bNewBar true for one tick.  This assumes that the code is in a class method and m_bNewBar and m_nLastBars are class members.  Alternatively, they could be declared globally, C-fashion.

int nBars=Bars(Symbol(),PERIOD_CURRENT);
if(m_nLastBars!=nBars)
  {
   m_nLastBars=nBars;
   m_bNewBar=true;
  }
else
  {
   m_bNewBar=false;
  }

Paul

http://paulsfxrandomwalk.blogspot.com/ 

Beta Testing of MetaTrader 5 Has Started! - MQL4 forum
  • www.mql5.com
Beta Testing of MetaTrader 5 Has Started! - MQL4 forum
To add comments, please log in or register