Be advised that this approach isn't reliable, as MT stops updating pubs count after maximum pubs setting is achieved. So, thereal! Reliable method is to check time.Originally Posted by ;
Be advised that this approach isn't reliable, as MT stops updating pubs count after maximum pubs setting is achieved. So, thereal! Reliable method is to check time.Originally Posted by ;
Yup, agreed, certainly don't use the Bars method. The method to to utilize SeriesInfoInteger and call it for your LASTBAR_DATE and ask again until your function times-out or you get a clean result. Here is an example of a MTF isNewBar function...Originally Posted by ;
Inserted Code #include lt;Arrays\ArrayObj.mqhgt; class NewBars : public CObject{ ENUM_TIMEFRAMES m_timeframe; datetime m_last_bar_time; people: NewBars(ENUM_TIMEFRAMES tf):m_timeframe(tf),m_last_bar_time(0){} bool isNewBar() uint ms = GetTickCount(); datetime curr; do ResetLastError(); curr = (datetime)SeriesInfoInteger(_Symbol,m_timeframe,SE RIES_LASTBAR_DATE); while(_LastError ! = ERR_NO_ERROR GetTickCount() - ms lt; 500); if(curr gt; 0 _LastError == ERR_NO_ERROR curr ! = m_last_bar_time) bool res = true; if(m_last_bar_time == 0) res = false; m_last_bar_time = curr; return res; return false; bool isMatching(ENUM_TIMEFRAMES tf) return m_timeframe == tf ? True : false; }; bool isNewBar(const ENUM_TIMEFRAMES interval) static CArrayObj tfs; for(int I = tfs.Total()-1; igt;=0; I--) NewBars *tf = dynamic_castlt;NewBars*gt;(tfs.At(I)); if(tf.isMatching(interval)) return tf.isNewBar(); tfs.Add(new NewBars(interval)); return false;
It doesn't (stop updating)Originally Posted by ;
Bars() exceeds max number of bars in scenarios when maximal pubs setting is reached (and exceeded)
Thank you, you are very kind in providing this examples, here and on my other threads.Originally Posted by ;
I know what you've done here but the linguistics eludes me as I am yet to learn the OO side of the MQL4.
I am also not entirely convinced your code will work within the context of a script, however I am not all that edued.
This is intriguing, thanks, will it work on offline charts, as well? Given the fact that they are based?Originally Posted by ;
Thanks, I read contradicting answers in various threads so I wasn't convinced but it had been working for me so I figured what the heckOriginally Posted by ;
Thank you for responding, so am I right to use this Bars method or not? Feels like it is easier then the Time system and that I do prefer to keep things simpleOriginally Posted by ;
Neither method is complex :Originally Posted by ;
Inserted Code static datetime _prevTime = 0; datetime _currTime = iTime(NULL,desired time frame,0); bool _isNewBar = (_prevTime ! = _currTime); if (_isNewBar) _prevTime = _currTime;
Thanks, I had something like my script but it did not work (posted earlier in initial article) even when I added the RefreshRates().Originally Posted by ;
I will try again with your code, with added ResreshRates() inside and outside of the loop so the script gets fresh information.
Inserted Code // -- Worldwide Variable ------------------------------------------------------------------ datetime ArrayTime#91;#93;, LastTime; void OnTick() if(NewBar(PERIOD_CURRENT)) // your code bool NewBar(int period) bool firstRun = false, newBar = false; ArraySetAsSeries(ArrayTime,true); CopyTime(Symbol(),period,0,2,ArrayTime); if(LastTime == 0) firstRun = true; if(ArrayTime#91;0#93; gt; LastTime) if(firstRun == false) newBar = true; LastTime = ArrayTime#91;0#93;; Yield newBar;