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

Sync position after restart Strategy

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

    Sync position after restart Strategy

    NT8 provides several following syncing methods but I still need more guidelines.
    https://ninjatrader.com/support/help...rtbehavior.htm

    Here is the scenario: if I have bought 100 shares of IBM stocks either using Strategy or manually, then for any reason, I restarted Strategy. How can I apply my Strategy to sell these 100 (sh) of IBM? Is it possible to use ExitLongLimit() anymore?

    If it is possible that Strategy can obtain this existing 200 share of IBM in my real account, can ExitLong() be used here to sell this 200 (sh) of IBM?
    Last edited by localappleseed; 09-17-2020, 09:58 AM.

    #2
    Hello localappleseed,

    Thank you for your post.

    This could be achieved by specifically programming the strategy to be able to adopt the account position.





    I'm attaching an example strategy made by one of my colleagues that will detect if there is an open position on the account for the instrument the strategy is applied to and submit stop loss/profit target orders to protect that position that should be helpful.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      This is so cool! Thanks a lot.

      Comment


        #4
        Hi, Kate,

        I tried to test this sample code you provided while there is a pending buying order submitted through SuperDOM. It looks like it didn't catch this pending position, is there anything I may have missed?

        protected override void OnBarUpdate()
        {

        if(State ==State.Historical) return;
        Print(State.ToString()+PositionsAccoun t[0].Quantity.ToString());
        Print(PositionsAccount[0].MarketPosition.ToString());


        Here are the outputs:
        Positions in State.DataLoaded:
        Positions in State.DataLoaded:

        Comment


          #5
          Hello localappleseed,

          Thank you for your reply.

          It would not be expected that an unfilled order would be recognized using Adopt Account Position - in fact, if you try to enable the strategy with a pending buy order you should see an error message pop up telling you that it cannot enable the strategy as "Adopt Account Position" requires that there are no working/pending orders on the strategies' instruments in that account.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pibrew, Today, 06:37 AM
          0 responses
          1 view
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          12 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          11 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          15 views
          0 likes
          Last Post AaronKoRn  
          Working...
          X