Max Historical Equity
Max Historical Equity
28 Jun 2016, 02:59
How to calculate the max historical equity? It'd be nice if HistoricalTrade had Equity property besides the Balance property .
Equity Chart actually shows it but there is no way to access it, or is there?
Replies
ChasBrownTH
06 Jul 2016, 04:33
RE: Memory Manager
PS - I use your Memory manager BOT and it is excellent ! Thank you for sharing it. ;)
@ChasBrownTH
galafrin
06 Jul 2016, 10:30
RE:
moneybiz said:
How to calculate the max historical equity? It'd be nice if HistoricalTrade had Equity property besides the Balance property .
Equity Chart actually shows it but there is no way to access it, or is there?
After downloading through backtesting M1 bars of each symbol traded from the very first trade, then browse historical trades in sync with files to rebuild trades in parallell. :()
@galafrin
ChasBrownTH
06 Jul 2016, 04:28
I have been wrestling with the same sort of problems, but in the end I think I found a workable solution. I wanted to be able to run extensive Optimisation cycles then analyse ALL the results, not just the top 20. So I use mySQL to keep very comprehensive records, then analyse it all externally, using my own Delphi creation. ;)
I can also re-create all the Equity Charts I want now, which makes it much easier to see what happened.
First I tried adding code into OnStop(), that wrote details of the BackTests out to mySQL, which works up to a point, BUT does not have access to trade.Equity.
Now I have added code into OnPositionsClosed() that does the trick, by being able to get the Account.Balance and Account.Equity for each trade as it happens.
Incidentally Account.Equity is the same as (Account.Balance + Account.UnrealizedNetProfit), not that it helps in this case though.
For your specific case, ie. seeking the max historical equity?, then you could just keep a running total from within OnPositionsClosed()
ie. something like this: [ first create a couple of global Vars, such as MaxEquity & MinEquity, also initialize them in OnStart() ie. MaxEquity = Account.Balance etc ]
private void OnPositionsClosed(PositionClosedEventArgs args)
{
if (Account.Equity > MaxEquity)
{ MaxEquity = Account.Equity }
if (Account.Equity < MinEquity)
{ MinEquity = Account.Equity }
}
I think that ought to work ? ;)
my own working example collects everything: [ sample here, or at least the key parts of it ]
/// <summary>
/// OnPositionsClosed - called after every Order is closed
/// </summary>
/// <param name="args"></param>
private void OnPositionsClosed(PositionClosedEventArgs args)
{
if (IsBacktesting)
{
// mysql query to report backtest Trade HISTORY
string query = "INSERT INTO backtest_history (uniqueid, finished, Balance, Equity, balunreal, Trades, BotVer) VALUES ('" + strUniqueBacktestID + "','" + Server.Time.ToUniversalTime() + "','" + Math.Round(Account.Balance, 2).ToString("0000000.00") + "','" + Math.Round(Account.Equity, 2).ToString("0000000.00") + "','" + Math.Round((Account.Balance + Account.UnrealizedNetProfit), 2).ToString("0000000.00") + "','" + History.Count.ToString() + "','" + BotVer.ToString() + "')";
// add copy to Log file for easy viewing
Print("OnClosed: " + query);
OpenSQLconnection();
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, mySQLconnection);
//Execute command
cmd.ExecuteNonQuery();
// cleanup mySQLconnection
CloseSQLconnection();
}
I hope this helps? One limitation is that I have to dump the history of losing sequences, since I see no way to filter them.
But using OnStop I can have
if ((NetProfit > 0) && (Account.Equity > 0))
{
foreach (HistoricalTrade trade in History)
{
BUT no access to the all important trade.Equity figure .. maybe Spotware will add it to the History collection sometime in the future ?
@ChasBrownTH