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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X