I'm narrowed a logic issue down to return values from the iBarShift function. I'm looking for the offset to other bars (obviously) and it seems that iBarShift will return a positive value even when the bar doesn't exist and the exact param is set to true.
This isn't always happening, I'm getting -1 return values for some bars which don't exist.
I've attached some code which illustrates the problem. The hourly bar for 2007.01.01 06:00 doesn't exist on my hourly chart, yet I'm getting a return offset for bar 2006.12.29 22:00.
Can I get another pair of eyes to check my code to make sure I'm not doing something stupid? If you would be so kind, download the script and run it on an hourly chart, what do you get?
Here's what I get (read output from bottom to top):
This isn't always happening, I'm getting -1 return values for some bars which don't exist.
I've attached some code which illustrates the problem. The hourly bar for 2007.01.01 06:00 doesn't exist on my hourly chart, yet I'm getting a return offset for bar 2006.12.29 22:00.
Can I get another pair of eyes to check my code to make sure I'm not doing something stupid? If you would be so kind, download the script and run it on an hourly chart, what do you get?
PHP Code
int start() {
// Test timestamp, this bar should NOT exist in charts
datetime dtTimestamp = D'2007.01.01 06:00';
// The shift of the bar on the chart
// this SHOULD be -1 since the bar doesn't exist
// and the exact param = true
int iBarNumber = iBarShift(NULL,PERIOD_H1,dtTimestamp,true);
// Let's see what we get
Print("Looking for bar with timestamp ", TimeToStr(dtTimestamp));
if (iBarNumber == -1) {
Print("Bar not found.");
}
else {
Print("Bar supposedly found at shift ", iBarNumber);
Print("Bar at shift ", iBarNumber, " has timestamp of ", TimeToStr(iTime(NULL,PERIOD_H1,iBarNumber)));
}
return(0);
}
QuoteDisliked2007.01.07 23:32:38 test EURUSD,H1: Bar at shift 94 has timestamp of 2006.12.29 22:00
2007.01.07 23:32:38 test EURUSD,H1: Bar supposedly found at shift 94
2007.01.07 23:32:38 test EURUSD,H1: Looking for bar with timestamp 2007.01.01 06:00
Attached File(s)
test.mq4
< 1 KB
|
267 downloads