ibarshift and currentTime

 
Hi, I am writing an expert advisor that works on the weekly chart. I am trying to find the first bar on the hourly chart that corresponds to each bar in the weekly chart. I call

weeklyBar = iBarShift(Symbol(), PERIOD_W1, TimeCurrent(), false);
Print ("This is bar number ", weeklyBar, " at time ", TimeToStr(TimeCurrent());

each time start function iterates. When I run the test I use the hourly chart period. I run the test from the beginning of 2006 but I always end up with weeklyBar being 0. If I manually enter a date instead of TimeCurrent() I get the proper answer. TimeCurrent() is suppose to be adjusted to the bar during a test correct? If so, why doesn't it work here.
 
shift=0;
weeklyStartHourBar = iBarShift(Symbol(), PERIOD_H1, iTime(Symbol(),PERIOD_W1,shift), false);

this gives you bar number for hourly bar for current week. iterate shift to specify weekly bar for which you need hourly bar number found.
 
irusoh1:
shift=0; weeklyStartHourBar = iBarShift(Symbol(), PERIOD_H1, iTime(Symbol(),PERIOD_W1,shift), false);

this gives you bar number for hourly bar for current week. iterate shift to specify weekly bar for which you need hourly bar number found.

How can I iterate over shift? I could just add one each time but then sometimes the bar is missing. How can I just get the exact time of the bar during the test?
currentTime solves that but it doenst seem to work for me.
 
I don't quite follow what you are saying. If weekly or hourly bar is missing then there is something wrong with your data. the exact time of the bar is in
Time[i] for the current chart. That's the time when the bar started.
 
I was asking how I could iterate over shift. Do I simply subtract one each time start is called? Then how do I find the initial value of shift? Is there any simple way to know which bar I am currently testing?


I need to go over all the bars during the test
 
Alright I have solved it. I didn't realize that while running the EA, the current bar its testing is 0. I thought 0 would be only the very last bar.
Reason: