MQL5 - Search for the closest closed sales order

 

I have this function that checks the closest open sales order.

My current need is to search for the closest sell order that the order has already been opened and closed (same day).

double novaVendaValor = 0; 
   
      for(int i = PositionsTotal()-1; i>=0; i--)  
   
        { if(PositionGetSymbol(i) == simboloDoAtivo && PositionGetInteger(POSITION_MAGIC) == magicNum && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) 
   
               { if (novaVendaValor == 0) 
   
                      { novaVendaValor = PositionGetDouble(POSITION_PRICE_OPEN); } 
               }
        }    
 
Read the Help: Basic Principles . You must distinguish between concepts such as 'deal' and 'position'. If the position was closed, then you need to refer to the trading history and look for a deal with the 'DEAL_ENTRY_OUT' (or 'DEAL_ENTRY_INOUT') type
Basic Principles - Trading Operations - MetaTrader 5 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...