Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Phantom profit target order

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Phantom profit target order

    I am getting strange order entry behavior with a strategy that I am developing. On the first day of trading, the limit order and profit-target order work just as I expect them to work. On the next day of trading, the same limit order (same name) is issued, but the position is closed by a profit target order at the entry price. It is as if there is a profit target order waiting to be filled when I place the limit order. However, I have the ExitOnClose property set true. I also checked to ensure that I am flat in the market before placing the limit order. A number of days behave this same way, but other days work as I expect them to work.
    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?

    #2
    seeker579, it would be best if you debugged your script with TraceOrders turned on in Iniatilize() -



    Likely the old reset to price when flat produces this not intended profit taking, you should reset to a default offset in ticks when being flat.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, Yesterday, 01:02 PM
    0 responses
    29 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    21 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    160 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    95 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    148 views
    2 likes
    Last Post CaptainJack  
    Working...
    X