iOpen returning 0.0 value on the hourly chart

Back to topics list To post a new topic, please log in or register
avatar
3
ianj1234567 2016.09.06 11:21
 

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 

avatar
735
honest_knave 2016.09.06 11:30 #
 

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.


avatar
1197
FMIC 2016.09.06 11:39 #
 

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.

avatar
3
ianj1234567 2016.09.06 14:28 #
 

   

 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;    
   }

 

avatar
12983
WHRoeder 2016.09.06 14:48 #
 
ianj1234567:

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 ?

  1. What part of
    FMIC: and use the SRC button to post it please.
    was unclear?
    Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. That's one solution. The other, when you get 4066 or 4073, is to sleep a second, clear the error, and retry.
avatar
1197
FMIC 2016.09.06 14:54 #
 
  1. As I have already stated, please use the SRC button (from toolbar) when adding code. So please edit your existing posts and correct them.
  2. 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://forum.mql4.com/72309/page2#1034408
avatar
3
ianj1234567 2016.09.06 15:35 #
 
Ok many thanks for you support, I'll check for 4066 and 4073 and add a delay loop.  - Post edited to show code.
Back to topics list  

To add comments, please log in or register