Hi,
I want my E.A to stop if my equty drops a fixed percent comparing the starting balance.
How can I do that? If you provide me such a code that would be better...
When the EA is initialized, at the "init" func, initialize a variable to your starting equity :
int init()
{
startingEquity=AccountEquity();
....
}
Then, in the "start" func you should always check the current equity like so:
currentEquity = AccountEquity();
if (currentEquity <= ((100-maxDD%)/100)*startingEquity)
don't trade
or actually use the opposite :
if (currentEquity > ((100-maxDD%)/100)*startingEquity)
allowed to trade
This will of course only work provided that you have no disconnections, or power failures.
As we all know, there's no such thing, so this actual code won't really work.
If you want something more robust, you'll need to use the "file functions" and read your "starting equity"
from there. You'll need to do it in the "start" function as well.
This is more complicated, but you get the idea.
When the EA is initialized, at the "init" func, initialize a variable to your starting equity :
int init()
{
startingEquity=AccountEquity();
....
}
Then, in the "start" func you should always check the current equity like so:
currentEquity = AccountEquity();
if (currentEquity <= ((100-maxDD%)/100)*startingEquity)
don't trade
or actually use the opposite :
if (currentEquity > ((100-maxDD%)/100)*startingEquity)
allowed to trade
This will of course only work provided that you have no disconnections, or power failures.
As we all know, there's no such thing, so this actual code won't really work.
If you want something more robust, you'll need to use the "file functions" and read your "starting equity"
from there. You'll need to do it in the "start" function as well.
This is more complicated, but you get the idea.
Thanks!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I want my E.A to stop if my equty drops a fixed percent comparing the starting balance.
How can I do that? If you provide me such a code that would be better...