I made an expert and now run into a problem.
In my code I use:
if ((iClose(Pair,PERIOD_M1,1) < ArrayLevel[i]) && iClose(Pair,PERIOD_M1,0) >= ArrayLevel[i])
this if-statement was true and actually it couldn't be true.I know this because of my logging: the arraylevel[i] => had the correct valueiClose(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
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...
In that case you can try:
string symbol, // symbol name
MqlTick& tick // reference to a structure
Please see: https://www.mql5.com/en/docs/marketinformation
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 xThen 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?!
Thanks for the hint!
oke... but do I understand it correctly that this errors appear on the opened chart?
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?
They could just have the same value... and could also just return the error code when something goes wrong.
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 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.
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!
Please enable the necessary setting in your browser, otherwise you will not be able to log in.