Hi, I am trying to properly use the isNewBar function based on time and I am getting an compile error when I use the code right after the onTick function is called.
I tried initializing with different constants and arrays but the program is working as expected and the remaining functions are being call on every new bar but on tick.
Any advice on how to use the time based onNewBar function?
The answer already exists here, just search for isNewBar (top right the lens) and copy the best solution for you.
Please remember that there is almost nothing that has not been programmed for MT5 (and MT4): Searching and copying is much faster than trying everything out yourself.
- An error which you don't state, nor post the code up to the line generating the error. There is nothing wrong with your posted MT4 code.
-
Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum?
The answer already exists here, just search for isNewBar (top right the lens) and copy the best solution for you.
Please remember that there is almost nothing that has not been programmed for MT5 (and MT4): Searching and copying is much faster than trying everything out yourself.
- An error which you don't state, nor post the code up to the line generating the error. There is nothing wrong with your posted MT4 code.
-
Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum?
I didn't know this was MT4 code, is there a MT5 variation of this code?
in XX5 there is no Time[0], instead, replace it with iTime(NULL,PERIOD_CURRENT,0)
But i am very sure that if you search the site for words like NewBar that there would be a few versions of working code that you can use for both 4/5.Compact version of NewBar()
//+------------------------------------------------------------------+ //| NewBar | //+------------------------------------------------------------------+ bool NewBar() { static datetime prevTime = iTime(_Symbol, PERIOD_CURRENT, 0); return (prevTime != (prevTime = iTime(_Symbol, PERIOD_CURRENT, 0))); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I am trying to properly use the isNewBar function based on time and I am getting an compile error when I use the code right after the onTick function is called.
I tried initializing with different constants and arrays but the program is working as expected and the remaining functions are being call on every new bar but on tick.
Any advice on how to use the time based onNewBar function?