Close_Orders - Universal function for closing positions and deleting orders
Brief description
One function for 14 trade management tasks in MetaTrader 5.
Closes positions and deletes pending orders with filtering by type, profitability and magic number.
What it can do
For positions (9 options):
All positions / only profitable / only losing positions
BUY only / SELL only
BUY profitable / BUY unprofitable
SELL profitable / SELL losing
For pending orders (5 options):
All pending orders / only Buy Stop / only Buy Limit
Only Sell Stop / only Sell Limit
How to use
// Call Examples:
Close_Orders("Position", "All", 0); // All positions
Close_Orders("Position", "Buy Profit", 123); // Profitable BUY with magik 123
Close_Orders("Order", "Buy Stop", 0); // All Buy Stop orders
Parameters:
p_o : " Position" or "Order" .
type_po : Filter type (see options above)
magicNumber : Magic (0 = all)
Advantages
Simplicity - one call instead of 14 functions
Flexibility - fine filtering of trades
Safety - proper handling of loops
Versatility - for Expert Advisors, scripts, indicators
Technical features
deviation = 5 - optimal price tolerance
Iteration from the end - safe deletion
Local variables - query isolation
Inclusion in project
#include <Close_Orders.mqh>
// Ready to use!