avatar
Close All OPEN SELL Orders

teolee 1,309 26th Apr, 2020

CPP 1.24 KB
                                           
                         //+------------------------------------------------------------------+
//|                                            close-all-orders.mq4  |
//|                                  Copyright © 2005, Matias Romeo. |
//|                                       Custom Metatrader Systems. |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2005, Matias Romeo."
#property link      "mailto:matiasDOTromeoATgmail.com"

int start()
{
 int total = OrdersTotal();
 for(int i=total-1;i>=0;i--)
 {
   OrderSelect(i, SELECT_BY_POS);
   int type   = OrderType();

   bool result = false;

   switch(type)
   {
     //Close opened long positions
     //case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );


     //Close opened short positions
     case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );   
     break;


   }

   if(result == false)
   {
     //Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
     Sleep(0);
   }
 }

 return(0);
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data

Comments

Authentication required

You must log in to post a comment.

Log in
    There are no comments yet.