how can close order with ticket?

 

Hi I try create EA. in my EA every open position ticket save in array and close with their ticket too. But i got some error and i do not know how to do it.

first: this is my open trade function. from my source for training  MTRequest get error. also i do not know how to get ticket after position open.

void OpenTrade(ENUM_ORDER_TYPE ENType,ENUM_SYMBOL_INFO_DOUBLE ESID,
               double Volume,double TP, double SL)
  {
   MqlTradeRequest MTRequest= {0}; // i got error from here
   MqlTradeResult MTResult;
   MTRequest.action = TRADE_ACTION_DEAL;
   MTRequest.type = ENType;
   MTRequest.symbol = _Symbol;

   MTRequest.type_filling = ORDER_FILLING_FOK;
   MTRequest.price = SymbolInfoDouble(_Symbol,ESID);
   if(ENType == ORDER_TYPE_BUY)
     {
      MTRequest.tp = SymbolInfoDouble(_Symbol,ESID) + (TP *_Point);
     }
   else
      if(ENType == ORDER_TYPE_SELL)
        {
         MTRequest.tp = SymbolInfoDouble(_Symbol,ESID) - (TP *_Point);
        }
   MTRequest.volume = Volume;
   MTRequest.deviation = 10;
   OrderSend(MTRequest,MTResult);

  }

second: this is my function for close all order with tickets. I use this link "https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradepositionclose", but the PositionClose method not working.

 for(int i = 0 ; i< 10 ; i++)
     {
      if(SellArray[i] != 0)
        {
         //close all sell with ticket
         
         PositionClose(SellArray[i],ULONG_MAX); // this method not work.
         SellArray[i] =0;
        }
     }
how to solve my problems? please help.
Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionClose
Documentation on MQL5: Standard Library / Trade Classes / CTrade / PositionClose
  • www.mql5.com
PositionClose(const string,ulong) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

one of my problem solve I use this for save ticket now:

ticket = MTResult.deal;

But still i can not close the position with ticket. i read the document again and i found i should add namespace "#include <Trade\Trade.mqh>" in my Expert. however I get the error "'PositionClose' - undeclared identifier    "

how can solve this?