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 algospoke, Today, 06:40 PM
          0 responses
          2 views
          0 likes
          Last Post algospoke  
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          6 views
          0 likes
          Last Post maybeimnotrader  
          Started by quantismo, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post quantismo  
          Started by AttiM, 02-14-2024, 05:20 PM
          8 responses
          168 views
          0 likes
          Last Post jeronymite  
          Started by cre8able, Today, 04:22 PM
          0 responses
          8 views
          0 likes
          Last Post cre8able  
          Working...
          X