Not able to close pending orders

 

Hey guys . I am learning to code and i decided to code a small EA that places two pending orders (buy stop and sell stop) at yesterday's high and low . I menaged to code the part that places two pending orders. Instead I have difficulties understanding why the second part , that is simply supposed to canel the oder order if one is triggered, is not working . From what I understand the ORDER_TYPE of an order changes when a DEAL is made... what am I getting wrong ?

I am using the standard libraries 

Thanks

David

   if((openposition==0)&&(openorders==0)&&(ask<high)&&(ask>low))
     {
      // Buy Stop
      if(trade.OrderOpen(names,ORDER_TYPE_BUY_STOP,LotsVolume,0,high,slbuystop,tpbuystop,0,0,NULL))
        {
         orderbuyticket  = trade.ResultOrder();
        }
      // Sell Stop
      if(trade.OrderOpen(names,ORDER_TYPE_SELL_STOP,LotsVolume,0,low,slsellstop,tpsellstop,0,0,NULL))
        {
         ordersellticket = trade.RequestOrder();
        }
     }
   if(orderinfo.Select(orderbuyticket))
     {
      if(orderinfo.Type() == ORDER_TYPE_BUY)
        {
         trade.OrderDelete(ordersellticket);
        }
     }
   if(orderinfo.Select(ordersellticket))
     {
      if(orderinfo.Type() == ORDER_TYPE_SELL)
        {
         trade.OrderDelete(orderbuyticket);
        }
     }                               
 
dadocoso :


A position is NOT an ORDER! The COrderInfo class works with PENDING orders, and the CPositionInfo class works with POSITIONS.

Do not confuse PENDING ORDER and POSITION.


Add:

Example - Calculate Positions and Pending Orders

How to start with MQL5
How to start with MQL5
  • 2020.12.19
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...