What is the best/recommended way to do something similar for live/real-time trading? Is there a way to programmatically get a running history of the account balance? I can probably get the cumulative net profit in similar fashion using SystemPerformance.RealTimeTrades.TradesPerformance .NetProfit, but for that to work I need to know the original starting balance and I don't see how to do that.
I should also mention that this is an intraday strategy and I tend to restart each morning, so keeping track of this in the runtime process like the backtest affords isn't a viable solution.
if (State == State.Historical)
{
if (SystemPerformance.AllTrades.Count > 0)
{
double netProfit = SystemPerformance.AllTrades.TradesPerformance.NetProfit;
AccountBalance = 100000 + netProfit;
PeakAccountBalance = Math.Max(PeakAccountBalance, AccountBalance);
Drawdown = AccountBalance - PeakAccountBalance;
DrawdownPct = Drawdown / PeakAccountBalance;
if (USE_COMPOUNDING == false)
{
DrawdownPct = Drawdown / 100000;
}
MaxDrawdown = Math.Min(Drawdown, MaxDrawdown);
MaxDrawdownPct = Math.Min(DrawdownPct, MaxDrawdownPct);
if (Bars.IsLastBarOfSession)
{
MaxClosingDrawdown = Math.Min(Drawdown, MaxClosingDrawdown);
MaxClosingDrawdownPct = Math.Min(DrawdownPct, MaxClosingDrawdownPct);
}
}
}

Comment