How detect an opened BUY-LIMIT or BUY-STOP order?

 

Hi!

I'm operating an strategy that opens BUY-LIMIT or BUY-STOP orders.

Due to my EA limits, I need to get the information about when these orders are effected and I tried the following code:

  if(HistoryDealSelect(trans.deal))
            {

                        deal_ticket =    HistoryDealGetInteger(trans.deal, DEAL_TICKET);
                        order_ticket =   HistoryDealGetInteger(trans.deal, DEAL_ORDER);
                        position_ticket = HistoryDealGetInteger(trans.deal, DEAL_POSITION_ID);
                        time = (datetime)HistoryDealGetInteger(trans.deal, DEAL_TIME);
                        type =           HistoryDealGetInteger(trans.deal, DEAL_TYPE);
                        entry =          HistoryDealGetInteger(trans.deal, DEAL_ENTRY);
                        symbol =         HistoryDealGetString(trans.deal, DEAL_SYMBOL);
                        volume =         HistoryDealGetDouble(trans.deal, DEAL_VOLUME);
                        price =          HistoryDealGetDouble(trans.deal, DEAL_PRICE);
                        profit =         HistoryDealGetDouble(trans.deal, DEAL_PROFIT);
                        swap =           HistoryDealGetDouble(trans.deal, DEAL_SWAP);
                        commission =     HistoryDealGetDouble(trans.deal, DEAL_COMMISSION);
                        magic =          HistoryDealGetInteger(trans.deal, DEAL_MAGIC);
                        reason =         HistoryDealGetInteger(trans.deal, DEAL_REASON);
                        comment =        HistoryDealGetString(trans.deal, DEAL_COMMENT);


                        int orderTYPE = HistoryOrderGetInteger(order_ticket,ORDER_TYPE);
			// It always returns "0"

                        int dealTYPE = HistoryOrderGetInteger(deal_ticket,ORDER_TYPE);
			// Also, it always returns "0"
                        
                        switch(orderTYPE)
                          {
                           case ORDER_TYPE_BUY_LIMIT:
                                Buy_Ticket_Limit = order_ticket;
                                break;
                                
                           case ORDER_TYPE_BUY_STOP:
                                Buy_Ticket_Stop = order_ticket;
                                break;
                                
                           case ORDER_TYPE_SELL_LIMIT:
                                Sell_Ticket_Limit = order_ticket;
                                break;
                                
                           case ORDER_TYPE_SELL_STOP:
                                Sell_Ticket_Stop = order_ticket;
                                break;

                           default:
                             break;
                          }
 }

I don't know if I really have a problem here, since every time I get the code as "0", which means a "BUY" order instead a BUY_LIMIT or BUY_STOP order.

So, is there any way I can get the specific code of these orders type, since I need to control them and not impact any other "BUY" (normal instant buy) orders?

I appreciate any help.

Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
 
AliceRioBR:

Hi!

I'm operating an strategy that opens BUY-LIMIT or BUY-STOP orders.

Due to my EA limits, I need to get the information about when these orders are effected and I tried the following code:

I don't know if I really have a problem here, since every time I get the code as "0", which means a "BUY" order instead a BUY_LIMIT or BUY_STOP order.

So, is there any way I can get the specific code of these orders type, since I need to control them and not impact any other "BUY" (normal instant buy) orders?

I appreciate any help.

As I understand the orders still exist, so there are no history orders.  Therefore call OrderGetInteger instead of HistoryOrderGetInteger. Furthermore, you must call OrderSelect before calling OrderGetInteger.

See https://www.mql5.com/en/docs/trading/orderselect

Also https://www.mql5.com/en/articles/211  may be helpful.
Documentation on MQL5: Trade Functions / OrderSelect
Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
OrderSelect - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Dr Matthias Hammelsbeck #:

As I understand the orders still exist, so there are no history orders.  Therefore call OrderGetInteger instead of HistoryOrderGetInteger. Furthermore, you must call OrderSelect before calling OrderGetInteger.

See https://www.mql5.com/en/docs/trading/orderselect

Also https://www.mql5.com/en/articles/211  may be helpful.

Thank you Dr Matthias, I'll try this in some days (after finish another part of code which is burning my brain).

  :D

Reason: