How to Code OrderDeletion on Specific Pair!! PLEASE HELP!!

 

How to Code OrderDeletion on Specific Pair!! PLEASE HELP!!

I am trying to code a break out EA that uses a BuyStop and a SellStop 1pip away from price. The problem is once one of the orders gets triggered I would like the other order to DELETE.

This is what I have so far:

      //Close All Other Orders();
   int pos_total=PositionsTotal();
   if(pos_total = 1)
     {
      (int i=ord_total-1;i>=0;i--)
      {
         ulong ticket=OrderGetTicket(i);
         if(OrderSelect(ticket) && OrderGetString(ORDER_SYMBOL)==Symbol())
           {
            CTrade *trade=new CTrade();
            trade.OrderDelete(ticket);
            delete trade;
           }
        }
     } 

But it instead closes one order before it even enters a position (PositionsTotal hits 1)

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Your code breaks if you have positions open on other symbols.
 
stevemac100 :

How to Code OrderDeletion on Specific Pair!! PLEASE HELP!!

I am trying to code a break out EA that uses a BuyStop and a SellStop 1pip away from price. The problem is once one of the orders gets triggered I would like the other order to DELETE.

This is what I have so far:

But it instead closes one order before it even enters a position (PositionsTotal hits 1)

Please insert the code using the button Code(I corrected your message). For reliability, you need to use the following algorithm: in OnTradeTransaction, catch the transaction TRADE_TRANSACTION_DEAL_ADD. If the transaction DEAL_ENTRY_IN generated the transaction and the symbol of the transaction and the magic number of the transaction match your settings, then you can start deleting pending orders.

Reason: