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

Strategy.Position delay in updating?

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

    Strategy.Position delay in updating?

    I am writing an unmanaged order handler and part of its job is to place a stop loss as soon as the entry order is filled.

    My order of operations are:
    1. SubmitOrderUnmanaged(....my entry order....)
    2. OnOrderUpdate is called with OrderState.Filled
    3. Immediately look to place stoploss by looking at Position.MarketPosition


    The problem is that Position.MarketPosition is returning MarketPosition.Flat and thus the stop is not being placed immediately. Is there any delay in the Strategy.Position being updated? I can simply look at the order itself but wondering why this field is not updated as I rely on it in several other places.

    #2
    Putting some debug code together shows that the Position still shows Flat until the next incoming tick....would it not be ideal to update the strategy position before NT calls the onorderupdate with a fill? Perhaps there is some other reason as to why it is not this way.

    Comment


      #3
      Hello FxRichard,

      Thank you for your note.

      Within OnOrderUpdate section of the helpguide you’ll see,

      Critical: If you want to drive your strategy logic based on order fills you must use OnExecutionUpdate() instead of OnOrderUpdate(). OnExecutionUpdate() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecutionUpdate() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().



      Its suggested you use OnPositionUpdate(),


      I have attached a sample strategy which if you apply to a 10 second chart and pull up an output window, you’ll see that while OnOrderUpdate prints flat OnOrderExecution/OnPositionUpdate will print a position reflecting the most recent fill.

      Please let us know if you need further assistance.
      Attached Files
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Thanks Alan, somehow missed that info.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by techgetgame, Today, 11:42 PM
        0 responses
        7 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Today, 11:36 PM
        0 responses
        1 view
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,612 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Working...
        X