High and Low of previous day not always correct

 

double High_pending = iHigh( Symbol(), PERIOD_D1, 1 );

double Low_pending = iLow( Symbol(), PERIOD_D1, 1 );

This problem might have been mentioned before but I wouldn't have a clue how to find that specific topic. I use the above statements to find the high and low of the previous day, regardless of the time frame the EA is on. Most of the time it works fine but sometimes I get the data from 2 days ago.

For instance, the EA was started this Monday morning at 08:33. The high returned the value of the Friday high. But the low returned the value of the Thursday low. So the High was correct but the Low was not. I have seen this problem twice and both on Mondays, but it does not always happen. I've seen it happen on both a demo and a live account. The first time I noticed it in time and removed the pending order, after which the EA place a new one at the correct price.

Has anyone experienced this as well?

 
Test for error 4066 after each call, (iHigh, iLow, etc), if you get an error 4066 repeat the call and test again, only move on when the error 4066 is no longer being generated.
 

Oh.. d*mn... had not thought about that at all. Thanks Raptor, it all seems very logical now.

 

After Raptor's post I was able to find this other post: https://www.mql5.com/en/forum/127460

Chipdude's observation number 5 is a bit disturbing. Apparently when you repeat the call to soon, you can get the situation where 4066 is not generated but the price data is still not correct.

Reason: