From MQL4 Documentation on iOpen:
Returned value
Open price value for the bar of specified symbol with timeframe and shift or 0 if error. To check errors, one has to call the GetLastError() function.
We are unable to help you if all you provide is the line:
PriceAtSevenOpen = iOpen(0,PERIOD_H1,0);
Without knowing the full context, we are unable to "decipher" your problem!
- Did you check for errors? Was there a 4066 or 4073 error?
- 7.01am? What timezone is that?
- What currency pair?
Only by knowing more about your code and your environment can we begin to address the problem. So provide more of the code context as well, and use the SRC button to post it please.
Ok thanks, I have added the error checking code (snippet as below ) and the error returned from code is 4066 - ERR_HISTORY_WILL_UPDATED - Requested history data is in updating state
Will a fix be to have the 1 hour chart active ?
if (!PrintedPriceAtOpen) { PriceAtSevenOpen = iOpen(0,PERIOD_H1,0); int ErrorCode = GetLastError(); if(ErrorCode != ERR_NO_ERROR) Print("There has been an error : ",ErrorCode); Print ("Price on the 1 Hour chart at ",DayStartTime ," a.m. Open is : ",PriceAtSevenOpen); PrintedPriceAtOpen = true; }
Ok thanks, I have added the error checking code (snippet as below ) and the error returned from code is 4066 - ERR_HISTORY_WILL_UPDATED - Requested history data is in updating state
Will a fix be to have the 1 hour chart active ?
What part of FMIC: and use the SRC button to post it please.was unclear?
Play videoPlease edit your post.
For large amounts of code, attach it.- That's one solution. The other, when you get 4066 or 4073, is to sleep a second, clear the error, and retry.
- As I have already stated, please use the SRC button (from toolbar) when adding code. So please edit your existing posts and correct them.
- When using Multi-time-frame (or Multi-currency) one has to check for 4066 and 4073 errors and then loop (with a delay) until the function correctly returns a value.
Please also read the following post/thread because it is relevant to your case: https://www.mql5.com/en/forum/158938/page2#1034408

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I have an EA which runs at 7.01 a.m. and it active on a 4 hour chart. I need to obtain the Open values on the hourly chart so am using the line of code
PriceAtSevenOpen = iOpen(0,PERIOD_H1,0);
When printing out the value "PriceAtSevenOpen" it intermittently returns a 0.0 or wrong value compared to looking at the hourly chart open value at 7.00.
I had hoped that be running the EA at 7.01 it would give enough time for the bar on the hourly chart to update and obtain the correct value
Can anyone help with this probelm
Many thanks
Ian