I got it to work this way:
if (SystemPerformance.RealTimeTrades.Count > 0)
{
// Check to make sure there is at least one trade in the collection
Trade lastTrade = SystemPerformance.RealTimeTrades[SystemPerformance.RealTimeTrades.Count - 1];
// Calculate the PnL for the last completed real-time trade
double lastProfitCurrency = lastTrade.ProfitCurrency;
if (lastTrade.Exit.Order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Flat)
{
// Pring the PnL to the NinjaScript Output window
//Print(Time[0] + "The last trade's profit in currency is " + lastProfitCurrency + "Cumulative profit of all trades is: " + " " + SystemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit);
SendMail("*********@txt.att.net", "Last Trade PnL Statement!",string.Format("{0} The last trade's profit in currency is: {1} Profits of all trades is: {2}", Time[0], lastProfitCurrency, SystemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit));
}
}
Did I do this correctly?
Also, two things: Sometimes I don't receive an email until minutes after the trade. And I can't get the real time performance to reset at the close of the session.
Comment