Here is the portion of the code i use in the OnBarUpdate event. Attached to this comment, there are two screen captures. One shows the Tab order in Ninja showing a buy order with a small profit and the results returned by the GetAtmStrategyRealizedProfitLoss command in the output window. The problem occurs when i close the trade manually by pressing the Close button with the middle mouse button. Any idea wha's going on?
#region MonitorOrderStatus
//-
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
if (status.GetLength(0) > 0)
{
if (status[2] == "Filled") {
IsTradeFilled = true;
IsStopReadyToMove = true;
countOnBarUpdateSinceTradeFilled = -1;
}
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
}
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
{
// when the trade is over, record the PnL
PnL_atmStrategy = GetAtmStrategyRealizedProfitLoss( atmStrategyId );
Print("PnL_atmStrategy read: " + PnL_atmStrategy + " at bar " + CurrentBar);
// reset the strategy id
atmStrategyId = string.Empty;
}
//-
#endregion

Comment