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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    48 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X