MQL4 - automated forex trading   /  

Forum

ibarshift and currentTime

Back to topics list To post a new topic, please log in or register

avatar
8
mmnoname 2007.01.27 02:37 
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.

article

Video interview with Rashid Umarov

The main conclusion is that it is insufficient to have a profitable strategy: it is necessary to strengthen its advantages and smooth its disadvantages. This is the point in money management: You should gain the largest profit from your approach, your Expert Advisor, your system with minimal risk and in maximal amounts, without being short of it. This is the most important thing, to my mind.


avatar
543
irusoh1 2007.01.27 06:33 
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.

avatar
8
mmnoname 2007.01.27 08:21 
irusoh1 wrote:
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.

avatar
543
irusoh1 2007.01.27 19:06 
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.

avatar
8
mmnoname 2007.01.27 19:51 
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

avatar
8
mmnoname 2007.01.27 21:52 
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.
Back to topics list  

To add comments, please log in or register