I have a Strategy that takes an initial position (long or Short) and then adds additional contracts and then covers them throughout the trade all while keeping the initial position open. I use Named orders like LE2, LE3 to establish additional position and then I use named Exits from Entries like LX2, LX3 which match to the entry orders when covering.
My problem is that my Relized profit Calulations don't match what is show in Strategy Tab of Control Center while the trade is still open and don't seem to make sense to me at all.
I think it may have to do with the FIFO and LIFO alogrithims that the functions use, I have the Options-->General--> Use FIFO unchecked
What I do it take the realized profit(loss) + the unrealized profit(loss) and if it is above a certain level I want to exit and stop trading for the day.
Any help would be appreciated.....
Here is my code:
DoneTrading = false;
TdyTotalRealizedProfitLoss = Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit;
if ( Position.Quantity > 0 )
CurUnRealizedProfitLoss = Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
else
CurUnRealizedProfitLoss = 0;
TdyTotalNetProfitLoss = (TdyTotalRealizedProfitLoss + CurUnRealizedProfitLoss );
if ( TdyTotalNetProfitLoss < 0 && Math.Abs(TdyTotalNetProfitLoss) >= DailyLossLimit )
{
OkToTradeNow = false;
DoneTrading = true;
if ( Position.MarketPosition == MarketPosition.Long )
ExitLong();
if ( Position.MarketPosition == MarketPosition.Short )
ExitShort();
Alert("LossLimit", NinjaTrader.Cbi.Priority.High, "Loss Limit Exceeded, Done Trading Today", "Alert3.wav", 3, Color.Black, Color.Yellow);
}
Comment