Reply

Close All Positions Only for Selected Chart

3 replies

tomas262

Administrator, sq-ultimate, 674 replies.

Visit profile

5 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

Customer, bbp_participant, community, 50 replies.

Visit profile

5 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

Customer, bbp_participant, community, 50 replies.

Visit profile

5 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

tomas262

Administrator, sq-ultimate, 674 replies.

Visit profile

5 years ago #136139

Open the existing EAW / code / CustomFunctions.mq4 and add this new function there

0

Viewing 4 posts - 1 through 4 (of 4 total)