Getting Deals Information - More than one deal at the same order.

To add comments, please log in or register
Guilherme Mendonca
610
Guilherme Mendonca  

Hello, 

I'm trying to get the balance return of the Deals History, but I'm having some issue, because, sometimes at the same order, there is more than one deal. 

I'm using the code below to organize in 02 arrays. One for time and other for the profit.

Is there any way when it is copying data if the time is equal, it will copy just one value?


   HistorySelect(0,TimeCurrent());
   uint     hist_total=HistoryDealsTotal();
   ulong    ticket=0;
   datetime ar_time[];
   double ar_pr[];
   datetime st=GlobalVariableGet(adder_lot);
   int c=0;
   for(uint i=0;i<hist_total;i++)
     {
      //--- try to get deals ticket 
      if((ticket=HistoryDealGetTicket(i))>0)
        {
         if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_IN)
            if(HistoryDealGetString(ticket,DEAL_SYMBOL)==_Symbol)
              {
               datetime time1=(datetime)HistoryDealGetInteger(ticket,DEAL_TIME);            
               long id=HistoryDealGetInteger(ticket,DEAL_POSITION_ID);

               Push(ar_time,time1);
               Push(ar_pr,CheckProfit(id));
              
               if(time1>=st)
                  c++;
              }
        }
     }
//+------------------------------------------------------------------+
template<typename T>
void Push(T &ar[],T v)
  {
   ArrayResize(ar,ArraySize(ar)+1);
   ar[ArraySize(ar)-1]=v;
  }
//+------------------------------------------------------------------+


This is the result I'm getting. 

ML 0 19:00:06.050 Kepha_2.0 (WING20,M5) [ 0] 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:10:09 2020.01.09 09:30:33 2020.01.08 15:59:59

QS 0 19:00:06.051 Kepha_2.0 (WING20,M5) [ 7] 2020.01.08 15:59:59 2020.01.08 15:59:59 2020.01.08 15:59:59 2020.01.08 13:30:04 2020.01.08 12:39:59 2020.01.08 12:39:59 2020.01.08 11:04:59

EK 0 19:00:06.051 Kepha_2.0 (WING20,M5) [14] 2020.01.08 11:04:59 2020.01.07 11:39:59 2020.01.07 10:50:00 2020.01.07 10:50:00 2020.01.07 10:15:00 2020.01.07 10:15:00 2020.01.07 10:15:00

JR 0 19:00:06.051 Kepha_2.0 (WING20,M5)   288   288   288   288  -176    40   -18   -18   -18   -18   -88    32    32    23    23  -128   336   336    64    64    64


You could check that there is 04 times for "2020.01.10 10:15:29".

So, I would like to copy just one time and ignore the other 03.

Alain Verleyen
38725
Alain Verleyen  
Guilherme Mendonca:

Hello, 

I'm trying to get the balance return of the Deals History, but I'm having some issue, because, sometimes at the same order, there is more than one deal. 

I'm using the code below to organize in 02 arrays. One for time and other for the profit.

Is there any way when it is copying data if the time is equal, it will copy just one value?



This is the result I'm getting. 

ML 0 19:00:06.050 Kepha_2.0 (WING20,M5) [ 0] 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:15:29 2020.01.10 10:10:09 2020.01.09 09:30:33 2020.01.08 15:59:59

QS 0 19:00:06.051 Kepha_2.0 (WING20,M5) [ 7] 2020.01.08 15:59:59 2020.01.08 15:59:59 2020.01.08 15:59:59 2020.01.08 13:30:04 2020.01.08 12:39:59 2020.01.08 12:39:59 2020.01.08 11:04:59

EK 0 19:00:06.051 Kepha_2.0 (WING20,M5) [14] 2020.01.08 11:04:59 2020.01.07 11:39:59 2020.01.07 10:50:00 2020.01.07 10:50:00 2020.01.07 10:15:00 2020.01.07 10:15:00 2020.01.07 10:15:00

JR 0 19:00:06.051 Kepha_2.0 (WING20,M5)   288   288   288   288  -176    40   -18   -18   -18   -18   -88    32    32    23    23  -128   336   336    64    64    64


You could check that there is 04 times for "2020.01.10 10:15:29".

So, I would like to copy just one time and ignore the other 03.

Why are you working with DEAL_ENTRY_IN, you should use DEAL_ENTRY_OUT (or IN_OUT if any) and use DEAL_PROFIT.

Guilherme Mendonca
610
Guilherme Mendonca  
Alain Verleyen:

Why are you working with DEAL_ENTRY_IN, you should use DEAL_ENTRY_OUT (or IN_OUT if any) and use DEAL_PROFIT.

I think it will not make diference because, sometimes DEAL_ENTRY_OUT also have more than 01 for the same order.




 I will solve it with some code lines, but all this issue could be solved if "MQL5 code" include some functions to work with POSITIONS instead DEALS.

Something like: "HistoryPositionGetDouble(position_ticket,POSITION_PROFIT);"

And the information received will be as same when you get Trading Account Report, like this:


All these problems happens because brazillian future market use the "REAL BOOK", so it is very similar to stock market and some times when you are buying/selling a share with a big lot, your order is executed with more than one price or executed with the same price, but diferent sellers. For each price or person it will receive a diferent deal, but in fact it was just one Position.

Alain Verleyen
38725
Alain Verleyen  
Guilherme Mendonca:

I think it will not make diference because, sometimes DEAL_ENTRY_OUT also have more than 01 for the same order.

Of course it will make a difference.

 I will solve it with some code lines, but all this issue could be solved if "MQL5 code" include some functions to work with POSITIONS instead DEALS.

Something like: "HistoryPositionGetDouble(position_ticket,POSITION_PROFIT);"

And the information received will be as same when you get Trading Account Report, like this:

Complaining is useless and waste of time, you have to deal with the actual API.

All these problems happens because brazillian future market use the "REAL BOOK", so it is very similar to stock market and some times when you are buying/selling a share with a big lot, your order is executed with more than one price or executed with the same price, but diferent sellers. For each price or person it will receive a diferent deal, but in fact it was just one Position.

I know that, and that's why I said you to work with deal out. You can NEVER expect a 1-by-1 relation between a deal and a position.

To add comments, please log in or register