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

 
use global variables as an option
 

This is how I made profit taking in one of my EAs:

extern double ProfitAutoClose = 100.0; // Increment for profit taking

double Depo;

int init()
{
//----
Depo=AccountEquity();
GlobalVariableSet("Depo",Depo);
//----
return(0);
}

int start()
{

Depo=GlobalVariableGet("Depo");

if(AccountEquity()-Depo>ProfitAutoClose)
{

ClosePositions("0",-1, Mn);//close all positions

Depo=AccountEquity();

GlobalVariableSet("Depo",Depo);

}

...

 
Rita >> :

This is precisely the difficulty. How do you determine equity in the previous step(s)?

You have to rely on some previous equity value. Where do we get it - the previous value?

GET A VARIABLE.

 

Thank you all. Yes, indeed.

I have closed on profit taking (from khorosh) and this option works very well. And after optimizing the ProfitAutoClose parameter the drawdown has considerably decreased!


However, it is not exactly equity trimming.

How to add trailing equity here? Would I introduce another variable?

 
Take a look at trailing equity in Igor Kim's new advisor.
 

Thank you, granit77!

But that's just the version I experimented with originally. It won't fit, because there the trawl is pushed off the balance and interacts with the balance . It is profit that is being trawled.

In my EA, equity is always below the balance and this build is not suitable.

I mentioned it earlier (last post on the 7th page):

"How can I trawl the equity if my EA always shows negative profit?
I.e.,there is no profit, but there is a current loss (it is the specific EA operation, each individual position closes (mostly) in the plus, but all open positions in this case are always in the loss).

 
Rita >> :

And with my EA - equity is always permanently below balance and this design is not appropriate.

Close unprofitable trades first, then profitable ones. The balance will fall below equity (which is equivalent to equity above the balance).

// It will not affect the profitability in any way.

Otherwise, I gather you tend to get nervous about the very fact of "equity<balance". So frustrated, in fact, that you're slowing down quite a bit. ;)

Basically, you can send the source code to me (if you don't want to make it public) and I will correct it for you.

 

Rita, here's a look at the code (as an example), once did myself, NOT using, but it worked as I remember now :)

no linkages to balance sheets, balance sheet profits and other unnecessary things

(check thoroughly before use, modify for your own needs)

if (!GlobalVariableCheck("StopTrading")) {if (!GlobalVariableCheck("TrStopEquity")) { int sl=SL_Equity; int tp=TP_Equity; if (( sl!=0 && AccountEquity()<=sl) || (tp!=0 && AccountEquity()>=tp)){ GlobalVariableSet("StopTrading",1); Sleep(500); ClosePositions(); if ( ShowComment){ comm="Trade completed. All trades are closed.\n"; comm=comm+"Expert Advisors stopped at: "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS); Comment( pref, comm);}} } }if (!GlobalVariableCheck("StopTrading")) {bool tr_stop=TrStop_Equity; int tr_step=TrStep_Equity; int tr_dist=TrDist_Equity; int tr_lvl =TrStartLvl_Equity;if (( tr_stop)||( tr_lvl!=0 && AccountEquity()>=tr_lvl)||(GlobalVariableCheck("trStopEquity")) { if (!GlobalVariableCheck("TrStopEquity")){ GlobalVariableSet("TrStopEquity",1);} Sleep(500); if (!GlobalVariableCheck("SL_Equity")){ GlobalVariableSet("SL_Equity",(AccountEquity()-tr_dist));} Sleep(500); sl=GlobalVariableGet("SL_Equity"); if (AccountEquity()<=sl){ GlobalVariableSet("StopTrading",1); Sleep(500); GlobalVariableDel("TrStopEquity"); Sleep(500); GlobalVariableDel("SL_Equity"); Sleep(500); ClosePositions(); if ( ShowComment){ comm="Trade completed. All trades are closed.\n"; comm=comm+"Expert Advisors stopped at: "+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS); Comment( pref, comm);}} else{if (AccountEquity()>( sl+tr_dist+tr_step)GlobalVariableSet("SL_Equity",(AccountEquity()-tr_dist);Sleep(500);if ( ShowComment) { comm="Trailing Stop is running:\n"; comm=comm+"Level Stop Loss: "+DoubleToStr(NormalizeDouble( sl,2),2)+"\n"; comm=comm+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);Comment( pref, comm); } }} 
The functions used are Kim's, find them on the forum if you don't already have them.
 

If you have a trawl for equity, please, send us a simple one- close all positions and delete all orders if equity = ХХХХ, i.e. if my balance was 10000 before opening positions, I set equity of 10500 in the trawl and as soon as equity = 10500, close all orders and open positions.)

I looked at Kim's ... I think it all looks a bit complicated ...) above in this thread ...) Thanks in advance:)

 

Ah, that's it, I think I found it just above... stCloseOrders seems to be the right one:)

But if anyone has something similar, then throw it in... it's never too useful:)