Download MetaTrader 5

Order History in MQL5

To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
amando
424
amando 2015.05.11 21:56 

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 

Alain Verleyen
Moderator
30707
Alain Verleyen 2015.05.12 08:53  
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.
amando
424
amando 2015.05.15 23:01  

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 

Alain Verleyen
Moderator
30707
Alain Verleyen 2015.05.16 10:54  
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.
amando
424
amando 2015.05.19 20:27  

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 

Dua Yong Rew
5422
Dua Yong Rew 2015.05.20 06:56  
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
amando
424
amando 2015.05.20 21:48  

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 


Dr.Trader
3783
Dr.Trader 2015.05.21 09:24  

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);
amando
424
amando 2015.05.21 10:02  

Thanks Dr. Trader

To add comments, please log in or register