Position Selective Close MT4
- Utilidades
- Francisco Manuel Vicente Berardo
- Versión: 1.2
- Actualizado: 5 octubre 2024
The Position Selective Close is a multi-symbol multi-timeframe script used to close simultaneously various positions.
General Description
The Position Selective Close possesses three operation modes (Intersection, Union and All) that control the way as four position features (symbol, magic number, type and profit) are used. The modes, available through the Selection Mode input parameter, relate to the features, available through the “Select by Feature” and “Feature” input parameters, as follows:
- Intersection – contains only the positions whose features match all the features opted in the script.
- Union – contains all the positions whose features match at least a feature opted in the script.
- All – contains all the positions, regardless of any feature opted or not in the script.
The Intersection and Union operations in the script are similar to those in set theory, with the features selection and feature values representing the sets and set elements, respectively.
To use a given feature in the Intersection and Union modes, the respective “Select by Feature” needs to be activated, and the “Feature” needs to be selected with the intended value, except in the Select by Symbol case, whose value is always the chart’s symbol where the script is executed.
As an example of the script’s operation modes, consider four positions with different features and all the 3 modes with the same features setting (the symbol and type aren’t used):
Position 1 | Position 2 | Position 3 | Position 4 | Each mode | |
---|---|---|---|---|---|
Symbol | AUDUSD | USDJPY | GBPUSD | USDCAD | -------------- |
Magic | 14758 | 32978 | 67389 | 90336 | 32978 |
Type | Buy | Buy | Sell | Sell | -------------- |
Profit | Profit | No Profit | Profit | No Profit | No Profit |
Each mode determines the following positions to close: Intersection – position 2, Union – positions 2 and 4, and All – positions 1 to 4.
Input Parameters
- Selection Mode: Positions’ selection mode – Intersection/Union/All (see the General Description section above).
- Select by Symbol: Selection based on the position symbol.
- Select by Magic: Selection based on the position magic number.
- Select by Type: Selection based on the position type.
- Select by Profit: Selection based on the position profit / no profit.
- Magic: Position magic number.
- Type: Position type.
- Profit: Position profit / no profit.
- Deviation: Maximum allowed slippage from the requested price (pips).
Some of the available parameters accept values that lead to particular options.
- Select by Symbol, Select by Magic, Select by Type and Select by Profit: The “true” value at just one of these parameters means that the Intersection and Union modes coincide.
- Magic: A null value means positions opened manually or automatically with the 0-default value.
Displayed Information
The script possesses a few messages to inform the user about errors that might occur during its execution. The messages are shown through the Alert function (by a pop-up window), its content includes:
- The warning that an input parameter has been incorrectly set.
- The Trade Server Return Codes description.
- The symbol’s quotes (immediately) before the trade request’s formation, followed by the symbol’s quotes (immediately) after the trade server’s decision (only relevant to the programmer).
- The Runtime Errors description.
- The standard function in the include file where the runtime error was detected (only relevant to the programmer).
Note: Some elements of the list are displayed simultaneously (in the same text line): 2 and 3; 4 and 5.
Conclusion
The Position Selective Close is a helpful and effective tool regarding the manual closing of positions, especially when these reach a significant number, enabling a simple and intuitive selection of the positions to close.