Large differences in historical prices when the referenced symbol is not on the main chart

 

I want to read the close prices of a pair that is not on the main chart. I have used

extern string ref_Symbol = "EURUSD";

and then (inside Start() and inside the loop)

PairQuote[i] = iClose(ref_Symbol, 0, i)

to read the close price i periods back.

The problem is that I get different prices, depending on whether the referenced symbol (in this case EURUSD) is on the main chart or not. For example, on 2017.12.5  04:15  I get two entirely different Close prices for EURUSD :
A) When EURUSD is on the main chart I get 1.1874
B) When GBPUSD is on the main chart I get a price between 1.1850  and 1.1853, depending on unknown reasons. That is difference of a 21 - 24 pips!

I noticed this yesterday. What I also noticed this morning is that when I first opened MT4 (the tabs were seemingly as I had left them since yesterday) the Close price of EURUSD on the above date, was magically the “correct” (?) one as in A above (1.1874), although GBPUSD was on the main chart! But then I switched to another tab and when I switched back to the first one, the price had changed again to 1.1850 (probably the wrong one) as in case B!

So, may I assume that there is something that has to do not only with which pair is on the main chart of the active tab, but also with switching between tabs and maybe with which pairs are open on the other tabs (?). I thought it might have to do with refreshing the chart but when I “Refreshed” it nothing changed. The “wrong” (?) close price of 1.1850 was still there.

This is very frustrating because we are not talking about a difference of just a couple of pips here (I have already read other threads regarding inconsistencies between charts and Market Watch, but this seems a different story). We are talking huge differences here, that might lead to entirely wrong analysis and subsequently wrong trading decisions in cases of strategies that are based on past prices of symbols that are not on the main chart. But I wonder if referencing past OHLC prices of a different symbol is completely inaccurate and thus dangerous, then what is the purpose of built-in functions like iClose(Symbol, TimeFrame, Shift)?
So, unless I am missing something technical and this is indeed an MQL- or broker-related issue it is quite serious.

Has anyone else noticed such behavior and huge differences? And do you have any idea of why and/or when such weird things might happen?
Thanks in advance.

 
mix1911: I want to read the close prices of a pair that is not on the main chart.
On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
 

Sorry but I do not understand. Error 4066 means “Requested history data is in updating state”. But I see the same wrong price for hours. So, I wonder: what kind of “updating state” is this?
Also, error 4073 means “No history data”.  So, how can I see any Close value (either right or wrong) on chart if there is no history data?
Finally, I read the thread where you sent me and tried to implement the suggested code. There was an error (missing parenthesis) and several warnings. I tried to correct it. But I saw no errors printed and the problem remains. Could you or someone else kindly elaborate on this problem and on any suggested solution?

 

I think I found the cause of the problem.
It must be the additional history from MetaQuotes, which I had downloaded a few days earlier.
I tried a new clean installation of MT4 and everything worked fine.
It seems to me that MT4 keeps a rather short recent history of the symbol on the main chart in memory (for speed), but for referenced symbols it reads data from the disk.
So, if the history on the disk comes from another source there might occur differences, since the symbol on the main chart has values from the current broker.

 
mix1911: error 4073 means “No history data”.  So, how can I see any Close value (either right or wrong) on chart if there is no history data?
You are seeing prices for the current chart's symbol and timeframe. What part of "Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors" was unclear? Unless x == y means x != y, a different symbol and or timeframe.
 

Forum on trading, automated trading systems and testing trading strategies

Large differences in historical prices when the referenced symbol is not on the main chart

whroeder1, 2018.01.26 14:37

You are seeing prices for the current chart's symbol and timeframe. What part of "Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors" was unclear? Unless x == y means x != y, a different symbol and or timeframe.

1) My problem was not with the prices of the current symbol. It was with the referenced symbol, for which I was seeing rubbish. Now I am seeing the correct prices, but this is because I re-installed cleanly using the broker's data only. I did explain both points quite clearly, I think.

2) I never said that the suggestion about handling errors "was unclear". Actually, I did check and there was no such error, exactly as I expected! And unless I do not understand the true meaning of these two specific errors, there could be no chance to find one in this case, for the reasons I also explained quite clearly. 

3) I do understand what "a different symbol and time frame" means. What I did not understand at the time I asked the question, and I think I understood later, is how MT4 handles history. And imo this handling, especially when combined with historical data from another broker/source, is the reason for such huge differences, which has nothing to do with errors 4066/4073, at least in my case. I may be wrong of course, but I will continue to believe in my explanation unless someone offers a more convincing one. If "No history data" has to do with missing historical prices, then a) such an error should be printed in my case, too -and it was not!-  and b) I should not be provided with any Close value at all (my indicator should have nothing to return), but it did return rubbish as I said! And it returned rubbish because that is what it read from the history on the HD.
So, what part of my question is unclear?

Reason: