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

Is the "Start Behavior" of "Adopt Account Position" more complicated or dangerous?

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

    Is the "Start Behavior" of "Adopt Account Position" more complicated or dangerous?

    Hi NinjaTrader support,

    I am just wondering why "Adopt Account Position" is treated so differently from the other choices. Here are the three differences I noticed:

    Difference #1. The "Start Behavior" drop-down list of the NinjaTrader 8 Strategy Builder has choices for all Start Behaviors except "Adopt Account Position".

    Difference #2. This "Start Behavior is the only one that requires another line of code to work, namely "IsAdoptAccountPositionAware = true;".

    Difference #3. There are plenty of examples throughout the forums of strategies whose "Start Behavior" was set to "Adopt Account Position" by the combination of the following two lines of code, but all of these examples either used unmanaged order handling or an "else if (State == State.Realtime)" block in the OnStateChange() method:

    Code:
    IsAdoptAccountPositionAware = true;
    StartBehavior = StartBehavior.AdoptAccountPosition;
    Is "Adopt Account Position" missing from the "Start Behavior" drop-down list of Strategy Builder and is this the only "Start Behavior" that requires another line of code to work because it requires more advanced programming by the user or is more dangerous for inexperienced users?

    Are there any examples of a really simple strategy that uses the two lines of code above to successfully have a "Start Behavior" of "Adopt Account Position", or is this "Start Behavior" particularly complicated to implement or dangerous as compared to the other options?

    Thanks in advance,

    EquityTrader

    #2
    Hello EquityTrader,

    Thank you for your post.

    As to your first question, it does require more advanced programming in that it requires you to specifically program the strategy to handle whatever the existing account position is, for example, if you wish to apply protective orders to it. Since setting this to true without specifically programming the strategy can cause issues, we hide it unless IsAdoptAccountPositionAware = true.

    Here's a relatively simple example that will adopt an existing account position and add a stop and target for the adopted position that one of my colleagues made. Note that when imported, it can be found in a folder at the top of the list called "AlanStrategies".

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

    Comment


      #3
      Thanks, NinjaTrader_Kate, for the clear answer and for the simple code sample dealing with protective orders when Start Behavior is set to "Adopt Account Position". I read a bunch of long forum threads and code samples that address this challenge and I wasn't really sure how simple coding for this challenge could be. Thanks again for the simple answer.

      EquityTrader

      Comment


        #4
        Hello:
        I have a 2 bar exit strategy written with
        State == State.SetDefaults
        StartBehavior = StartBehavior.AdoptAccountPosition;
        IsAdoptAccountPositionAware = true;
        Strategy works great to exit if enabled onto a chart with a position. But if enabled when flat, & then I manually enter a position, it will not submit exit order. Is it possible to code a strategy so it can run enabled & flat and then adopt a manual position? Seems like the trouble is the adopting commands are in SetDefaults, so it can't sense a new order coming in. Can something be done to AdoptAccountPositon within OnExecutionUpdate or other method? Thanks!

        Comment


          #5
          Hello Kicks.Spin,

          Thank you for your reply.

          That would be expected, Adopt Account Position will only recognize positions entered prior to starting a strategy. To manage manual orders, you would want to use the AddOn Framework and create a NinjaScript that:
          1. Loops through the Account.Orders collection for the account to find active orders
          2. Subscribes to Account OrderUpdate events to look for any newly opened orders.
          3. Tracks these Orders in the script so they can be changed or cancelled with Account.Change or Account.Cancel
          I have included NinjaTrader 8 documentation on these items below if you wish to investigate further.

          Order object - https://ninjatrader.com/support/help...n-us/order.htm

          Account.Orders - https://ninjatrader.com/support/help...rs_account.htm

          Account.OrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

          Account.Change - https://ninjatrader.com/support/help...-us/change.htm

          Account.Cancel - https://ninjatrader.com/support/help...-us/cancel.htm

          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 TraderBCL, Today, 04:38 AM
          2 responses
          16 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          106 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          609 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          5 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X