Close All Symbol Function

 

Hello, so i've created a close all symbol function but for some unknown reason it's producing alot of errors such as 'PositionClose' - undeclared identifier, ')' - unexpected token, 'PositionClose' - some operator expected, expression has no effect, '.' - struct or class type expected. I have inserted Ctrade trade above on the int OnInit().

Here is the code: 

void CloseThisSymbolAll()
  {
   int trade,orders;
   ulong ticket = PositionGetInteger(POSITION_TICKET);
   int orderType = PositionGetInteger(POSITION_TYPE) ;
   int orderPendingType = OrderGetInteger(ORDER_TYPE);
   string orderSymbol = PositionGetString(POSITION_SYMBOL);
   int orderPendingTicket = OrderGetInteger(ORDER_TICKET);
   
   for(trade=PositionsTotal()-1, orders=OrdersTotal()-1;trade>=0, orders>=0;trade--,orders--)
     {

      if(orderSymbol!=Symbol()) continue;
      if(orderSymbol==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         if(orderType==POSITION_TYPE_BUY) trade.PositionClose(ticket);
         if(orderType==POSITION_TYPE_SELL) trade.PositionClose(ticket);
         if(orderPendingType==ORDER_TYPE_BUY_LIMIT) trade.OrderDelete(orderPendingTicket);
         if(orderPendingType==ORDER_TYPE_SELL_LIMIT) trade.OrderDelete(orderPendingTicket);
         if(orderPendingType==ORDER_TYPE_BUY_STOP) trade.OrderDelete(orderPendingTicket);
         if(orderPendingType==ORDER_TYPE_SELL_STOP) trade.OrderDelete(orderPendingTicket);
         if(orderPendingType==ORDER_TYPE_BUY_STOP_LIMIT) trade.OrderDelete(orderPendingTicket);
         if(orderPendingType==ORDER_TYPE_SELL_STOP_LIMIT) trade.OrderDelete(orderPendingTicket);

        }
     }
  }
 
Jhon Bronxe:

Hello, so i've created a close all symbol function but for some unknown reason it's producing alot of errors such as 'PositionClose' - undeclared identifier, ')' - unexpected token, 'PositionClose' - some operator expected, expression has no effect, '.' - struct or class type expected. I have inserted Ctrade trade above on the int OnInit().

Here is the code: 

difficult to say what all your errors are as you have not included all the code, but the following line is gibberish so you should start there..

for(trade=PositionsTotal()-1, orders=OrdersTotal()-1;trade>=0, orders>=0;trade--,orders--)


https://www.mql5.com/en/docs/basis/operators/for

Documentation on MQL5: Language Basics / Operators / Loop Operator for
Documentation on MQL5: Language Basics / Operators / Loop Operator for
  • www.mql5.com
Loop Operator for - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5