Account Equity Cease trading - Coding Help
Account Equity Cease trading - Coding Help
05 Dec 2013, 19:35
Hi, does anyone know of a way to code in a kind of "fire-sale". I.e. when your equity hits a certain low, all trades are closed.
The idea being that a certain amount of equity is always protected, so I could (for example) go on holiday and leave a robot running without having to worry about it clearing my account. Although stop-losses should prevent this, it's possible with a series of bad trades and it would be typical that this would happen while I'm not watching.
Replies
Kevin
05 Dec 2013, 20:13
Awesome, thanks! :D
I noticed you replied to my other post too and I have a similar problem with this in that I don't know how to add it to the code I already have.
Also, I can change the email address as that is quite clear, but where do I edit/add the account balance or percentage?
@Kevin
Cerunnos
05 Dec 2013, 20:33
RE:
Kevin said:
Awesome, thanks! :D
I noticed you replied to my other post too and I have a similar problem with this in that I don't know how to add it to the code I already have.
Also, I can change the email address as that is quite clear, but where do I edit/add the account balance or percentage?
In the declaration block add following code:
private double startingBalance;
private const double BalancePercent = 0.85; // change the value = max. DrawDown
@Cerunnos
Cerunnos
05 Dec 2013, 20:03
RE:
Kevin said:
protected override void OnStart()
{
startingBalance = Account.Balance;
}
protected void CheckBalance()
{
if (Account.Equity <= startingBalance * BalancePercent)
{
foreach (var pos in Account.Positions)
{
// If(pos.Label == "m10_Robot")
Trade.Close(pos);
}
Stop();
Notifications.SendEmail("xy@domain.net", "xy@domain.net", "DrawDown!", "Robot was stopped! Check It!");
Print("DrawDown!");
}
}
Hope that helps :-)
@Cerunnos