I have used the Visual Studio debugger to trace the operation of my strategy, but with no success. The following is the event handler for OnOrderUpdate(). The ProfitTarget variable is set properly in this method, which indicates that the market position was long when the order filled.
protectedoverridevoid OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder == order)
{
if (order.OrderState == OrderState.Filled)
{
if (Position.MarketPosition == MarketPosition.Long)
{
ProfitTarget = Position.AvgPrice + DATR;
StopLoss = Position.AvgPrice - (double)CnterStopLoss * TickSize;
}
elseif (Position.MarketPosition == MarketPosition.Short)
{
ProfitTarget = Position.AvgPrice - DATR;
StopLoss = Position.AvgPrice - (double)CnterStopLoss * TickSize;
}
entryOrder = null;
}
}
elseif (exitOrder != null && exitOrder == order)
{
if (order.OrderState == OrderState.Filled)
exitOrder = null;
}
}
However, at no point after the OnOrderUpdate() method runs, does the market position indicate anything but flat. This prevent my PositionExit() method from executing.
protectedvoid PositionExit()
{
if (Position.MarketPosition != MarketPosition.Flat)
{
SetProfitTarget(CalculationMode.Price, ProfitTarget);
if ((TradingStates & States.AllowReversal) == States.AllowReversal)
{
TradingStates ^= States.AllowReversal; //Disable reversals
if (Position.MarketPosition == MarketPosition.Long)
exitOrder = EnterShortStop(StopLoss);
elseif (Position.MarketPosition == MarketPosition.Short)
exitOrder = EnterLongStop(StopLoss);
}
}
}
When I look at the chart, I find that the limit order position is immediately closed by a profit target order at the entry price. I cannot tell where this profit target order is coming from! Any suggestions as to how to track down this phantom profit target order?

Comment