![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);}
...
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?
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).
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 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:)