Scripts: CloseAllPositions

 

CloseAllPositions:

The script closes all open positions on the current account.

CloseAllPositions

Author: Nikolay Kositsin

 

scipt is not working --

 
Robert:

scipt is not working --

Try this version.

 

// An EA to close all pending orders


void OnTick()
  {
//---
 
 
    {
  
  int Welbeck=OrdersTotal();
    for(int i=0;i<Welbeck;i++)
     {
      ResetLastError();
      //--- copy into the cache, the order by its number in the list
         
         
         ulong tickett= OrderGetTicket(i);
        
         if(tickett>0)
         {
         
         if(mytrade.OrderDelete(tickett)) //--- Request successfully completed
        
        
                 {
                  Alert("An opened order has been successfully closed!!");
                
                 }
               else
                 {
                  Alert("The order close request could not be completed - error: ",


                       mytrade.ResultRetcodeDescription());

                 }
            
              
            }
            }
            }
  }



 

// An EA to close all pending orders


void OnTick()
  {
//---
 
 
    {
  
  int Welbeck=OrdersTotal();
    for(int i=0;i<Welbeck;i++)
     {
      ResetLastError();
      //--- copy into the cache, the order by its number in the list
         
         
         ulong tickett= OrderGetTicket(i);
        
         if(tickett>0)
         {
         
         if(mytrade.OrderDelete(tickett)) //--- Request successfully completed
        
        
                 {
                  Alert("An opened order has been successfully deleted !!");
                
                 }
               else
                 {
                  Alert("The order delete request could not be completed - error: ",


                       mytrade.ResultRetcodeDescription());

                 }
            
              
            }
            }
            }
  }

Reason: