Exp4 Close Minus by Plus
Closing unprofitable positions by searching and closing profitable positions
- This assistant looks for, among all positions, in the terminal the most unprofitable position.
- Further, by searching for the remaining profitable positions, he calculates a series of positions that can cover the loss when the profit of one or more positions is greater than the loss of another position.
- If a set of such positions was found, then the adviser closes them.
- A series of positions can consist of absolutely any position. Their maximum number is adjustable in the advisor settings.
- You can also specify the minimum loss for the search and additional profit for closing.
You can test the Expert Advisor in the strategy tester and trade with our EAPADPRO toolbar in visual mode!
- TypeOfUnitToClose - type of profit and loss calculations. In USD or in points.
- MinLossInUnit - the minimum loss of a position in units (TypeOfUnitToClose), to be taken into account by the EA.
- An order with a loss of "MinLossPoss_in_unit" units (USD or points), should be placed in the negative zone.
- It is the upper limit when searching for unprofitable positions.
- For example: MinLossInUnit = -100, TypeOfUnitToClose = USD.
- Then the EA looks for or waits for a position with a loss greater than or equal to -100 USD, for example: -100 USD, -150 USD, -200 USD and so on.
- A position with a loss of -99 USD is ignored.
- AdditionalProfitInUnit - the amount of profit units for the difference to close a set of positions.
- Position (or several) with the total profit exceeding the loss by "AdditionalProfitInUnit" units.
- For example: AdditionalProfitInUnit= 10, MinLossInUnit= -100, TypeOfUnitToClose = USD.
- The EA will look for or wait for at least 2 positions, where one position has a loss of -100 USD and the other has a profit of +110 USD. At this point, the EA decides if it is necessary to activate its functions.
- MaxPos_in_Class - the "MaxPos_in_Class" parameter should limit the number of positions of the entire closing "set".
- For example: MaxPos_in_Class = 3, then the EA will look for a closing set with 3 positions at most (1 unprofitable and 2 profitable ones).
- FirstSymbolClose - search for position pairs and close only those in the currency of the currently processed losing position.
- You can disable the FirstSymbolClose, parameter. Then the EA will close any sets of losing and profitable positions on the entire account, regardless of the currency pair included in calculation.
- When the FirstSymbolClose function is enabled, the EA considers and closes sets of the same currency pair.
- OrderToClose - type of positions: -1 = All Orders, 1 = Sell, 0 = Buy;
- MagiсToClose - magic number of positions: -1 = any, or you can specify a unique magic number of your positions to be processed.
- SymbolToClose - currency pair to monitor: -1 = All Symbol, 1 = Current Symbol;
Operation of the Expert Advisor
The operation involves attaching the Expert Advisor to a separate chart, making the necessary settings and continuing to work in our terminal. When the programmed condition triggers, the Expert Advisor comes into play and starts making calculations.
All calculations are written to the log, as follows:
close #22079015 sell 1.00 EURUSD at 1.35141 at price 1.35119 Tickets of prof positions: .22079015 close #22085491 sell 1.00 USDCHF at 0.90423 at price 0.90430 Tickets of loss positions: 22085491 Numbers of positions to Close: 80635972 All profit from open positions: 20 dollars Maximim profit ticket: 22079015 Maximim profit: 20 dollars Maximum Loss ticket: 22085491 Maximim loss: -7 dollars Overlapping loss positions by closing profitable positions started using the minus:
-Added additional information that will be displayed on the "Strategy" tab of our panel.
This will help monitor the current situation when closing positions.
Added tooltips for parameters in external settings.
- Additional languages added to the panel: Spanish, Portuguese (Brazil), German, Chinese, Japanese;
The translation was made using the GOOGLE Translator + MQL + Terminal site!
if you find an error in your language, please report it in messages. Thank!
- Increase the speed of the panel;
- Renamed the parameters:
TypyClose = TypeOfUnitToClose
MinLossPoss_in_unit = MinLossInUnit
ProfitPerLoss_in_unit = AdditionalProfitInUnit
MagikToClose = MagicToClose
Details on the panel in our blog: https://www.mql5.com/en/blogs/post/687140
MinLossPoss_in_unit - should be set in the negative zone. This is the upper limit when searching for unprofitable positions.
If the parameter is set to MinLossPoss_in_unit=-10, then the unprofitable trade (covered by the profitable ones) must be less than -10 dollars (points)
MinLossPoss_in_unit = parameter that limits the EA operation if the negative trade is greater than the MinLossPoss_in_unit. For example, when opening a trade, it profit = -spread.
The algorithm works if there are 2 or more positions to be closed.
- Added enumerations to select calculation and close type.