• Overview
  • Reviews (3)
  • Comments (39)
  • What's new

Exp4 Close Minus by Plus

Covers losing positions by identifying and closing winning positions.

This assistant looks for the most loss-making position among all positions in the terminal.

Further, by searching for other positions, it calculates a series of orders that can cover the loss and closes them.

The series of orders can include any position. The maximum number of positions is specified in the settings of the Expert Advisor.


Settings

  • 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.
  • OpenHoura OpenMinutea - the EA operation start hour.
  • CloseHoura CloseMinutea - the EA operation end hour.
  • 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:

2014.02.05 01:18:38.408 Exp - Exp - CloseMinusByPlus USDCHF,H1: close #22079015 sell 1.00 EURUSD at 1.35141 at price 1.35119
2014.02.05 01:18:38.346 Exp - Exp - CloseMinusByPlus USDCHF,H1: Tickets of prof positions: .22079015
2014.02.05 01:18:38.346 Exp - Exp - CloseMinusByPlus USDCHF,H1: close #22085491 sell 1.00 USDCHF at 0.90423 at price 0.90430
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Tickets of loss positions: 22085491
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Numbers of positions to Close: 80635972
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: All profit from open positions: 20 dollars
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Maximim profit ticket: 22079015
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Maximim profit: 20 dollars
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Maximum Loss ticket: 22085491
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Maximim loss: -7 dollars
2014.02.05 01:18:38.283 Exp - Exp - CloseMinusByPlus USDCHF,H1: Overlapping loss positions by closing profitable positions started using the currency pair minus:

The above suggests that we have had a lot of open positions (chaotically opened).
We have specified in the settings that the calculation should start when we find the biggest losing position with a loss of -50 (MinLossInUnit = -50) pips (TypeOfUnitToClose = 2) and the total profit being higher by 20 pips (AdditionalProfitInUnit = 20).

We have also specified that not more than 5 orders (MaxPos_in_Class = 5) should be closed.

The Expert Advisor has found a position with a loss of -51 pips, as well as a series of orders with the profit of +72 pips. So it closed both the losing position and the series of winning positions.

Gusstaw
43
Gusstaw 2015.05.16 12:17 
 

работает на 5+,любой счет,любой депозит,полезен новичкам,те постоянно в минуса лезут,закрывает и -10 и -100,настройки минимальны и очень просты,авторы всегда помогут,если и закрывает с минусом,то минимальным..поверьте-это один из лучших помошников

umtelo
156
umtelo 2015.04.09 23:00 
 

я так понял главное правильно настроить. И в принципе из 10 пар закрывает пачку ордеров плюс минус.

savagerus
141
savagerus 2015.01.15 15:42 
 

Отличный и полезный советник

Version 18.515 - 2018.05.29
- Updated EAPADPRO v2.0 info panel;

Attention!
- Renamed the parameters:
TypyClose = TypeOfUnitToClose
MinLossPoss_in_unit = MinLossInUnit
ProfitPerLoss_in_unit = AdditionalProfitInUnit
MagikToClose = MagicToClose
Version 17.208 - 2017.02.14
Improved EAPADPRO
Version 17.123 - 2017.01.27
- Added the EAPADPRO information panel
Details on the panel in our blog: https://www.mql5.com/en/blogs/post/687140
Version 16.121 - 2016.04.07
Fixed the error of closing the profitable trades when there are no unprofitable ones and the MinLossPoss_in_unit parameter is set to +
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.
Version 15.731 - 2015.08.03
Added the message to the strategy tester stating that the product cannot be tested in the strategy tester.
Version 15.729 - 2015.07.30
Added: disabling algorithm if there are more than 1 positive trade.
The algorithm works if there are 2 or more positions to be closed.
Version 14.965 - 2014.12.23
- Compiled under new build.
- Added enumerations to select calculation and close type.
Version 14.709 - 2014.07.09
Added array release before every pass to avoid closing positions with the same tickets.