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

OnPositionUpdate

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

    OnPositionUpdate

    According to the documentation, OnPositionUpdate is called for every change in strategy position.
    Is this for every element of a strategy position?

    A strategy position has a market position: long, short or flat. I'm not questioning these changes.
    But a strategy position also has average price and quantity.

    So for example, assume the strategy position is long 10 contracts.

    Strategy then calls EnterShort(10)

    Managed order system submits order "Close position" to sell 10 contracts ( to get to flat )
    Managed order system submits order "Sell" to sell 10 contracts ( to honor the request to be short 10 ).

    Execution of 1 sell takes place making the market position long 9 contracts.

    Is OnPositionUpdate called at this point?

    The MarketPosition is still long but the averagePrice and quantity are different, right? Is OnPositionUpdate called with these new values at this point?

    The problem I'm trying to solve...

    I have a strategy that is caching execution objects passed in on OnExecutionUpdate. I have 4 execution objects for the entries:
    executionLE1, executionSE1, executionLE2, executionSE2.

    I have logic that uses these execution objects to make decisions. Sometimes a particular trade is only using executionLE1 or SE1 ( no 2nd entry submitted ). In this case the executionLE2 and executionSE2 would be pointing to executions that were part of a previous trade.

    I'm looking for a place/event in the strategy that I can reset these execution objects to null.

    I thought that if the strategy is Flat that it means the trade is over. BUT that might not be the case. The strategy might be transitioning from long to short as part of a reversal and pass through FLAT on its way.

    How can I solve this? Is the only way to do it is in the logic that's deciding that it wants to become long, short or flat? But if the code performs the nulling at that point in time it is occurring before the orders actually execute. There's some chance that not all of the orders will fill and so nulling the execution objects this early would not be a good idea. That is why I'm looking to the callbacks OnPostionUpdate and/or OnExecutionUpdate to handle this.

    Do you have an example that properly caches execution objects for only the current trade?

    #2
    Hello Brillo,

    The position updating the quantity will also cause OnPositionUpdate() to update. The quantity would have to change for the average price to change.

    Also, note that the marketPosition and position.MarketPosition are different.


    Below is a link to an example that resets Order variables to null when the exit order fills.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,404 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    95 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    159 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    8 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X