Expert Advisor EA TotalRecovery

Expert Advisor EA TotalRecovery

3 June 2019, 10:03
1 654

Last Update 04/February/2019 v6.2

Expert Advisor FY  Total Recovery is a pure recovery system, fully automated.

This system tries to recover accounts. Positions out of reach will be tried to recover until last position is closed with profit.

Content :

  1. Terms used herein
  2. Prerequisites
  3. General cases
  4. General algorithm
  5. Special close situations
  6. Further instructions
  7. Set Up
  8. Parameters
  9. Buttons on TotalRecovery chart
  10. Is my TotalRecovery healthy or something wrong?
  11. Brokers comment
  12. Global recovery variable
  13. version update of TotalRecovery

1 Terms used herein :

T-position : trade positions, the positions to recover, opened by you or your expert advisors

H-positions : hedge positions, opened by TotalRecovery

O-position : operational positions opened by TotalRecovery

2 Prerequisites:

  • Your account must be able to realize hedges and of course Non-Fifo.
  • Your margin/free balance  must allow to set 1 or 2 hedges and additional positions. There is no recovery without trading. TotalRecovery needs some room  to trade as well.

3 General Cases

- you succeed with your regular trading and TotalRecovery will be active from a certain DD level (default =25%).

- you didn't succeed with your general trading and TotalRecovery will ne instantly active and may close all charts windows to that currency pair

- TotalRecovery succeeds in recovering (regular case)

- TotalRecovery does not succeed in recovering (there is no holy grail with 100% success on a deep DD account)

4 General algorithm 

1. Check if there is an overall positive basket in buy or sell and close with profit.

2. Check if single positions of a direction can be closed in profit if step 1 didn't succeed

3. Set a hedge (H-position, hedge) on all Buy- and/or Sell T-positions in a single step when trend is against direction of T-positions. There will be single a hedge for Buy and a single Hedge for sells.   SL+TP will be removed from all positions

4. Will open operational positions (O-positions, recovering positions, up to 10), first in direction of trend/and or hedge direction when setting hedge firs. O-positions are not set before hedge is set, then RSI-filter will decide to open O-trades.

5. If O-positions have enough profit to cover losses on T-positions and H-position TotalRecovery will close a basket of all three kinds T,H and O.  This is a recovery/resolve process.

TotalRecovery calculates position size to resolve and may (often) choose partial recovery on long distance positions.  A text with calculated profit will be printed onto chart at close time.

6. Repeat with 4 until account recovered (no position is open)

Please attach to any time frame, M15 is fine.

5 Special close situations

When TotalRecovery is in recovery mode and O-trades are open, those might close without releasing H-position  and T-position if market situation changes and trend might indicate to close those with needed profit.

6 Further instructions

  • It will not fire trades from its own, but watch and care about positions opened by other expert advisors or manual trades.
  • It will fire some trades in strategy tester to fulfill Metaquotes requirements for product verification and demonstration
  • If draw down of selected positions (magicno and/or manual positions) it will switch from Guard mode to Recovery Mode then it will open positions in the total size of open position in counter direction as hedge to freeze DD, then begin to release positions
  • You can use it as an automated  watch dog to enter recovery of as soon a certain draw dawn is reached, or start recovery manually by pressing Recovery button in chart on open positions.
  • You can manage up to 3  MagicNo per currency pair and include positions without magic number as well.
  • It's possible to close all charts belonging to the watched currency pair as soon as recovery mode is entered.
  • It's important not to modify, close or even open positions to recover in the currency pair to recover AFTER recovery mode is entered, but you may start or add operational positions at price levels of your favor with provided buttons (open buy, open sell) before Total Recovery does (it will).
  • Attach TotalRecovery to the pair that needs to be recovered, it will not touch any other pairs in that account

7 SetUp

Choose M15,H1 or whatever chart on your currency pair to recover. Expert advisor will work with the time frame you specify in time_frame_rec parameter. M15 or M5 is fine because you will see the printed closing labels better. Otherwise they will overlap or even overwritten and unreadable (no problem for functionality and log is always written).

Adapt the Magicno1..3 and parameters 'all_positions' 'include_without_magicno' to include all you current and future positions to include into the set of detected T-positions.   TotalRecovery will show up the detected open positions. Check, that number and size do match if there are any positions open.

Attention : If you already reached DD value it will immediately start recovery. If you want to start immediately check the included positions. Either set Autotrade off in MT4 or set parameter 'rec_percent' to a very high value (higher than your current DD, example : 99) , so TotalRecovery stays in Guard Mode.

Recovery button is for starting manually before DD reaches the value rec_percent(25%) or for testing. 

Example : rec_percent is 25%. A high impact news sends the price of your currency pair to an other level and it is unlikely that it will return due to the facts. DD rises to 20% and no way to get back. You press 'Recovery' and TotalRecovery will start recovery from better 16% than 25% level.

If DD value is not reached TotalRecovery will wait in Guard mode :

If TotalRecovery is in recovery mode ALL your charts in that currency should either be closed or do no contain active experts on that currency pair.

Attention : If you start with a DD that is higher than 25% make sure your other expert advisors on that pair will not trade in parallel. Close charts before (if not choosen close_charts_on_recovery=true in parameters, then they will be closed automatically).

If you use Metaquotes VPS note that any chart from PC will  be active on VPS , even trading was switched off in expert parameters and smiley was down. Do not keep open or synchronize charts, that should not be active  with Metaquotes VPS.

If your account has Yen as currency base you need to multiply some parameters with 100 :

  • new : per_currency_units_t=500 ->set it to 50000
  • new : per_currency_units_w=500 ->set it to 50000
  • profit_per_MinLot=1.00 -> set it to about 100

8 Parameters

Determine the amount/set/kind of positions to recover :

  • MagicNo1=-1 first Magicno to watch/recover if you have a single expert advisor that opened the positions to recover enter the number here
  • MagicNo2=-1 2nd MagicNo to watch/recover in case you have 2
  • MagicNo3=-1 3rd MagicNo to watch/recover  in case you have 3
  • all_positions=false   all positions belonging to current currency pair, but without manual positions (MagicNo is 0 with those). If you choose all_positions=true, you don't need to enter MagicNo1,2,3.
  • include_without_magicno=false  if set to true all manual positions are included( or created by expert advisors without using MagicNo).

If correctly attached  'your T-positions' (that are the ones you want to recover) are shown up in TotalRecovery panel correct in number and lot sum. You can test by switching Autotrade off to see the detected positions and DD level.

Hint : To be sure scroll with mouse wheel over every single T-position and investigate MagicNo.Write down numbers if there are more or choose all_positions=true. Take care of manual positions, are there any ?

If you use TotalRecovery as a watch dog it can close all charts belonging to the traded pair. the number of charts is shown up in the panel. Attention : this parameter is switched off by default to protect open charts when updating software version. Sometimes default values will be shown up and other charts could be incidentally closes. Total Recovery will not close any charts after entered Recovery modes for safety reasons

  • close_charts_on_recovery=false  If TotalRecovery changes form Guard Mode to Recovery Mode it can close all charts belonging to the pair it's attached. Default is false to prevent closing of charts at a version upgrade in recovery mode
  • comment="FYR" prefix of broker comment. This will be as informational text in column 'comment'.
  • maxspread=30 maximum spread, adapt to your pair and broker. Examples : GBPUSD>=20, EURUSD>=10. This is the spread in points TotalRecovery allows your broker to work. Look at the market window (switch on spread column with right mouse click if not visible). What is the typical spread of your broker ?! 15 or 20 is a value for GBPUSD, EURUSD on ECN. TotalRecovery will use  spread filter for open AND close positions.
  • rec_percent=25 draw down in the selected positions to start recovery. TotalRecvoery will switch form guard mode to recovery mode.
  • release_size_auto=true   maximum release position size considering account balance. 0.01/1000.
Release size is the maximum position size to resolve/recover out of a T-position (possible with hedge H-positions and/or operational O-positions

  • per_currency_units_t=500 : 0.01/currency units for calculations release_size
  • release_size=0.01           fixed value when release_size_auto=false
The archived release size may vary  and smaller than by formula 0.01/1000 caused by larger distance between H-position and T-position
  • distance_to_release=auto  recover nearest or farest position first or choose automatic mode. Near is with less loss, can be resolved earlier and avoid swap and load when closed. Far is most eepensive to resolve/recover. auto option will choose the best position depending on market condition.
Close positive positions T-pos
  • close_T_basket_in_positive=true  If you start TotalRecovery for the first time (then no hedge is set at this time), TotalRecovery will close a buy or sell basket  that is in total positive. In most cases there is no, but TotalRecovery will check this and close if here is. This also works in Recovery mode in case unseen T-positions show up
  • close_T_single_in_positive=true If you start TotalRecovery for the first time (then no hedge is set at this time), TotalRecovery might close all buys or sells  with floating profit.
  • close_T_only_in_counter_trend=true . If set to true T-positions are only closed in profit in counter trend, otherwise trend doesn't decide close on T-positions. They may stay open for a while when set to true.

Correct T-position H-position relation
  • allow_TH_synch=true;
  • MagicRh=86000
T-positions and H-positions should have almost same size. In case there is a mismatch of total size, Total Recovery can repair two constellations and T-positions and H-positions will show up same size
  • H-position is in profit and T-position is missing -> TotalRecovery will release a part of the H-position with profit.
  • H-position is in loss and T-position is missing -> TotalRecovery will open a T-position with magic number MagicTH.


  • MagicRh=87000        Magic number of hedge positions. Mustn't be used by other expert advisors and be different from parameter MagicRo and MagicS1..MagicS3.
  • auto_set_hedge=true if a hedge gets accidentally lost (manual accident?) TotalRecovery will recreate it as soon as trend is against direction of T-positions.
  • hedgekind : if set to difference_load Total Recovery will set incomplete hedges. This is intended for accounts with very big DD (>50%) as a last chance when margin is nearly exhausted. Default is 'all'. 'all' is the behaviour of standard v5.6 or lowr. Warning : setting to 'difference_load' can increase DD !
  • force_hedge_from_dd=x, default x=0 : hedge is easier to be set if dd of x or higher is reached. (On values below Total Recovery prefers working with possible rebounds without forced hedges).
  • hedgeclose_max_dd=y, default y=40; a hedge may be closed in total as T-H-O close if trend changes. It will be restored on next trend change. This will not be performed if DD>y%
  • MagicRo=88000    Magic Number of operational positions. Mustn't be used by other expert advisors and be different from parameter MagicRh.
  • buy_allowed=true allow operational buys
  • sell_allowed=true allow operational sells
  • open_max_percent_0=90 do not allow to open (new, additional) O-positions if DD is too high
  • per_currency_units_w=500 0.01/currency units for calculation start_size_o
  • start_size_o_auto=true    operating position size considering account balance. 0.01/1000
  • start_size_o=0.02            fixed otherwise. Should be greater or equal than release_size, if fixed is used
  • max_pos_o=10            maximum number of operational positions ( of course on each direction)
  • multiplier_o=1.0         multiplier for operational positions , 1.0 means : no martingale
  • distance_auto=true    auto calculate minimum distance distance_o between two O-positions ( distance_o parameter below ignored then). The 2nd O-trade will ignore this parameter. It might open below, on same or above the level of first O-position if signal triggrs open. This will help to resolve faraway positions. distance_o is respected from position 3 and higher.
  • distance_o=25; fixed distance_o otherwise
  • distfac_o=1.1              multiplier for distances between positions. Will  be used for both auto calculated and fixed distance_o value.
  • fast_first=false  when setting hedge TotalRecovery will open O-position in direction of hedge immediately
Autonomous close of O-positions
  • close_on_o_counter=true; if profit is not sufficient in wrong trend for closing a basket, but O-positions can reach the needed profit, they are allowed to close outside basket
  • close_on_o_from_pos=2; O-positions are only allowed to close without participating in a basket if you have 2 or more O-positions open. Otherwise we would see a chain of O-positions close that waste time even they make good profit with them.
Basket profit
  • method_basket_profit=Linear Absolute, Linear or RaiseWithTrend. 
    • Absolute close basket if total profit is profit_per_MinLot (==1). Fastest method, close with minimum in profit.
    • Linear close basket if total profit is Total position size/MinLot/2 Example 0.10 Lot will require 5 $/€ basket profit on a 0.01 MinLot. A reasonable required profit to prevent slippage or spread effects. Medium speed. Default value.
    • RaiseWithTrend as Linear but position size/MinLot in trend. Example 0.1 will require 10 $/€ in trend and 5$/€ in missing trend/counter trend. Maximum additional profit, but take A longer to recover. Better not to use on high DD rates.
  • profit_per_MinLot=1.00   Total basket profit in currency units. Either absolute or as base for calculation on Linear and Raise withTrend  method.
Recovery trigger type
  • time_frame_rec=PERIOD_H1  time frame for recovery algorithm, TotalRecovery considers higher time frames as well
  • ma_lead_period=52  this is important parameter to decide whether to buy , to sell, to close.
  • open_on_new_bar=true open new O-position only at new bar
  • open_first_T=true allow expert advisor to open T-positions even there is no T-position in that direction or hedge related. B
  • Panel properties
  • showInfo=true    show panel
  • background  clrCornflowerBlue panels background
  • bg_transparent  make background transparent
  • text_color color of text in panel
  • corner : Left upper, right, upper or right lower. Left lower will be shown as left upper to allow buttons left lower.


  • verbose=false   hide some messages in log  as 'high spread'

9 Buttons on Total Recovery chart

There is no need to press any of the following buttons except you intend to force opening of O-positions or H-positions. TotalRecvoery will open those positions right in time (hopefully).
  • Open O-Sell  Open O-trade manually. This might be used in very strong an fast trends to open first operational positions. No need to use this TotalRecvoery will open at the right time and place
  • Open O-Buy  Open O-trade manually,  This might be used in very strong an fast trends to open first operational positions. No need to use this TotalRecovery will open at the right time and place
  • Restore Hedges create a possible hedge

10 Is my TotalRecovery healthy or something wrong?

If TotalRecovery is in recovery mode the T sum and H sum are often of the same size to realize a perfect hedge situation. O-trades might be opened from tome to time. Hedges might be missing sometimes. It's o.k. If they don't show up immediately a good entry is required and TotalRecvoery waits for signal. In strong trends they might follow quickly with short breaks in between (rebounds). In range or low volatile situtions it might take hours or days.

If hedge is missing a hedge is sooner or later needed and TotalRecovery will create hedge.

Are TP or SL of any of the affected positions greater than 0 ?  This is a mismatch !

TotalRecovery will reset SL and TP to 0 at any start. If there still SL and TP are changed some other expert advisor  is still active or these positions are not seen by TotalRecovery by chosen parameters /Magicno, all_positions, manual).

11 Brokers comment

You will find texts like 'FYR_b_H_0'  or 'FYR_b_o_A_2"  in column  'comment' of any position when TotalRecovery os working on.

These comments are informational only and not reread by TotalRecovery for any action. Broker may delete and modify them at any time !


where ..

  • FYR is parameter 'comment' in expert advisors parameter section
  • direction is  = Buy or s=Sell
  • kindoftrade is H=hedge, O=operational position, T=Trade position
  • trigger is the method to trigger an operational Trade S=central indicator, M=manually triggered by Button "open .. trade"
  • numberofposition is the number of position of same kind and direction starting with 0...1,2,3,


  • do not have a kind of trigger, they follow scheme <FYR>_<direction>_<kindoftrade>_<numberofposition>
Hedges and Trade positions
  • loose their comment as soon as a partial close is done. A human identification on the trade window is only possible then by magicno in the left column (scroll with mouse over ticket number)

12 Global recovery variable

As soon as TotalRecovery enters Recovery Mode it sets an identifying global variable into MT4 with value 1. This kind of global variable survives closing and openings of charts and MT4 program.

TR_<currency_pair>_<magicno_of_hedge> = 1

Example, pair EURUSD, expert parameter in TotalRecovery MagicRh=87000 (default)  for Hedge :

You can see this Global Variable by pressing F3 in MT4 or Tools->Global Variables

As soon as recovery ends this variable will be set to 0.

Attention :

If you

  • reinstall MT4
  • change TotalRecovery to an other terminal for same account recovery constellation
  • delete this variable TotalRecovery 
  • DD is below the rec_percentage value (of 25%), there is no hedge and there is no operational position at the same time
may not longer be in RecoveryMode, 

You must press "Recovery Button" then manually in chart. During regular work in the same terminal there is no need to do this.

Also you could use this variable to stop recovery by deleting it or set to 0, if you  are at low DD level and don't want to continue to  recover. Close TotalRecovery chart and change global variable.

Notes on update process in MT4

If updating expert advisor switch autotrade off.

Otherwise TotalRecovery might see the Hedges, cant's see the T-positions and create big 'missing' T-positons in that size.

Switch AutoTrade on as parameters are changed to your needs  and TotalRecvoery shows all T-positions (and  H-positions, O-poisitions)

This is not a problem with TotalRecovery, but with general update process in MT4 where sometimes all changed parameters are reset to initial in update process. It happens to all expert advisors and is not related to this product.

13.version update of TotalRecovery

Turn AutoTrade off.

Make a screen shot or note your MagicNo1-3 / all positions / manual trades included

Update TotalRecovery by market or doing a refresh in navigator window on experts (right mouse click)

Reattach expert advisor

Restore the values MagicNo1-3 / all positions / manual trades included  by entering in to the new version parameters

If all positions show up turn AutoTrade on.

Restart MT4 if panel doesn't show the right values or to be safe on memory/variables and so on

Share it with friends: