Download MetaTrader 5

looks iClose had old information on-board

To add comments, please log in or register
Bert
61
Bert  

Hi,

I made an expert and now run into a problem.

In my code I use:

if ((iClose(Pair,PERIOD_M1,1) < ArrayLevel[1][i]) && iClose(Pair,PERIOD_M1,0) >= ArrayLevel[1][i])

this if-statement was true and actually it couldn't be true.
I know this because of my logging: the arraylevel[1][i] => had the correct value
iClose(Pair,PERIOD_M1,0) had also the correct value because that was at the moment a trade was started (the result if this if-statement is true)

then (iClose(Pair,PERIOD_M1,1) must had an old value....is it possible that this bar wasn't updated and can I overcome this with RefreshRates() before I do the check?

it only looks if this is sometimes happened after the Init of the EA


Best regards

Marco vd Heijden
Moderator
5956
Marco vd Heijden  

Well then you try

Print(iClose(Pair,PERIOD_M1,1));
Bert
61
Bert  
Marco vd Heijden:

Well then you try

Well... I can't reproduce the error :( that's the problem. Not in backtesting, not in live.

So the question actually is: is RefreshRates() also updateing the Close[] bars info.... because iClose looks to the Close[] array.... if so then I also need to use RefreshRates() for using iClose...

Marco vd Heijden
Moderator
5956
Marco vd Heijden  

In that case you can try:

bool  SymbolInfoTick(
   string    symbol,     // symbol name
   MqlTick&  tick        // reference to a structure
   );

Please see: https://www.mql5.com/en/docs/marketinformation


Documentation on MQL5: Market Info
Documentation on MQL5: Market Info
  • www.mql5.com
Market Info - Reference on algorithmic/automated trading language for MetaTrader 5
Bert
61
Bert  
Marco vd Heijden:

In that case you can try:

Please see: https://www.mql5.com/en/docs/marketinformation


Thanks but that's not what I'm searching... I just need an
iClose(Pair,PERIOD_M1,1) and iClose(Pair,PERIOD_M1,0));

That is up-to-date!

Well I'm a little further. The issue is only there if I for the first time a chart open in an timeframe. Well then the bars are not uptodate yet...they still downloaded at that moment!

Well what I'm trying to do?

My EA is running in Symbol x
Then I need the value iclose for current bar and the bar before of PERIODE_M1 (that was never loaded before....) then I get unpredictable values!!


How to overcome this.... can I load the values in my Init and the wait some time before going on with the EA. So that my PERIODE_M1 is loaded. But when I know that the download is complete?!

whroeder1
16572
whroeder1  
Bert: Then I need the value iclose for current bar and the bar before of PERIODE_M1 (that was never loaded before....) then I get unpredictable values!!
Unless the chart is that specific pair/TF, you must handle 4066/4073 errors.
Bert
61
Bert  

Thanks for the hint!

oke... but do I understand it correctly that this errors appear on the opened chart?

my situation:

My EA is running on chart EURUSD

and during the program I also use an iClose("GBPUSD", PERIODE_M1,1)  ... If it is not in history it goes to download the info for GBPUSD.... How can I control this ?! Can I download it maybe on forehand, On INIT() maybe?

Marco vd Heijden
Moderator
5956
Marco vd Heijden  
Bert:
Thanks but that's not what I'm searching... I just need an

That is up-to-date!

Well I'm a little further. The issue is only there if I for the first time a chart open in an timeframe. Well then the bars are not uptodate yet...they still downloaded at that moment!

Well what I'm trying to do?

My EA is running in Symbol x
Then I need the value iclose for current bar and the bar before of PERIODE_M1 (that was never loaded before....) then I get unpredictable values!!


How to overcome this.... can I load the values in my Init and the wait some time before going on with the EA. So that my PERIODE_M1 is loaded. But when I know that the download is complete?!

They could just have the same value... and could also just return the error code when something goes wrong.

Like this:

//--- iClose  
   Print("iClose: ",DoubleToStr(iClose(Symbol(),PERIOD_M1,0)));

//--- MqlTick   
   MqlTick last_tick;
   if(SymbolInfoTick(Symbol(),last_tick))
     {
      Print("MqlTick: ",last_tick.bid);
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());

What do we get ?

As soon as the last bar (bar 0) closes it will shift to bar 1 and a new bar zero will be opened, this is why Close[0] usually has the value of Bid.

Remember that iClose returns:

If local history is empty (not loaded), function returns 0. 
To check errors, one has to call the GetLastError() function.

If the history is not accessible you can print the error to see the error code.

Bert
61
Bert  

Thanks Marco!

I think I now know what to do....combination of what you where saying and https://www.mql5.com/en/forum/158938 gives what I need!

Regards

Anyone know how to develop a multicurrency indicator ?
Anyone know how to develop a multicurrency indicator ?
  • 2016.04.21
  • www.mql5.com
Anyone know how to develop a multicurrency indicator ? I want to choose BETWEEN 1 to 10 different currencies and 5 bars for each currency...
To add comments, please log in or register