Close All Positions Only for Selected Chart
3 replies
Tomas Matejka
10 years ago #114928
To close all open position and orders only for EURUSD for example (not for all active charts in MT) you would need a custom function that contains Symbol check
void sqCloseAllOrdersForChart() {
for(int i=OrdersTotal()-1; i>=0; i--) {
if (OrderSelect(i,SELECT_BY_POS)==true) {
if((OrderType() == OP_BUY || OrderType() == OP_SELL) && Symbol() == OrderSymbol()) {
sqClosePositionAtMarket(-1);
} else if (Symbol() == OrderSymbol()) {
tmpRet = OrderDelete(OrderTicket());
}
}
}
}
Add this into EA Wizard / code / CustomFunctions.mq4 file. Then you can use it in Wizard as it is shown in example attached.
0
Jojo
10 years ago #136035
To close all open position and orders only for EURUSD for example (not for all active charts in MT) you would need a custom function that contains Symbol check
void sqCloseAllOrdersForChart() { for(int i=OrdersTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS)==true) { if((OrderType() == OP_BUY || OrderType() == OP_SELL) && Symbol() == OrderSymbol()) { sqClosePositionAtMarket(-1); } else if (Symbol() == OrderSymbol()) { tmpRet = OrderDelete(OrderTicket()); } } } }Add this into EA Wizard / code / CustomFunctions.mq4 file. Then you can use it in Wizard as it is shown in example attached.
Thank you Tomas, this answers many of my prayers!
0
Jojo
10 years ago #136037
Quick question: Do we create another folder into which to place this file (…/code/CustomFunctions)? or place it in the Code folder?
0
Tomas Matejka
10 years ago #136139
Open the existing EAW / code / CustomFunctions.mq4 and add this new function there
0
Viewing 3 replies - 1 through 3 (of 3 total)