I don't understand how to distinguish between position and order.

 

in this case I try to delete objects that have the same name as the position or order comment.
it works only for orders while for positions I don't understand how to do it.


void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {

    HistorySelectByPosition(request.position_by);
   
         ObjectDelete(ChartID(),HistoryOrderGetString( request.order ,ORDER_COMMENT));
         ObjectDelete(ChartID(),HistoryOrderGetString( request.order ,ORDER_COMMENT)+"A");
         ObjectDelete(ChartID(),HistoryOrderGetString( request.order ,ORDER_COMMENT)+"B");
         
    HistorySelectByPosition(trans.position_by);
    
         ObjectDelete(ChartID(),HistoryDealGetString( trans.order ,DEAL_COMMENT));
         ObjectDelete(ChartID(),HistoryDealGetString( trans.order ,DEAL_COMMENT)+"A");
         ObjectDelete(ChartID(),HistoryDealGetString( trans.order ,DEAL_COMMENT)+"B");

    }
 

A simple way to view it ...

  • Order — the request (current and history)
  • Deal — the action (history)
  • Position — the result (current)

Read the following article ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.