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

AdoptAccountPosition

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

    AdoptAccountPosition

    Hi,
    I've been testing AdoptAccountPosition so that a strategy can recover from a stoppage.

    When the strategy is stopped, it leaves a position in the account and working orders in the account. That's ok - the intention is that AdoptAccountPosition will be able to recover from this.

    AdoptAccountPosition fails in this scenario.

    It is only if no orders are active in the Account that AdoptAccountPosition successfully creates a virtual execution and gets the strategy in sync.

    Note that these orders I am talking about here are from the strategy itself. Other orders (such as those manually placed) create a warning that the strategy cannot be started. I'm fine with that, but I do want the strategy to successfully sync when its own orders from earlier are still working in the account.

    You can see the fail in the text below.

    Over to you.
    Thanks,
    saltminer


    TestOrderRecoveryFromAccount state=Transition
    ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'


    DiscoveringAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30'
    Sim101 found working order orderId='bf082caace724b02a13037ab7b90b9ae' account='Sim101' name='LS' orderState=Accepted instrument='AUDUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=0.75266 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1660 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'
    Sim101 found working order orderId='f5466b8b22714dc4ae3e063c7f4ec2f5' account='Sim101' name='LT' orderState=Working instrument='AUDUSD' orderAction=Sell orderType='Limit' limitPrice=0.75346 stopPrice=0 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1661 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'

    Enabling NinjaScript strategy 'TestOrderRecoveryFromAccount/123813582' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Default quantity ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes

    ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'

    #2
    Hello saltminer,

    Thank you for your note.

    Without the full code we're unable to test on our end.

    If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

    You may also be interested in the following link in our helpguide,


    As well as a Adapt Account Position Strategy sample I have attached which will submit a PT and SL when started should the account/instrument the strategy was started on have an open position, say through a superdom trade. When you disable the strategy the PT and SL orders remain working, but when you reenable the strategy they are canceled.

    I look forward to your reply.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      point proven

      Hi Alan,
      your example strategy demonstrates the problem perfectly.

      I changed Calculate to OnEachTick and enhanced the print statements like this:


      Print("PositionAccount:");
      Print(State.ToString()+PositionsAccount[0].Quantity.ToString());
      Print(PositionsAccount[0].MarketPosition.ToString());

      Print("PositionStrategy:");
      Print(State.ToString()+Positions[0].Quantity.ToString());
      Print(Positions[0].MarketPosition.ToString());

      Perform the following steps and you'll see AdoptAccountPosition fail.
      1. * Open a position manually
      2. * Enable the strategy. It correctly adopts the account position, and puts on some orders.
      3. * Disable the strategy.
      4. * Enable the strategy. The orders cancel, and the strategy fails to adopt the account position.


      The first time you run the strategy (step 2) it prints out this:

      PositionAccount:
      Realtime10000
      Long
      PositionStrategy:
      Realtime10000
      Long

      The second time you run the strategy (step 4) it prints out this:

      PositionAccount:
      Realtime10000
      Long
      PositionStrategy:
      Realtime0
      Flat

      Regards,
      saltminer

      Comment


        #4
        Hello saltminer,

        I am able to replicate and will follow up when I have more information.

        Thank you for your patience.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          I'm in the middle of a project that is hinging on this feature. Do you have a timeline on a fix or even just news on this issue?
          Thanks.

          saltminer

          Comment


            #6
            Hello saltminer,

            Thank you for your response.

            The fix is planned for implementation in the next release of NinjaTrader 8. I do not have a time frame for the release.

            Please let me know if you have any questions.

            Comment


              #7
              any news?

              Hi Patrick,
              any idea when this fix might be coming? I have a paid project just circling the airport...
              Thanks,
              saltminer

              Comment


                #8
                Hello saltminer,

                Thank you for your post.

                This matter was resolved in NinjaTrader 8.0.14.0. The ID for this item was 12795 which you can look up in the Release Notes at the following link: https://ninjatrader.com/support/help...s/8_0_14_2.htm

                Please let me know if you have any questions.

                Comment


                  #9
                  Hello Patrick,
                  the matter may have been "resolved", but unfortunately I don't believe that means "fixed".

                  When using AdoptAccountPosition now, strategies are not allowed to start if there are working orders in the Account. The following message is given:

                  <strategy name> could not be enabled because the ‘Start behavior’ parameter 'Adopt account position' requires that there are no working orders on this strategy's instrument(s) in 'Sim101'. Please cancel any working orders on the same account-instrument combo(s) first to be able to enable your strategy.

                  So this problem has not been fixed, merely avoided. This is unhelpful, as strategies will want to adopt both an Account Position and working orders.
                  Please put this issue back into your work queue for a proper fix.

                  saltminer

                  Comment


                    #10
                    Hello saltminer,

                    Are you suggesting that previous to the fix, you could have working orders on the account and start the strategy?

                    The issue you describe here was resolved, or fixed, was it not?
                    Support for the development of custom automated trading strategies using NinjaScript.


                    If no to question 1 and yes to question 2, then would you agree this is a feature request? "Allow strategies to adopt Account Position and working orders".

                    I look forward to your reply.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi,
                      of this list, #4 is now not possible. The strategy is not allowed to start with orders in the account.


                      * Open a position manually
                      * Enable the strategy. It correctly adopts the account position, and puts on some orders.
                      * Disable the strategy.
                      * Enable the strategy. The orders cancel, and the strategy fails to adopt the account position.

                      As a feature request "Allow strategies to adopt Account Position and working orders" might be overreaching. A properly coded strategy could find working orders in the Account and do stuff with them. However, we are now prevented from doing that.
                      The latest update was not a bugfix, but a bug firewalled away from the user.

                      So my feature request is "Reinstate the ability for a strategy using AdoptAccountPosition to be enabled while orders are active in the Account".

                      Thanks,
                      saltminer

                      Comment


                        #12
                        Hello saltminer,

                        I open a position, enable the strategy which submits PT/SL. Disable and Reenable the strategy, the orders are canceled and then resubmitted.

                        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                        Is this not the behavior you are seeing?

                        I look forward to your reply.
                        Attached Files
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Alan,
                          I recreated your test successfully. I also noted that if manual orders are placed in the account, the test is NOT successful. It seems only orders created by the strategy itself are allowed.
                          BUT, now try doing your test but additionally quitting NT8 and restarting with the open position and working orders, and try to enable the strategy. This would simulate a crash or computer restart or a weekend.
                          You aren't allowed to enable the strategy from the Control Centre (clicking the enable checkbox does nothing) and if you go to the chart to enable it the error message in the screenshot arrives, forbidding strategy startup.

                          saltminer
                          Attached Files

                          Comment


                            #14
                            Hello saltminer,

                            I also noted that if manual orders are placed in the account, the test is NOT successful.
                            It was not clear from your instructions that these were manually placed orders.

                            Enable the strategy. It correctly adopts the account position, and puts on some orders.
                            This is expected behavior per the helpguide,

                            The account and instrument the strategy is started on must not have any working orders which were submitted outside of the strategy, or by another instance of the same strategy. If an order is detected, the strategy can not be started until these orders have been manually managed.
                            https://ninjatrader.com/support/help...ccountPosition

                            Would you agree the bug below was resolved?
                            Support for the development of custom automated trading strategies using NinjaScript.


                            Regarding restarting NinjaTrader and the strategy not enabling, I'm currently looking into this and will follow up when I have additional information.
                            Alan P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello saltminer,

                              I submitted a bug report for the behavior where after a NT restart the strategy will not start.
                              Alan P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X