# Close Group

## Description

The Close Group function is a very powerful tool which allows the closing of multiple orders which can be filtered based on your parameters, it also has variety of closing methods so read the descriptions carefully. Depending on the closing method it won't execute immediately even if not inside another condition.

## Syntax

${\displaystyle fx=BT\_CLOSEGROUP(eaid,symbol,tradeOperation,magicStart,magicEnd,comment,lots,slippage,minProfitAccountCurrency,minProfitPips)}$

## Inputs

eaid

symbol
Forex pair for the order, such as EURUSD. Write it like this “EURUSD” and make sure the pair name matches exactly the name in MetaTrader. If this is empty it will execute the tradeOperation command on all pairs.

Pay close attention as each of these parameters act differently:

-2 = Close all orders.
-1 = Cancel trailing.
1 = Close sell orders.
2 = Delete buy limit pending orders.
3 = Delete sell limit pending orders.
4 = Delete buy stop pending orders.
5 = Delete sell stop pending orders.
10 = check total profit (set in profit in pip or account currency parameters) before closing BUY orders.
11 = check total profit (set in profit in pip or account currency parameters) before closing SELL orders.
20 = Trail group total profit (set trail and profit in pip or currency min profit parameters) before closing BUY orders.
21 = Trail group total profit (set trail and profit in pip or currency min profit parameters) before closing SELL orders.
30 = Check total lots in BUY orders and if 80% of lots profit and 20% or less in loss it will close both profitable and losing orders. You can set target profit in pip or currency min profit parameters.
31 = Check total lots in SELL orders and if 80% of lots profit and 20% or less in loss it will close both profitable and losing orders. You can set target profit in pip or currency min profit parameters.
40 = Same as 30 but works with trailing even if trailing was not set. You can specify trailing in its parameter, If you set trailing to 100 pips it will start when 80% of lots are in profit and price went up 100 pips then it will place the trail between the 80% line and 100 pips at 50 pips and trail from there. Might close earlier to preserve profit. Min profit parameters are used as trailing parameter for this.
41 = Same as 31 but works with trailing even if trailing was not set. You can specify trailing in its parameter, If you set trailing to 100 pips it will start when 80% of lots are in profit and price went up 100 pips then it will place the trail between the 80% line and 100 pips at 50 pips and trail from there. Might close earlier to preserve profit. Min profit parameters are used as trailing parameter for this.

magicStart
Lower bound of the magic to search for. Pass -1 to search for all magic numbers. If you use the search in magic number parameter this will limit tradeOperation actions only to the magic number group you want. This is required and cannot be empty.

magicEnd
Upper bound of the magic to search for. The value itself is not included. This is not required and can be empty.

comment
Optional comment to search for orders with same text. Leave empty to match all comments. If you use this it will limit tradeOperation parameters actions only to orders that has the text you look for. You can write up to 31 characters, no commas “,” are allowed as description for each order. This is useful for grouping orders or marking them in strategies. You can later search for what you wrote in full or in part in BT_OpenOrder function. This is not required and can be empty. Input ex.”M1Group".

lots
How many lots to close. Bear in mind if you do not match the order you want to close lot size and provided a smaller lot size than the order it will partially close, for example 1 lot order and you wrote here 0.01, then it will only close 0.01 lot and you will have 0.99 lots remain open. Pass 0 to close orders completely regardless of their variable size. Minimum is 0.01 lot. BEWARE, partial closing work with only the following tradeOperation commands -2,0,1,10,11 and if you set lot to 0 it works with all tradeOperation commands. Set lot size if all orders you target are the same size for other tradeOperation parameters.

slippage
Allowed difference (in pips not points) between requested price and market price when executing the order. If we say 3 pips slippage you accept to open an order anywhere between 3 pips above or below the price and 0 or no input mean you won't accept anything but the exact price. This is not required and can be empty.

minProfitAccountCurrency
This parameter acts as both a minimum profit target in cash or trailing goal. Check tradeOperation parameters for how each command see it. This is not required and can be empty.

minProfitPips
This parameter acts as both a minimum profit target in pips or trailing goal. Check tradeOperation parameters for how each command see it. This is not required and can be empty.