Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Operator Logic Question for OnOrderUpdate

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

    Operator Logic Question for OnOrderUpdate

    Hello Ninjatrader staff, hope you had a great weekend.

    My goal is to have my strategy do the same thing for an Order whether the Order is Filled completely or whether the Order is Partially Filled, and I'm wondering specifically if the || operator works in this scenario.

    if (LongTrade != null && LongTrade == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    {
    TP
    SL
    }
    }

    Thank you for your time, I look forward to your reply.

    #2
    Hello GLFX005,

    Thanks for your post.

    You can use an OR operator to check if the order state is filled or part filled. Your condition is checking execution.Order.OrderState which would not be valid on OnOrderUpdate. You could check order.OrderState instead if you would like.

    execution.Order.OrderState would be checked from OnExecutionUpdate. for a complete example that uses OnOrderUpdate and OnExecutionUpdate for submitting profit targets and stops, and have the target and stop protect an entry that develops from partial fills, please see the SampleOnOrderUpdate strategy. We recommend using OnExecutionUpdate for submitting stop loss and profit target orders when using Exit methods for target/stop. The strategy's Position object is also updated based on executions and can be read in OnExecutionUpdate.

    Set methods should be used in OnBarUpdate or OnStateChange. If used in OnBarUpdfate, the price levels for the Set methods should be reset to their intended initial levels before the next entry is made. (Set methods prep NinjaTrader to submit target/stop when NinjaTrader sees the execution of those orders. See SamplePriceModification for best practices when using Set methods in OnBarUpdate.) We would not recommend using Set methods in OnOrderUpdate or OnExecutionUpdate.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X