Order History in MQL5

 

Hello,

 

does anyone have an idea how  how i can select an old order?

in my mind is, to check how long was the last order ago in the currency pair

 

as example, before i set an order, i will check out, if there was an order within the last 5 minutes.

 

does anyone have a code idea for me?

 

Amando 

 
https://www.mql5.com/en/articles/211
Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • 2011.02.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 

this anwer do not really help, 

i know the difference between position, order and deal

 

but how i can check, when the last position was closed?

 

amando 

 
amando:

this anwer do not really help, 

i know the difference between position, order and deal

 

but how i can check, when the last position was closed?

 

amando 

All what you need is explained in the article. Show your code please if you need help.
 

this is the code i use to check if was a deal within the last 5 minutes

 

         HistorySelect(PeriodSeconds(PERIOD_M5),TimeCurrent());   //--- Wählt die Periode aus PERIOD_M% = letzten 5 Minuten
         int deals = 0;
         deals=HistoryDealsTotal();  //--- get ticket of the deal with the last index in the list
        
         Print(deals);
    

 

default is the value 0, if there was an deal the value count up

 

why does the value never go back to 0? it counts always up

 

amando 

 
amando:

this is the code i use to check if was a deal within the last 5 minutes

 

 

default is the value 0, if there was an deal the value count up

 

why does the value never go back to 0? it counts always up

 

amando 

Check out my code i posted few days back. Im on mobile and not able to paste the code here
 

i checked it out but i dont find a solution

 

the only think i want, is a value 0 when there was no order within the last 5 minutes

 

i modified the code a little bit

 

      long   EntryType;
      ulong  Ticket;
      string DealSym;
      int DTS;
      int DTB;

      DTS = 0;
      DTB = 0;
      
      HistorySelect(0,TimeCurrent());

      for(int i=HistoryDealsTotal()-1; i>=0; i--)
        {
         Ticket    = HistoryDealGetTicket(i);
         DealSym   = HistoryDealGetString(Ticket, DEAL_SYMBOL);
         EntryType = HistoryDealGetInteger(Ticket, DEAL_ENTRY);
         
         if(DealSym==_Symbol && EntryType==DEAL_ENTRY_OUT)
           {
            if(HistoryDealGetInteger(Ticket,DEAL_TYPE)==DEAL_TYPE_BUY)
              {
               DTB+=1;
              }
           }

         if(HistoryDealGetInteger(Ticket,DEAL_TYPE)==DEAL_TYPE_SELL)
           {
            DTS+=1;
           }
        Print("OldOrder"," value: ",DTS,DTB);
        }

 but i didnt get any result

 

i get following value out, and this endless 

 2015.05.20 21:47:59 Core 3 2015.01.13 13:21:10   OldOrder value: 12

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:10   OldOrder value: 11

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:10   OldOrder value: 01

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 43

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 43

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 33

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 23

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 22

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 12

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 11

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 01

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 53

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 43

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 43

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 33

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 23

2015.05.20 21:47:59 Core 3 2015.01.13 13:21:09   OldOrder value: 22

 

amando 


 

You have first HistorySelect parameter wrong. Try this:

         HistorySelect(TimeCurrent()-PeriodSeconds(PERIOD_M5),TimeCurrent());   //--- Wählt die Periode aus PERIOD_M% = letzten 5 Minuten
         int deals = 0;
         deals=HistoryDealsTotal();  //--- get ticket of the deal with the last index in the list
        
         Print(deals);
 

Thanks Dr. Trader

Reason: