delete pending ( problem with order ticket )

 

Hi;

can you please help to fix,

it's can not delete pending:

//--- input expert parameters
/*
#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
*/
MqlTradeRequest trReq;
MqlTradeResult trRez;
.
.
int MAGIC=999;              // MAGIC number
long ORDER_TICKET;
.
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   MqlTick tick;
   if(!SymbolInfoTick(Symbol(),tick))
     {
      Print("Failed to get Symbol info!");
      return;
     }
/*   
   //--- make sure that the account is demo
   if(AccountInfoInteger(ACCOUNT_TRADE_MODE)==ACCOUNT_TRADE_MODE_REAL)
     {
      Alert("Script operation is not allowed on a live account!");
      return;
     }
*/         
   if(...) 
     {
      //DeleteAllOrdersByMagic();
      Delete_Pending_Orders_Sub_Program();
      Buy_Stop_Trade_Sub_Program();
     }
Comment("" 
       );
   return;
   }   
//--- End of OnTick()   
//*************************************************************     
//------------------------------------- Buy_Stop_Trade_Sub_Program --------------------------------
void Buy_Stop_Trade_Sub_Program()
    {
      trReq.symbol=Symbol();
      trReq.action=TRADE_ACTION_PENDING;                         // setting a pending order
      trReq.magic=MAGIC;
      trReq.deviation=10;                                        // deviation in 5 points
      trReq.price=max_high;  
      trReq.sl=0;         
      trReq.tp=0;           
      trReq.type=ORDER_TYPE_BUY_STOP;              
      trReq.volume=LOT;
      OrderSend(trReq,trRez);
    }
//---------------------------------------------------------------------------------------------------------------|

void Delete_Pending_Orders_Sub_Program()
    {
     for(int i=OrdersTotal()-1;i>=0;i--)
        {
         //trReq.symbol=Symbol();
         trReq.order=OrderGetTicket(0);
         trReq.action=TRADE_ACTION_REMOVE; 
         OrderSend(trReq,trRez);

        }
    }    
//+------------------------------------------------------------------+
 
TIMisthebest:

Hi;

can you please help to fix,

it's can not delete pending:

void Delete_Pending_Orders_Sub_Program()
    {
     for(int i=OrdersTotal()-1;i>=0;i--)
        {
         //trReq.symbol=Symbol();
         trReq.order=OrderGetTicket(i);
         trReq.action=TRADE_ACTION_REMOVE; 
         OrderSend(trReq,trRez);

        }
    }    
I strongly suggest you to check the returned value when you are using a function.
 
angevoyageur:
I strongly suggest you to check the returned value when you are using a function.

thank you ;

but also with this correction ; still does not work.

 
TIMisthebest:

thank you ;

but also with this correction ; still does not work.

So, what is the returned value of the OrderSend() function ? What is the value of trRez.retcode ?
Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Documentation on MQL5
 
angevoyageur:
So, what is the returned value of the OrderSend() function ? What is the value of trRez.retcode ?
sorry,

10009

TRADE_RETCODE_DONE

Request completed

 
angevoyageur:

You don't call your function ?

      //Delete_Pending_Orders_Sub_Program();

:) sorry

thank you.

 
TIMisthebest:
sorry,

10009

TRADE_RETCODE_DONE

Request completed

Please note that you have to initialize your structure, or you can also have some errors.

//---  Remove All Pending Orders

   MqlTradeRequest request={0};
   MqlTradeResult  result;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      request.order=OrderGetTicket(i);
      request.action=TRADE_ACTION_REMOVE;
      bool isOk=OrderSend(request,result);
      if(!isOk || !(result.retcode==10008 || result.retcode==10009))
        {
         Print("Remove pending order #",OrderGetTicket(i)," error #",result.retcode);
        }
     }
 
angevoyageur:
thank you.
 

hi mehrdad

void DeletePendingOrder(int magic, string sym ,ENUM_ORDER_TYPE type =ORDER_TYPE_BUY_LIMIT )
{
    
    long order_ticket;
    
    HistorySelect(0,TimeCurrent());
   
    for (int i=OrdersTotal()-1;i>=0;i--)
    if (order_ticket=OrderGetTicket(i))
 
    if (OrderGetInteger(ORDER_MAGIC) == magic && OrderGetString(ORDER_SYMBOL) == sym && OrderGetInteger(ORDER_TYPE) == type )
    {
        MqlTradeResult result;
        MqlTradeRequest request;
        request.order=order_ticket;
        request.action=TRADE_ACTION_REMOVE;
        OrderSend(request,result);
     
    }
    
 
kourosh1347:

hi kourosh:

thank you.