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

Real misunderstanding of GetRealtimeOrder() to restore current AccountPosition

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

    Real misunderstanding of GetRealtimeOrder() to restore current AccountPosition

    For some days i really try to understand how i have to use GetRealtimeOrder() to restore current AccountPositions to Strategy.
    I have generated a general Strategy for all test that i can imagen on real money and account but nothing works like expected. :-(

    Strategy is very simple:
    Opens a LONG-Position by (EntryLong) on every (10, 20, 30, 40, 50) Minute for every Hour and holds this position für 5 Minutes.
    If time if the current bar is (05, 15, 25, 35, 45, 55) Minute, LONG-Position would be closed by (ExitLong).

    Start behavior for Strategy is set to (StartBehavior.ImmediatelySubmitSynchronizeAcco unt)!

    While position was opened and still existing on account-side, i stop running strategy and restart them within 5 seconds.
    With that activity i want to simulate any type of server or connection error.

    Me expectation for NT respectively current strategy is, that current account position would be matched to strategy position and position administered by strategy while state (RealTime) is reached.
    At the moment current account position would closed if i restart strategy and i don't understand why this happens!!!

    I have read all documentation for several states and also use GetRealtimeOrder() convert any old historical order object references to the new live order on real-time account.


    Is there somebody out there that can help me to modify current code to excepted result?
    This would be gorgeous... :-)


    With best regards,
    Phil
    Attached Files

    #2
    Hi Phil, thanks for writing in.

    GetRealTimeOrder is used to sync up resting orders that the strategy has made in the past when it gets reset, your strategy is only submitting market orders so that would not be applicable. If you want to adopt the account position then set IsAdoptAccountPositionAware to true and the startup behavior to AdoptAccountPosition. If the strategy calculates it should have been in a position in the historical data that carries over to real-time, then ImmediatelySubmitSyncAccount should work. You can test that it does work by testing the SampleMACrossover strategy. If you are seeing the account position sync on SampleMACross but not your strategy, I would recommend making a copy of your strategy and reducing it down to find the problem.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      thanks for your fast feedback!
      I was very close to your advice.
      Related code was already implemented just right combination of parameters was mising...

      IsAdoptAccountPositionAware = true; //to list in UI StartBehavior box
      StartBehavior = StartBehavior.AdoptAccountPosition;


      I directly tested this parameter set live on account.
      It works like you've told, but not enough for my understanding of security.

      Strategy has open a new positionen.
      I stopped strategy and restart them while 5 second.
      Strategy adopts current position from account. OK!

      Then i closed current position manually to be aware, that strategy handles this new position "size" from account.
      Strategy keeps running, but (Position.Quantity) seems not the same then (PositionAccount.Quantity).
      Position.Quantity = 1
      PositionAccount.Quantity = 0

      While Position.Quantity seems not updated by new PositionAccount.Quantity, strategy keeps running but NOT reacting by implemened rules. (Close on Minute 05, 15, 25 etc.)

      How can i force an update on account-side to strategy for some kind of recalculation?
      May i have to retrigger some state like initial strategy loading?


      Cheers,
      Phil
      Attached Files
      Last edited by PWidera; 05-20-2021, 11:47 AM.

      Comment


        #4
        I want to reach maximal resilience for strategy and system.
        Is something went wrong, data from account (real money) should be the leader for any decision by strategy.
        Last edited by PWidera; 05-20-2021, 11:52 AM.

        Comment


          #5
          Hi Phil, thanks for your reply.

          If your strategy position is out of sync with the account position, go to the Strategies tab of the Control Center>Right click the strategy>Syncronize all Strategies. This will force the account to synchronize to the strategy position. There is no way of doing this programmatically. If the strategy goes out of sync by manual intervention or other means this procedure will need to be done.

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            I really enjoy your handy pragmatism!
            This helps me out alot.
            Thanks for your post...

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X