Trailing funds function (equity) - has anyone come across a ready-made one? - page 4

 

my suggestion :

//+------------------------------------------------------------------+
//|Трал по эквити                                                    |
//+------------------------------------------------------------------+
bool EcvitiTral3(double EqvTralStep){
if(OrdersTotal()<1){ gEqviti=AccountBalance();return(false);}
if(!GlobalVariableCheck("step")){ EqvTralStep= EqvTralStep;}
  else{ EqvTralStep=GlobalVariableGet("step");}
EqvTralStep= EqvTralStep*(GlobalVariableGet("multi")-GlobalVariableGet("disable"));
  if( WithoutLoss){
    if(AccountEquity()>=AccountBalance()){
      if(AccountEquity()-AccountBalance()>((AccountBalance()/100)*( EqvTralStep*2))){ EqvTralStep= EqvTralStep*2;}
      if(AccountEquity()>( gEqviti+( gEqviti/100* EqvTralStep))){
        gEqviti= gEqviti+( gEqviti/200* EqvTralStep);
        eqvtrade=true;
        if(!GlobalVariableCheck("stop")){GlobalVariableSet("stop",0);}
      }
      if(AccountEquity()<= gEqviti){ CloseAll();Print("CloseAll");GlobalVariableDel("stop");return(false);}
      else{Comment(AccountFreeMargin()+AccountMargin(),"\n",
                 "EQUITY TRALING MODE\n",
                 "EQUITY TRALING STEP   =", EqvTralStep," %",
                 "\n ACCOUNT BALANS         = ",AccountBalance(),
                 "\n CLOSE LEVEL                  = ", gEqviti,
                 "\n ACCOUNT EQUITY        = ",AccountEquity(),
                 "\n NEXT STEP                     = ", gEqviti+( gEqviti/100* EqvTralStep));
                 return(true);
      }
    }else{GlobalVariableDel("stop");} 
  }else{
    if(AccountEquity()>AccountBalance()){
      if(AccountEquity()-AccountBalance()>((AccountBalance()/100)*( EqvTralStep*2))){ EqvTralStep= EqvTralStep*2;}      
      if(AccountEquity()>( gEqviti+( gEqviti/100* EqvTralStep))){
        gEqviti= gEqviti+( gEqviti/200* EqvTralStep);
        eqvtrade=true;
        if(!GlobalVariableCheck("stop")){GlobalVariableSet("stop",0);}
      }
      if(AccountEquity()<= gEqviti){ CloseAll();Print("CloseAll");GlobalVariableDel("stop");return(false);}
      else{Comment(AccountFreeMargin()+AccountMargin(),"\n",
                 "EQUITY TRALING MODE\n",
                 "EQUITY TRALING STEP   =", EqvTralStep," %",
                 "\n ACCOUNT BALANS         = ",AccountBalance(),
                 "\n CLOSE LEVEL                  = ", gEqviti,
                 "\n ACCOUNT EQUITY        = ",AccountEquity(),
                 "\n NEXT STEP                     = ", gEqviti+( gEqviti/100* EqvTralStep));
                 return(true);
      }
    }else{GlobalVariableDel("stop");}  
  }
return(false);
}
The call is put at the beginning, and overlaps the rest of the EA blocks for the trawl time, the trailing step is variable - quadratic, which allows to work well with equity jumps capturing the maximum profit. CU mode allows to cut unprofitable orders in the bud.
 
xrust >>:

my suggestion :

The trailing step is variable, it allows to work off Equity jumps capturing maximum profit. CUE mode allows to cut unprofitable orders in the bud.

Good afternoon,xrust ! Please explain a little more about the operation of this unit. I can't get it to work.

I can't get it to work.

1. Function CloseAll(), it must be a f-function that deletes all the orders and/or closes the positions.

I have an analogue of this function and there is no problem here.

2. I have defined it in the properties.

extern bool WithoutLoss = true;

- what is this parameter?

3.

extern double gEqviti=200;// - is this the size of reaching equity, at which the trawl starts working ?

4. I also set -

bool eqvtrade;

What else needs to be set? How is parameter EqvTralStep; set?

And please (if it's not difficult) describe in 2-3 words how the function works in general form.

 
The function is called at the very beginning of the EA immediately after int Start():
//удаляем запрет на торговлю после удаления всех ордеров 
  if(OrdersTotal()<1){
    if(GlobalVariableCheck("stop")){GlobalVariableDel("stop");}  
    gEqviti=AccountBalance(); 
  } 
//тралим эквити
  if( EcvitiTral3( EqwTralStep)){return(0);}
  if(GlobalVariableCheck("stop")){return(0);}

if eqviti has risen above the balance, it blocks all EA's steel functions and trawls.

Now for variables: in global variables static double gEqviti;

extern double EqwTralStep=0.03; trailing step in percent of equity extern bool WithoutLoss=false; allowing to apply Breakeven method

How this function works: when equity exceeds the balance it records the balance level as zero, which means that it needs to close, if equity exceeds by EqwTralStep in percents it moves the closing level up, if the speed of exceeding is high, the function increases the step quadratically.

 
Thank you! I'll give it a try.
 

You're welcome, if you have any difficulties, please don't hesitate...

 

Done. It's up and running. So far it's working fine. Been online for a second week.

But. There are rare glitches from time to time.

Usually I have 3-10 positions in the market at the same time .

But - When there is one position in the market, it suddenly closes with a profit =1-2 pips, for no apparent reason!

I do not understand why. The basic code of my Expert Advisor does not provide for such a situation.

 

It is quite easy to control, such closures can be caused by a sharp price swing and a move to a new closing level and as a consequence close the position.

Do so :

организуйте в функции стическую переменную static double prewlewel;

потом перед , или за комментами 

  if( prewlewel!= gEqviti){
    prewlewel= gEqviti;
    Print( prewlewel);
  } 

А здесь добавьте обнуление переменной 
if(OrdersTotal()<1){ gEqviti=AccountBalance(); prewlewel=0;return(false);}
 

xrust - Ihave a suggestion/request to you - can you bring the code of your version of the equity trawl as a standalone EA.

It would be a very useful tool for hand traders.

I have been looking for such a tool for a long time, but have not found anything suitable, and I myself am not good at coding (or rather am weak).

 
ToKa_TuXa писал(а) >>

xrust - Ihave a suggestion to you - can you bring the code of your version of the equity trawl as a standalone EA.

It would be a very useful tool for hand traders.

Good idea! I support you...

Indeed. Such a design will not go unnoticed.

 
Try this one Easy to operate. I use it myself. All you have to do is specify the profit you want and the percentage of allowable drawdown after it is reached.