MQL5: CopyTickVolume() returns same value for H1,H4,D1 for volume of current uncompleted bar

 

Here's a test script that depicts this odd behavior.

The documentation says:

If you need to return value corresponding to the current uncompleted bar, you can use the first form of call specifying start_pos=0 and count=1.

Note: when I pull the volume for the first completed bar, i.e. START_POS = 1, the values look more reasonable.

Any thoughts?



#property copyright       "Copyright 2019, Anthony J. Garot"
#property link            "http://www.garot.com/trading/"
#property version         "1.00"
#property description     "Tests issue observed with CopyTickVolume()."
#property strict

// Time frames that interest me
const ENUM_TIMEFRAMES tfs[] = {
    //~ PERIOD_M15,
    //~ PERIOD_M30,
    PERIOD_H1,
    PERIOD_H4,
    PERIOD_D1,
    //~ PERIOD_W1,
    //~ PERIOD_MN1
};

// A few symbols
const string currencyPairs[] = {
    "EURUSD",        // major
    "GBPUSD",        // major
    "USDJPY",        // major
    "EURGBP",        // major
    "EURJPY",        // major
    "GBPJPY",        // major
    "USDCAD",        // major
    "CADCHF",        // major
    "USDCHF",        // major
    "CHFJPY",        // major
    "EURCHF",        // major
    "GBPCHF",        // major
    "CADJPY",        // major
    "EURCAD",        // major
    "GBPCAD",        // major
};

void OnStart()
{
    for ( int i = 0; i<ArraySize(currencyPairs); i++ )
    {
        for ( int j = 0; j<ArraySize(tfs); j++ )
        {
            GetVolume(currencyPairs[i], tfs[j]);
        }
    }
}

long GetVolume(const string symbol, const ENUM_TIMEFRAMES tf)
{
    const int START_POS = 0;        // Get the current uncompleted bar volume
    long volume_array[1];            // Only want one value

    // Get the volume for this symbol/period
    const int copied = CopyTickVolume(symbol, tf, START_POS, 1, volume_array);
    if ( copied == -1 )
    {
        PrintFormat("%s(): Error getting with CopyTickVolume()", __FUNCTION__);
        return false;
    }
    PrintFormat("CopyTickVolume(%s,%s) = [%d]", symbol, EnumToString(tf), volume_array[0]);

    return volume_array[0];
}

 

After switching to the first completed bar, then back to the current uncompleted bar, the duplicates have shifted, but they're still odd.

Consider EURCAD . . .


 
Anthony Garot: but they're still odd.
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 - MQL4 and MetaTrader 4 - MQL4 programming forum

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          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

 
whroeder1:
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 - MQL4 and MetaTrader 4 - MQL4 programming forum

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          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

Ah, of course. Now that you mention it, I realize this is what is missing.

Thank you.

Reason: