Tick database

Dominik Egert
1130
Dominik Egert  

Hello, 

I need some support in understanding the issue I am currently having.


My finding is either, i have an issue in my code, or the tick_volume given by the terminal has one tick to much on every period.

Please see screenshot attached. 

I am comparing the results from the Functions CopyTicksRange and CopyTicks. I am querying two consecutive periods and CopyTicks deliveres the same tick twice, as exit tick for the last period as well as entry tick for the new period.

But the counting of ticks is concurrent with the tick_volume variable given by the terminal. 

The results returned by CopyTicksRange is, as it seems the correct information. But this has one tick less than the tick_volume variable and the count returned by CopyTicks.

Is this a bug or am i doing something wrong here?


It is very hard to extract the corresponding code to make it run standalone, but anyways, here it is:

//+------------------------------------------------------------------+
//| OnTickVolume()                                                   |
//+------------------------------------------------------------------+
void OnTickVolume(const int index = -1)
{
    // Local init
    
    #ifndef IND_DISPLAY_EMPTY_VALUE
        const ENUM_TIMEFRAMES   local_tf        = data::wh_timeframe;
        const string            local_symbol    = data::wh_symbol;
    #else 
        const ENUM_TIMEFRAMES   local_tf        = fw_cfg::CustomTimeframe;
        const string            local_symbol    = fw_cfg::CustomSymbol;
    #endif

        const ulong             start_date      = ((index == -1) ? (TimeCurrent() - (TimeCurrent() % PeriodSeconds(local_tf))) : data::time[index]) * 1000;
        const int               count           = (int)((index == -1) ? 0x01 : data::tick_volume[index]);
        MqlTick                 ticks[];


    // Read ticks

        int retval = CopyTicksRange(local_symbol, ticks, COPY_TICKS_ALL, start_date, start_date + (PeriodSeconds(local_tf) * 1000) - 1);

        retval = CopyTicks(local_symbol, ticks, COPY_TICKS_ALL, start_date, count);

        retval = CopyTicksRange(local_symbol, ticks, COPY_TICKS_ALL, (data::time[index + 1] * 1000), (data::time[index + 1] * 1000) + (PeriodSeconds(local_tf) * 1000) - 1);

        retval = CopyTicks(local_symbol, ticks, COPY_TICKS_ALL, (data::time[index + 1] * 1000), (uint)data::tick_volume[index + 1]);

        
    // Return
    return;
}


And here is the output


Screenshot output


I removed the output code from the source file for easy reading.

Alain Verleyen
41237
Alain Verleyen  

You should provide a code that can be compiled.

How is data::tick_volume array filled ?

Is that on a live chart or backtest ? Which broker ?

Dominik Egert
1130
Dominik Egert  
Alain Verleyen:

You should provide a code that can be compiled.

How is data::tick_volume array filled ?

Is that on a live chart or backtest ? Which broker ?

Thank you for taking a look.

Here is an extract of the code.

//+------------------------------------------------------------------+
//| OnTickVolume()                                                   |
//+------------------------------------------------------------------+
void OnTickVolume_A(const int index = -1)
{
    // Local init
    
        const ENUM_TIMEFRAMES   local_tf        = Period();
        const string            local_symbol    = Symbol();
        const int               bar_start       = (Bars(local_symbol, local_tf) - index) * ((index >= NULL) & 0x01);
        const int               bar_cnt         = Bars(local_symbol, local_tf) - bar_start;
              long              _tick_volume[];
              CopyTickVolume(local_symbol, local_tf, bar_start, bar_cnt, _tick_volume); 
              datetime          _time[];
              CopyTime(local_symbol, local_tf, bar_start, bar_cnt, _time); 

        const ulong             start_date      = ((index == -1) ? (TimeCurrent() - (TimeCurrent() % PeriodSeconds(local_tf))) : _time[index]) * 1000;
        const int               count           = (int)((index == -1) ? 0x01 : _tick_volume[index]);
        MqlTick                 ticks[];

    // Read ticks

        int retval = CopyTicksRange(local_symbol, ticks, COPY_TICKS_ALL, start_date, start_date + (PeriodSeconds(local_tf) * 1000) - 1);

	// For testing
	if(index < NULL)
	{ return; }

        retval = CopyTicks(local_symbol, ticks, COPY_TICKS_ALL, start_date, count);

        retval = CopyTicksRange(local_symbol, ticks, COPY_TICKS_ALL, (_time[index + 1] * 1000), (_time[index + 1] * 1000) + (PeriodSeconds(local_tf) * 1000) - 1);

        retval = CopyTicks(local_symbol, ticks, COPY_TICKS_ALL, (_time[index + 1] * 1000), (uint)_tick_volume[index + 1]);

        
    // Return
    return;
}


THe original array data::tick_volume and data::time are fed by the input from OnCalcualte in an indicator environment. - If this code is used inside an EA, a special function mimicing the OnCalcualte will fill the array as sown in the code provided here.

The Broker is FXflat, a german Broker, High quality data provided by them.

The results are constructed in the Strategy-Tester, but show same on a Live (Demo-Account) behaviour.


I dont think its an issue with the provider, I think it is a faulty if-clause inside the terminal.

BTW: The code provided is currently untested, it compiles. I have not checked deeper into it.