What is the best (standard) way to access the market data (High, Low, Open, Close, ...) of the other symbols?

 

Hi.

I am calculating some formula in Symbol1 which needs some data from Symbol2. 

For instance, think that the indicator is placed in "USDJPY" pair and this indicator calculates the following:

datetime        bar_time        =       iTime(NULL , 0 , i);
bool            exact           =       false; 
int             day_index       =       iBarShift(NULL , PERIOD_D1 , bar_time , exact);
if( iClose("AUDJPY",0,i ) != 0)
        value[i]        =       value[i] + ( iClose("AUDJPY",0,i) - iOpen("AUDJPY",PERIOD_D1,day_index) ) / iClose("AUDJPY",0,i) * 100;
else
        Print( "///////////////// Error: iClose of AUDJPY is zero!" )     ;

How can I do this?

Could I use  CopyOpen and CopyClose and get into open_array the history data of bar open prices for the "AUDJPY"-period pair in the specified quantity?

In other word, I want to be sure that the data of the other Symbol (in this case: "AUDJPY") are loaded completely and are available and accessible for calculations!

Please consider that I have done the above code and I can get the data for at least some last candles if I set max value of i (bar counter) to a number (for example, 20), but when I use the following code then the indicator shows wrong data on the screen:

int OnCalculate(const int rates_total,
                                                const int prev_calculated,
                                                const datetime &time[],
                                                const double &open[],
                                                const double &high[],
                                                const double &low[],
                                                const double &close[],
                                                const long &tick_volume[],
                                                const long &volume[],
                                                const int &spread[])
{
        int     i,limit;

        //--- preliminary calculations
        if(prev_calculated<10)
                limit = 0;
        else
                limit = prev_calculated - 1;

        //--- the main loop of calculations
        for( i = limit ; i < rates_total && !IsStopped() ; i++ )
        {
                //main code here.
        }
        return(rates_total);
}

Please note that I do not have any periodic calculations and period constants (like Moving Averages) and I want the indicator calculates the formula for all candles in the chart!

I also use the following code as OnInit:

int OnInit()
{
        //--- indicator buffers mapping
        SetIndexBuffer(0, value, INDICATOR_DATA);
        
        ArraySetAsSeries(value,true); 
        
        return(INIT_SUCCEEDED);
}

Thanks for your help.

 
On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 № 26

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero the first call.

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum