Exp Close Minus by Plus - Covering losing positions by identifying and closing winning positions.
Further to the subject of leveling positions, I would like to offer you a more reliable and easy-to-use algorithm of covering losing positions. Every one of you is certainly free to choose your own way of getting rid of negative positions. Our previous Expert Advisor closing positions by total profit or loss, with trailing of the obtained profit, was quite successful.
Introduction This Expert Advisor searches for the biggest losing position across all positions in the terminal (magic numbers, positions and their directions can be specified separately in the settings). Further, using a clever search of 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 TypyClose - dollars - 1, pips - 2. MaxLossPoss_in_unit - order with a loss of "MaxLossPoss_in_unit" units. ProfitPerLoss_in_unit - order (one or more) with the total profit exceeding the loss by "MaxPos_in_Class" units. MaxPos_in_Class - "MaxPos_in_Class" parameter should limit the number of deals of the whole closing "set". FirstSymbolClose - search for pairs of orders and close only those in the currency of the losing position we want to cover. timetrade_ - time settings of the Expert Advisor. OpenHoura - trade opening hour. OpenMinutea - trade opening minute. CloseHoura - trade closing hour. CloseMinutea - trade closing minute. OrderToClose - all orders = -1, Sell = 1, Buy = 0. MagikToClose - all orders = -1. SymbolToClose - all symbols = -1, current symbol = 1.
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 -10 (MaxLossPoss_in_unit=-10) dollars (TypyClose=1) and the total profit being higher by 10 dollars (ProfitPerLoss_in_unit=10). 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 -7 dollars, as well as a series of orders with the profit of +20 dollars. So it closed both the losing position and the series of winning positions.
Developed by www.expforex.com 
gestureс Уважением, Владислав Expforex
|