//+------------------------------------------------------------------+ //| close-all-orders.mq4 | //| Copyright © 2005, Matias Romeo. | //| Custom Metatrader Systems. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Matias Romeo." #property link "mailto:matiasDOTromeoATgmail.com" #property show_inputs #include <stdlib.mqh> #include <stderror.mqh> extern double TargetPrice=0; extern int Slippage=5; extern bool ClosePendingOrder=false; int start() { if(TargetPrice==0) return(0); int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = true; //Print(i, OrderTicket(), OrderType()); switch(type) { //Close opened long positions case OP_BUY : if(Bid>=TargetPrice) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage, Yellow); break; //Close opened short positions case OP_SELL : if(Ask>=TargetPrice) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage, Yellow); break; //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : if(ClosePendingOrder==TRUE) result = OrderDelete( OrderTicket() ); } if(result == false) { Print("Order " , OrderTicket() , " failed to close. Error:" , ErrorDescription(GetLastError()) ); //Sleep(3000); } } return(0); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
Other Features: