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 aa731, Today, 02:54 AM
    0 responses
    4 views
    0 likes
    Last Post aa731
    by aa731
     
    Started by thanajo, 05-04-2021, 02:11 AM
    3 responses
    470 views
    0 likes
    Last Post tradingnasdaqprueba  
    Started by Christopher_R, Today, 12:29 AM
    0 responses
    10 views
    0 likes
    Last Post Christopher_R  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    166 responses
    2,237 views
    0 likes
    Last Post sidlercom80  
    Started by thread, Yesterday, 11:58 PM
    0 responses
    5 views
    0 likes
    Last Post thread
    by thread
     
    Working...
    X