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

Getting confused about the Account object

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

    Getting confused about the Account object

    Hi everyone,

    While I started out using the AtmStrategyCreate and AtmStrategyChangeStopTarget calls, I didn't bother with the Account object and when I did that, it seems like the order was submitted based on the Account selected on the Chart Trader.

    However, I decided to "improve" my strategy and I messed around with things like "Account.OrderUpdate += OnOrderUpdate;" - now it seems like the order will be submitted based on the account that the strategy was configured with; which is not what I want.

    I would really like to "get back" to the original state of submitting my order based on the account selected on Chart Trader (and not the account configured for the Strategy) - may I know how I can do that (and yes, I still need the OrderUpdate notifications).

    Thanks for your help.



    #2
    Hello mav8rick,

    Thanks for your post.

    Using Atm methods in a NinjaScript strategy does not submit orders to the account selected in the Chart Trader Account drop-down menu. The strategy will submit orders to the account that it is set to run on when enabling the strategy.

    For example, say you have two Sim accounts, Sim101 and Sim102. Say you would like to enable the strategy on the Sim102 account. You would right-click on a chart, select Strategies, select your strategy from the Available section, set the Account drop-down menu to Sim102, check the enable box, and click OK.

    Similarly, if you wanted to have the strategy place orders on the Sim101 account, you would set the Account drop-down menu to Sim101 when enabling your strategy.

    If you are using the Account class, you could find the name of the account you want to subscribe to in your script. See below from the help guide page example. Note that you will still need to ensure that the strategy is running on the correct account when enabling it. For example, if you want to find the Sim101 account, you would use the code below and also ensure that you are enabling your strategy on the Sim101 account.

    Code:
     // Find our Sim101 account
    
            lock (Account.All)
    
                  account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
    
    
             // Subscribe to order updates
    
            if (account != null)
    
                  account.OrderUpdate += OnOrderUpdate;
    Account: https://ninjatrader.com/support/help...ount_class.htm
    OrderUpdate: https://ninjatrader.com/support/help...rderupdate.htm

    Let us know if we may further assist.
    Last edited by NinjaTrader_BrandonH; 08-03-2021, 07:55 AM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the clarification Brandon.

      I assume that if I do want to submit an order based on the ChartTrader's account selection, I would have to switch to using StartAtmStrategy instead?

      Comment


        #4
        Hello mav8rick,

        Thanks for your note.

        StartAtmStrategy() could be used to submit entry orders with ATM strategies. It does not specify the account that the orders are submitted to.

        As seen in the StartAtmStrategy() help guide example linked below, you would need to subscribe to the account that you would like your order submitted to.

        StartAtmStrategy(): https://ninjatrader.com/support/help...tmstrategy.htm

        If you would like to submit orders to the account selected in Chart Trader, see the attached example script which demonstrates how to get the account set in the Chart Trader Account drop-down menu and submit an order to that account using StartAtmStrategy().

        Also, see the help guide documentation below for more information.
        ChartControl: https://ninjatrader.com/support/help...artcontrol.htm

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you Brandon.
          The only issue with the StartAtmStrategy part is that you have to create the Order object with the quantities first. To summarize:

          AtmStrategyCreate
          • Orders are submitted based on the account the strategy was configured with
          • You can't get at the instance of the AtmStrategy created - you just have a string ID and limited calls
          • You don't have to mess with the quantity for an order because the quantity is ALWAYS lifted off the ATM strategy template (that is written to disk)


          StartAtmStrategy
          • You can choose the account to submit the the order on
          • However, you have to specify the order quantity even though you can't really get at the quantity as specified in the ATM strategy template
          • You get back the reference to the AtmStrategy instance that you can use for further manipulation

          I just want to be able to submit an order based on the account as listed on ChartTrader using AtmStrategyCreate (so that I don't have to fiddle with the order quantity) but I guess you're saying that this is not possible. I just hope the designers/developers can see the funny mismatch between the 2 aka I don't see why the 2 should work so differently since I'm sure that AtmStrategyCreate ends up using the same underlying calls that StartAtmStrategy is using.

          Is it possible to "force" the Account the strategy is using just by "re-assigning" it at runtime e.g. "Account = accountSelector.SelectedAccount;" and then use AtmStrategyCreate? What would happen if I did?

          Update: yeah - it works (not sure if supported) - just reassign the current Account
          Last edited by mav8rick; 08-03-2021, 01:07 PM.

          Comment


            #6
            Hello mav8rick,

            Thanks for your note.

            It would not be possible to change the account that the strategy is applied to while the strategy is running. Strategies are meant to run on the account that they are enabled on.

            To specify which account an ATM template is applied to, you would need to use the AddOn approach StartAtmStrategy() method.

            If you would like to use the order quantity from Chart Trader, you could get that value using ChartControl.OwnerChart.ChartTrader.Quantity. For example, see below.

            Code:
            ChartControl.Dispatcher.InvokeAsync((Action)(() =>
            {
                int orderQty = ChartControl.OwnerChart.ChartTrader.Quantity;
                Print(orderQty);
            }));
            Or, you could use the default quantity that the strategy has set. See the help guide page below.

            DefaultQuantity: https://ninjatrader.com/support/help...ltquantity.htm

            Is it possible to "force" the Account the strategy is using just by "re-assigning" it at runtime

            Please note that this would not be recommended. If you decided to take this approach and there is a problem, we cannot provide assistance with this use case. The account is not meant to be reassigned and we do not know what consequences that may carry.

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thank you for the detailed answer.
              As a last word on this, may I suggest that the future refinements of AtmStrategyCreate be focused on providing programmatic access to Chart Trader. There are a lot of limitations with AtmStrategyCreate e.g. you can't change the quantity (it will always read off the template) and you can't get references to the underlying instantiated AtmStrategy etc. Therefore, AtmStrategyCreate - should IMHO - be focused on helping us work with Chart Trader and therefore, most of the parameters e.g. the account, the strategy etc. should be lifted off the Chart Trader interface once AtmStrategyCreate is initiated.

              For use cases where a lot more flexibility is required then StartAtmStrategy would be used but the difference would be that StartAtmStrategy just use an initial template to "spark off" the trade but the rest of the management is expected to be managed by the underlying code and less by the defined template.

              Comment


                #8
                Originally posted by NinjaTrader_BrandonH View Post
                If you are using the Account class, you could find the name of the account you want to subscribe to in your script. See below from the help guide page example. Note that you will still need to ensure that the strategy is running on the correct account when enabling it. For example, if you want to find the Sim101 account, you would use the code below and also ensure that you are enabling your strategy on the Sim101 account.
                Code:
                // Find our Sim101 account
                
                lock (Account.All)
                
                account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
                
                
                // Subscribe to order updates
                
                if (account != null)
                
                account.OrderUpdate += OnOrderUpdate;
                Hello Brandon,

                I would like to use the account class with the activated account. I tried to code the following:

                Code:
                // Find our Sim101 account
                
                lock (Account.All)
                
                account = Account.All.FirstOrDefault(a => a.Name == Account.Name);
                
                
                // Subscribe to order updates
                
                if (account != null)
                
                account.OrderUpdate += OnOrderUpdate;
                Using the code above, the strategy will disappear from the list of strategies. What is wrong in the code?

                Kind regards
                Gerik

                Comment


                  #9
                  Hello Gerik,

                  This is Jim responding on behalf of Brandon who is out of the office at this time.

                  Why are you trying to get a private account object when the strategy already has an account object called Account?

                  I am not sure if you are trying to listen to Account level OrderUpdate events in the strategy, but if you are, please see the example I attached here. (Notice that I am using a different method to subscribe to the Account.OrderUpdate event in order to not conflict with the strategy level OnOrderUpdate method.)

                  If you are just trying to get strategy level OrderUpdates, you can simply override OnOrderUpdate.

                  OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

                  Attached Files
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by zstheorist, Today, 07:52 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post zstheorist  
                  Started by pmachiraju, 11-01-2023, 04:46 AM
                  8 responses
                  150 views
                  0 likes
                  Last Post rehmans
                  by rehmans
                   
                  Started by mattbsea, Today, 05:44 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post mattbsea  
                  Started by RideMe, 04-07-2024, 04:54 PM
                  6 responses
                  33 views
                  0 likes
                  Last Post RideMe
                  by RideMe
                   
                  Started by tkaboris, Today, 05:13 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post tkaboris  
                  Working...
                  X