Problems receiving times & sales data in real time.

 

Friends,


I'm having trouble trying to save times & trades data to a text file.

I am trying to save this data in real time, but always the last trades executed in the market are appearing repeated.

If I use the Print () function to display in the console the last volumes of executed orders, they appear in some cases repeated.

I'm writing the code as a custom indicator in the OnCalculate () function block.



//+------------------------------------------------------------------+
//| TickRequest.mq5 |
//| Copyright 2018, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property version "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---

MqlTick tick_array[]; //Ticks indexados em uma matriz de estruturas.
CopyTicks(Symbol(),tick_array,COPY_TICKS_TRADE,0,1); //Requisitando tick e indexando na matriz de estruturas.
ArraySetAsSeries(tick_array,true);//Tornando o index 0 o tick mais atual

MqlTick ticks = tick_array[0]; //Recebendo dados indexados na matriz e salvando em estrutura simples.
if(ticks.volume>=10){ // Filtando volume a ser exibido
Print(ticks.volume); //plotando volume no console
}


//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---

}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---

}
//+------------------------------------------------------------------+





 
 
renatocastro1:

Friends,


I'm having trouble trying to save times & trades data to a text file.

I am trying to save this data in real time, but always the last trades executed in the market are appearing repeated.

If I use the Print () function to display in the console the last volumes of executed orders, they appear in some cases repeated.

I'm writing the code as a custom indicator in the OnCalculate () function block.

Because you are running your code in OnCalculate() which is triggered for ALL ticks, while your code only show TRADE tick, the last one. Check the tick time to filter.

Or use SymblInfoTick() eventually, depends of your goal.

 
Alain Verleyen:

Porque você está executando o seu código em OnCalculate (), que é acionado para TODOS os tiques, enquanto o seu código mostra apenas TRADE tick, o último. Verifique o tempo de seleção para filtrar.

Ou use SymblInfoTick () eventualmente, depende do seu objetivo.



Alain Verleyen thank you for your answer,

My goal is to study &Quot;TRADE tick" in real time. Example: A sequence of trades of purchase with volume &Quot;x" that call my attention on tape reading. But the trades tick appear repeated in many cases exactly as commented. Guided Me to use CopyTickRange() and get 1 minute intervals, which would agree would receive without repetitions and in real time. SymblInfoTick () would solve this problem?

Thank you for your help.

 
renatocastro1:



Alain Verleyen thank you for your answer,

My goal is to study &Quot;TRADE tick" in real time. Example: A sequence of trades of purchase with volume &Quot;x" that call my attention on tape reading. But the trades tick appear repeated in many cases exactly as commented. Guided Me to use CopyTickRange() and get 1 minute intervals, which would agree would receive without repetitions and in real time. SymblInfoTick () would solve this problem?

Thank you for your help.

There is a repetition only because your code do it.

int OnCalculate(...)
{
//---

MqlTick tick_array[]; //Ticks indexados em uma matriz de estruturas.
CopyTicks(Symbol(),tick_array,COPY_TICKS_TRADE,0,1); //Requisitando tick e indexando na matriz de estruturas.

OnCalculate is run on ALL ticks, trade ticks AND all other ticks.

CopyTicks get the trade ticks, so you can have several "no trade" ticks between trade ticks. Until there is a new trade tick, the last trade tick will be repeated.

// NOT TESTED

static ulong msec=-1;
MqlTick tick_array[]; //Ticks indexados em uma matriz de estruturas.

if(CopyTicks(Symbol(),tick_array,COPY_TICKS_TRADE,msec+1,1)!=-1) //Requisitando tick e indexando na matriz de estruturas.
  {
   // check for error, always !
  }
else
  {
   msec=tick_array[0].time_msc;
   if(tick_array[0].volume>=10)
     { // Filtando volume a ser exibido
      Print(tick_array[0].volume); //plotando volume no console
     }
  }
//+------------------------------------------------------------------+
 
Alain Verleyen:

There is a repetition only because your code do it.

OnCalculate is run on ALL ticks, trade ticks AND all other ticks.

CopyTicks get the trade ticks, so you can have several "no trade" ticks between trade ticks. Until there is a new trade tick, the last trade tick will be repeated.

 
Please check with your broker weather are they subscribed to mt5 version 1375..
Time and sales data are only available to the latest version of MT5..