TIMES & SALES

 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
enum  ENUM_COPY_TICKS
  {
   TICKS_INFO=1,     // only/Bid è Ask 
   TICKS_TRADE=2,    // only/Last è Volume
   TICKS_ALL=-1,     // all ticks
  };
//--- input parameters
input int               ticks=1;       // number of requested tics
//--- parameters
input ENUM_COPY_TICKS   type=COPY_TICKS_TRADE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   Print(TICK_FLAG_BID," - tick has changed a Bid price");
   Print(TICK_FLAG_ASK,"  - a tick has changed an Ask price");
   Print(TICK_FLAG_LAST," - a tick has changed the last deal price");
   Print(TICK_FLAG_VOLUME," - a tick has changed a volume");
   Print(TICK_FLAG_BUY," - a tick is a result of a buy deal");
   Print(TICK_FLAG_SELL," - a tick is a result of a sell deal");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//--- the array that receives ticks
   MqlTick tick_array[];
    MqlTick t;
//--- requesting ticks
   int copied=CopyTicks(_Symbol,tick_array,type,0,ticks);
//--- if ticks are received, show the Bid and Ask values on the chart

      //--- generate the comment contents 
      /*
      string flags="";
         
         if((tick_array[0].flags  &TICK_FLAG_BID)==TICK_FLAG_BID)
            flags=" TICK_FLAG_BID "+id;
         if((tick_array[0].flags  &TICK_FLAG_ASK)==TICK_FLAG_ASK)
            flags+=" TICK_FLAG_ASK "+id;
         if((tick_array[0].flags  &TICK_FLAG_LAST)==TICK_FLAG_LAST)
            flags+=" TICK_FLAG_LAST "+id;
         if((tick_array[0].flags  &TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME)
            flags+=" TICK_FLAG_VOLUME "+id;
         if((tick_array[0].flags  &TICK_FLAG_BUY)==TICK_FLAG_BUY)
            flags+=" TICK_FLAG_BUY "+id;
         if((tick_array[0].flags  &TICK_FLAG_SELL)==TICK_FLAG_SELL)
            flags+=" TICK_FLAG_SELL "+id;
*/       
        if(copied>0){
        Print(tick_array[0].volume);
        }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Indicator  deinitialization function                             |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- 
   Comment("");
  }
//+------------------------------------------------------------------+
Olá,
Meu objetivo é exportar cada ordem executada à mercado, mas primeiro, preciso resolver este problema.
Não consigo plotar no console ou exportar sem que ocorra uma repetição das ordens executadas.
Alguém já passou por esse problema? Já testei muitas recomendações aqui e nada.


 

Olá Amigo, 
Existe uma discussão parecida no tópico abaixo,

https://www.mql5.com/en/forum/224693 

Caso tenha conseguido de alguma fora diferente, nos atualize por favor, ainda não tive o problema mas estou estudando passar a utilizar estas informações.

Abraço!

Problems receiving times & sales data in real time.
Problems receiving times & sales data in real time.
  • 2018.01.13
  • www.mql5.com
Friends, I'm having trouble trying to save times & trades data to a text file...
 

Olá Renato.

Uma hipótese ...

O evento OnCalculate() é disparado não somente a cada trade, mas também a cada modificação de preço BID ou ASK, mesmo não havendo trade.

Se o indicador estiver sendo iniciado com as entradas default, o filtro COPY_TICKS_TRADE será usado na função CopyTicks() fazendo com que esta selecione sempre o último tick em que houve trade, mesmo nos eventos acionados por ticks que não são de trade.

Então, por exemplo, se logo após o trade de volume 30 ocorrerem 2 eventos de modificação apenas de BID ou ASK (sem trade), esses dois eventos vão acionar o OnCalculate() uma segunda e uma terceira vez e, em todas as três vezes, o registro selecionado será o último trade executado, aquele de volume 30, fazendo com que o 30 seja impresso 3 vezes consecutivas.

Verifique se por acaso o problema é esse.

 
Renato Castro:


Oi Renato!

Use o SymbolInfoTick()

Assim ó :


...
 if(copied>0){

 MqlTick tick_array; 

if(SymbolInfoTick(Symbol(),tick_array)) 
     {    
        Print(tick_array.volume);
        }
}
}
...


depois Implementa um struct : tick_array[i] se quiser manter as informações no array!

mas desse jeito vai funcionar só que vai sumir cada vez que o meta atualizar, seja por falha no sinal ou por outro motivo.


depois posta o código aqui pra gente ver como ficou


Abs

Razão: