Close Minus by Plus - Closing loss-making positions, by finding and closing of profitable positions

Close Minus by Plus - Closing loss-making positions, by finding and closing of profitable positions

21 June 2019, 13:14
Vladislav Andruschenko
7
2 008

Exp - Close Minus by Plus 



In the continuation of the topic of leveling positions  , I want to offer you a more reliable and pleasant algorithm for overlapping loss-making positions.

Of course, everyone has the right to choose their own way of getting rid of negative positions. Our last article describing the assistant for the trader, namely the  Closing on the total profit or loss, with the trailing of the profit obtained , brought quite good results.

This article describes an algorithm that was written 4 years ago, but has not been brought to mind. But with the presentation of our valued customers, the project has earned again.

Foreword

 
To begin with, I would like to express my gratitude to our regular customer. Thanks to   Alexander Puzanov. who again started the mechanism of this assistant.
 

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.

 

Assistant work

 

All the work is that we put the expert on a separate chart, set it up and work further on our terminal. When the programmed condition comes - the expert advisor joins in the work and begins his calculations.


 
At what all calculations the expert advisor writes down in logs, it looks so:
 
  • 16:57:34 Exp - Exp - CloseMinusByPlus GBPUSD, H1: initialized
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: Overlapping of loss-making positions by closing of profitable positions started:
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: The biggest negative: -51 pips
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: The biggest minus ticket: 222064678
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: The biggest plus: 22 pips
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: The biggest plus of the ticket: 222064722
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: Aggregate Profit for the Positions Found: 72 pips
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: Number of positions to close: 5
  • 16:58:41 Exp - Exp - CloseMinusByPlus GBPUSD, H1: Tickets for closing unprofitable positions: 222064678
  • 16:58:42 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064678 buy 0.10 GBPUSD at 1.65055 at price 1.65004
  • 16:58:42 Exp - Exp - CloseMinusByPlus GBPUSD, H1: Tickets for closing profitable positions: .222064722. 222064691. 222064750. 222064878. 222064715
  • 16:58:53 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064878 sell 0.10 EURUSD at 1.35773 at price 1.35774
  • 16:58:54 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064750 sell 0.10 GBPUSD at 1.65034 at price 1.65025
  • 16:58:54 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064722 sell 0.10 GBPUSD at 1.65039 at the price of 1.65025
  • 16:58:55 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064715 sell 0.10 EURUSD at 1.35765 at price 1.35773
  • 16:58:56 Exp - Exp - CloseMinusByPlus GBPUSD, H1: close # 222064691 sell 0.10 GBPUSD at 1.65038 at the price of 1.65024
 
As you can see from this entry, we had many open positions (a chaotic discovery).
In the settings, we set up - start the calculation when the largest unprofitable position with a minus -50
 (  MinLossInUnit = -50) pips (  TypeOfUnitToClose = 2) and the aggregate profit will be 20 pips more is found (  AdditionalProfitInUnit = 20)
Also we have established that it is necessary to close no more than 5 orders (  MaxPos_in_Class = 5 )
 
The expert found the position at a loss of -51 pip, as well as a series of orders with a profit of +72 pips. and, in fact, closed both the unprofitable position, and a series of profitable positions.
 
 
 
 
 

An example of this algorithm  

in the Expert advisor 2 MACD


without function:


with closing function by overlapping:
 
 

External Variables and Settings

 


Name Description
TypeOfUnitToClose Type of profit and loss. In dollars or in points
MinLossInUnit Minimum loss of position in units ( TypeOfUnitToClose ), which is taken into account the Expert advisor.
An order with a loss in the "MinLossPoss_in_unit" units (dollars or points) must be set in the negative zone.
This is the top bar for finding loss-making positions.
For example: MinLossInUnit = -100 TypeOfUnitToClose = dollars, then the EA looks for or expects a position at a loss greater than or equal to -100 dollars, for example: -100 dollars, -150 dollars -200 dollars and so on.
The position with a loss of -99 dollars is already ignored.
AdditionalProfitInUnit The number of units of profit for the difference in the closing of the set of positions.
Position (one or several) with a total profit exceeding the loss on the " AdditionalProfitInUnit " units.
For example: AdditionalProfitInUnit = 10 MinLossInUnit = -100 TypeOfUnitToClose = dollars
The advisor is looking for or waiting for at least 2 positions, one of which at a loss of -100 dollars, and the second with a profit of +110 dollars. at this point the adviser decides on the inclusion of his function
MaxPos_in_Class The parameter "MaxPos_in_Class" should limit the number of positions of the entire "set" of closing.
For example: MaxPos_in_Class = 3, then the expert advisor will look for a set for closing from a maximum of 3 positions (1 loss-making and 2 profitable ones)
FirstSymbolClose Search for pairs of positions and close only the currency, minus which we are processing.
You can turn off the FirstSymbolClose parameter , then the EA will close any kits from the losing and profitable positions in the entire account, regardless of which currency pair is included in the calculation.
When you enable FirstSymbolClose -   the expert advisor considers and closes sets from one currency pair
OpenHoura OpenMinutea Start time of the Expert Advisor
CloseHoura CloseMinutea End time of the Expert Advisor
OrderToClose Positions type: -1 = All Orders, 1-Sell, 0 = Buy
MagicToClose

Magic of positions: -1 = any magic numbers. Or you can specify a unique magic number of its positions, which should be processed.

You can specify multiple magic numbers separated by commas.

SymbolToClose Currency pair for monitoring -1 = All Symbol, 1-Current Symbol





You can also download my other products:
Description MetaTrader 4  MetaTrader 5
Copy of deals and positions between terminals  COPYLOT  MT4  COPYLOT MT5
Trading panel in 1 click from the chart and keyboard  VIRTUALTRADEPAD MT4 VIRTUALTRADEPAD MT5
Automatic scalper without settings  TICK HAMSTER MT4  TICK HAMSTER MT5
Professional Automatic scalper, Smart Robot  TICKSNIPER MT4 TICKSNIPER MT5

Universal Expert Advisor on Custom Indicators  The xCUSTOMEA MT4 The xCUSTOMEA MT5
Universal Advisor on Standard Indicators  THE X MT4 THE X MT5
Averager, grid, additional opening of positions on Trend and against Trend  AVERAGER MT4 AVERAGER MT5
Duplicator of positions, copying positions on one terminal  DUPLICATOR MT4 DUPLICATOR MT5
Automatic installation of stop loss / take profit / trailing stop  ASSISTANT MT4 ASSISTANT MT5
Simulator for strategy tester  TESTERPAD MT4 TESTERPAD MT5
Professional account report   EXTRAREPORTPAD MT4 EXTRAREPORTPAD MT5




Share it with friends: