This usually happens when time period (from-to) is changed in the tester. If I recompile
after changing the dates - then it is fine again, but as soon as I change the from-to
dates the reappears. Setting the values from the Inputs tab does not solve the
problem.
irusoh1 wrote: the easiest way to check for new bar: ... if(bartime!=Time[0])I agree that this is much simpler (although it doesn't let you check for new candle within the first X seconds of it like my code does). I will try using this as a workaround to see if it can solve my immediate problem, thank you.
However my main purpose here was to report a condition which very much looks like a MT4 bug to me. I was hoping to get some response from somebody from MetaQuotes Software telling me whether they agree that this is a bug and if yes when will it be fixed.
This is why I think it is a bug - look at the debug message printed in the Journal by my code:
2007.02.17 04:33:13 2006.10.01 20:00 SeriesAnalysisLib GBPUSD,H4: IsCandleStart returninig TRUE: iPeriodStartTime(1171656000)=2007.02.16 20:00:00 iCurrTime(1159732800)=2006.10.01 20:00:00 iSecondsAllowed=1
The tester knows that the current time (current simulated time) is 2006.10.01 20:00 - because of the date stamp in the beginning of the printed line. This is also confirmed by the call to TimeCurrent (printed in BLUE). However - and this is the bug! - Time[0] for the same period returns 2007.02.16 20:00:00?!?, which is bs.
Somebody from MetaQuotes please tell me you will fix this ASAP...
Put your code
into include-file (i.e. /experts/my_include.mqh) , add line #include <my_include. mqh> and try again.
bool IsCandleStart(int iSecondsAllowed) { static datetime iPeriodStartTime=0, iPeriodEndTime=0; static datetime iCurrTime = 0; iCurrTime = TimeCurrent(); if( iCurrTime > iPeriodEndTime ) { iPeriodStartTime = Time[0]; iPeriodEndTime = Time[0]+Period()*60-1; Print("@CandleStart: ", TimeToStr( iPeriodStartTime, TIME_SECONDS ) ); return (true); // crossing into new candle is always a candle start } if(iCurrTime <= (iPeriodStartTime+iSecondsAllowed)) { Print("IsCandleStart returninig TRUE: ", "iPeriodStartTime(", iPeriodStartTime, ")=", TimeToStr( iPeriodStartTime, TIME_DATE|TIME_SECONDS ), " iCurrTime(",iCurrTime, ")=", TimeToStr( iCurrTime, TIME_DATE|TIME_SECONDS ), " iSecondsAllowed=",iSecondsAllowed ); } return(iCurrTime <= (iPeriodStartTime+iSecondsAllowed)); } //+------------------------------------------------------------------+
into include-file (i.e. /experts/my_include.mqh) , add line #include <my_include. mqh> and try again.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
, when tested in the tester, with from-to dates equal to 01.Oct to 01.Nov, generates output like this:
2007.02.17 04:33:13 2006.10.01 20:00 SeriesAnalysisLib GBPUSD, H4: IsCandleStart returninig TRUE: iPeriodStartTime(1171656000)=2007.02.16 20:00:00 iCurrTime(1159732800)=2006.10.01 20:00:00 iSecondsAllowed=1
2007.02.17 04:33:13 2006.10.01 20:00 SeriesAnalysisLib GBPUSD, H4: IsCandleStart returninig TRUE: iPeriodStartTime(1171656000)=2007.02.16 20:00:00 iCurrTime(1159732800)=2006. 10.01 20:00:00 iSecondsAllowed=1
2007.02.17 04:33:13 2006.10.01 20:00 SeriesAnalysisLib GBPUSD, H4: IsCandleStart returninig TRUE: iPeriodStartTime(1171656000)=2007.02.16 20:00:00 iCurrTime(1159732800)=2006. 10.01 20:00:00 iSecondsAllowed=1
How can this be correct? TimeCurrent() and Time[0] should be the same at the beginning of each candle (are at least very close) in any case 16.Feb.2006 has nothing to do with my Oct-Nov test. To get rid of this problem I have to recompile and then set the inputs again.
Here are some screenshots