# Test a code with different starting week over a specified period

Hi all, I am trying to test an EA where it starts each week and see the different results I get. Here is the code (removed all code not related to that matter), it works fine for the first 54 passes and stopped on 1 January 2023. Any idea why?

I set the input NumberWeekTest in the Fast genetic from 0 until 100, with steps of 1.

Thanks

```input bool M5 = true;
input bool H1 = false;
input int NumberWeekTest = 4;

//-----------------------------------------------------------------------------------------------------------------------

long Num_Bars = 0;
datetime d1= D'2022.01.01 00:00';
datetime d2= D'2023.08.23 00:00';
long currentBars = Bars(_Symbol, _Period, d1, d2);
if (M5){
Num_Bars = 1400*NumberWeekTest;}
if (H1){
Num_Bars = 120*NumberWeekTest;}

if ( currentBars < Num_Bars) Print("");
else if ( currentBars >= Num_Bars){

Here in the mqh file you have various time functions: https://www.mql5.com/en/code/45287

I think you find what you need like one week is from BoW(TimeCurrent()) until BoW(TimeCurrent()) + FXOneWeek ...

Dealing with time (2) functions
• www.mql5.com
Calculate DST for USA, EUR, AUD and RUB and the offset time of the broker automatically from the 70's until 2030 - even in the Strategy Tester of MQ.

```    if (M5){
Num_Bars = 1400*NumberWeekTest;}
if (H1){
Num_Bars = 120*NumberWeekTest;}```

That every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)

Use iBarShift.

Carl Schreiber #:

Here in the mqh file you have various time functions: https://www.mql5.com/en/code/45287

I think you find what you need like one week is from BoW(TimeCurrent()) until BoW(TimeCurrent()) + FXOneWeek ...

Thank you!

William Roeder #:

That every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)

Use iBarShift.

Thank you!