Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Break Even in OnOrderUpdate

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

    Break Even in OnOrderUpdate

    I am using OnExecution to trigger submission of stop/target orders.
    When I raise the stop-loss order to breakeven in OnBarUpdate nothing happens.
    I know it has to do with the code below (from the SampleOnOrderUpdate) that shows only the EntryLong order. When I comment the lines for ExitShort order everything works just fine.

    if (entryOrder != null && entryOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    // Stop-Loss order 10 ticks below our entry price
    stopOrder = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice-(10*TickSize), "StopEL1", "EL1");

    // Stop-Loss order 10 ticks above our entry price
    stopOrder = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice+(10*TickSize), "StopES1", "ES1");

    // Target order 50 ticks above our entry price
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 50 * TickSize, "TargetEL1", "EL1");

    // Target order 50 ticks below our entry price
    targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 50 * TickSize, "TargetES1", "ES1");

    // Resets the entryOrder object to null after the order has been filled or partially filled
    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    entryOrder = null;
    }
    }
    }

    #2
    Maarten, this is very likely a coding issue in your script – as you’re using the same IOrder object for the Long and Short side here, I would recommend using a dedicated object per side.

    Also, please ensure the reset parts as outlined in the sample script are working in your code as expected as well, best is to print all states associated with the object to debug your custom code modifications.

    For tips on debugging, please check this tip out:

    http://www.ninjatrader.com/support/forum/showthread.php?t=3418
    Vince B.NinjaTrader Customer Service

    Comment


      #3
      I already thought about using a dedicated object per side and that fixed it.
      Thanks for your reply.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      368 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      571 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X