Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Waxavi, 04-19-2024, 02:10 AM
    2 responses
    37 views
    0 likes
    Last Post poeds
    by poeds
     
    Started by chbruno, Yesterday, 04:10 PM
    1 response
    44 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Max238, Today, 01:28 AM
    1 response
    23 views
    0 likes
    Last Post CactusMan  
    Started by giulyko00, Yesterday, 12:03 PM
    2 responses
    10 views
    0 likes
    Last Post giulyko00  
    Started by r68cervera, Today, 05:29 AM
    0 responses
    4 views
    0 likes
    Last Post r68cervera  
    Working...
    X