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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X