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

Indicator code snippets to get Account, Quantity, ATM from ChartTrader?

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

    Indicator code snippets to get Account, Quantity, ATM from ChartTrader?

    Can someone share Indicator code snippets to get Account, Quantity, ATM from ChartTrader?

    (Ninja 8)

    thanks

    #2
    Hello vantojo,

    Thanks for opening the thread.

    Please try the following:

    Code:
    ChartControl.Dispatcher.InvokeAsync(new Action(() =>
    {
        Print(ChartControl.OwnerChart.ChartTrader.Account.Name);
        Print(ChartControl.OwnerChart.ChartTrader.Quantity);
        Print(ChartControl.OwnerChart.ChartTrader.AtmStrategy.Template);
    }));
    We look forward to assisting.
    Last edited by NinjaTrader_Jim; 01-12-2021, 02:36 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      I'm getting an "object reference not set to an instance of an object"

      Comment


        #4

        also, I'm using Invoke instead of InvokeAsync as I need the following code to be executed sequentially after this assignment

        Comment


          #5
          the problem is this

          ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate

          I am getting a null reference

          I get the Account and Quantity OK


          Comment


            #6
            ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate

            Comment


              #7
              Hello vantojo,

              Using Invoke instead of InvokeAsync is known to cause deadlock issues. You should use InvokeAsync. Please see the detail below.

              Multi Threading Considerations - https://ninjatrader.com/support/help...-threading.htm

              I don't get a null reference exception when I use InvokeAsync.

              You could consider using a timer to add a small delay for your code when invoking the dispatcher to allow the dispatched code to complete, but I would also suggest testing if it is necessary for your purposes since checking these properties from the dispatcher should be very fast.

              You could also consider capturing the current values with InvokeAsync in State.DataLoaded and also capturing the control via AutomationID. Then you could consider subscribing to SelectionChanged events for the control to pick up on changes that are made after start up.

              The thread below discusses capturing ChartTrader Controls via AutomationID.

              https://ninjatrader.com/support/foru...lected-account

              Documentation on using these control in NinjaScript can be found here - https://ninjatrader.com/support/help...8/controls.htm

              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello Jim,

                I can't put a delay in this because I'm submitting an OIF to place an order.

                (This method is already much slower than a hot key, but there is no hot key to get a mouse click at a certain price / chart point. But it is the only way I know to submit a Limit Order at a specific price)

                in Ninja 7 I did this and it works well

                AccountName = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"].Text;
                Quantity = Convert.ToInt32(((NumericUpDown)ChartControl.Contr ols["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["nudQuantity"]).Value);
                ATM_Name = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboStrategy"].Text;

                In NT8 I took out the Dispatcher code...why do I need it?

                I have this now

                AccountName = ChartControl.OwnerChart.ChartTrader.Account.Name;
                Quantity = ChartControl.OwnerChart.ChartTrader.Quantity;
                ATM_Name = ChartControl.OwnerChart.ChartTrader.AtmStrategy.Na me;

                I get the AccountName and Quantity fine with this, but not the ATM_Name....it works sometimes and sometimes not. Sometimes I get a null reference and other times there is an error that it cannot load the ATM even though it is there in the list and also in the Ninja directory.

                There should be a simple way like I did in NT7???

                Thanks

                Comment


                  #9
                  Maybe you will ask why I use an OIF instead of Submit()

                  -- because apparently the Submit does not allow an ATM to be submitted with the order, and an OIF does

                  Comment


                    #10
                    Hello vantojo,

                    Why don't you program a NinjaScript strategy or AddOn as opposed to using NinjaScript to submit OIF's?

                    EDIT: Just saw your reply. Please see documentation for submitting orders with ATM strategies with AddOn code: https://ninjatrader.com/support/help...tmstrategy.htm

                    You can you mouse coordinates to submit orders with AddOn code, please see the example attached.

                    NinjaTrader 8 is multi threaded and ChartTrader controls exist on a UI thread. If you do not use a dispatcher, you risk thread access errors if you try to access from OnBarUpdate or other events that are updated from instrument (OnBarUpdate OnMarketData, OnMarketDepth) or adapter threads (OnOrderUpdate OnExecutionUpodate, OnPositionUpdate, etc.)

                    ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate gets the name of the selected ATM strategy template in Chart Trader.

                    Are you checking this with Dispatcher.InvokeAsync?

                    Is there an ATM strategy selected when your code executes?

                    Demo - https://drive.google.com/file/d/1V9M...w?usp=drivesdk

                    We look forward to assisting.
                    Attached Files
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Ok, I don't have this in the dispatcher....but can put this code in a dispatcher....this works

                      if (ChartControl.OwnerChart.ChartTrader.AtmStrategy == null)
                      ATM_Name = "";
                      else
                      ATM_Name = ChartControl.OwnerChart.ChartTrader.AtmStrategy.Di splayName;

                      because evidently when the selection is "None" the object is set to null

                      and DisplayName returns the correct name for complex named ATMs.

                      Well, at least it is documented here.

                      :-)

                      Comment


                        #12

                        I am just now starting to port some of the code over to NT8.

                        The reason I don't use an addon or strategy is that this is a manual order entry based on the click price...it is on a chart...all my discretionary trading is from a chart....very very chart intensive.

                        So, at least from my experience with NT7, an indicator seems to be the best solution.

                        I would rather not submit Orders via an OIF, but am forced to because the Submit() does not allow the order to specify an ATM, which I want the the option to use.


                        Comment


                          #13
                          I don't want to use StartAtmStrategy because many time I have the ATM selected to "None"

                          Comment


                            #14
                            Hello vantojo,

                            If the AtmStrategy is null, use Submit, if the AtmStrategy is not null, use SubmitAtmStrategy with the AtmStrategy or the template name.

                            I think this would give you a faster and cleaner approach than using OIF's and would be my recommendation for achieving your goal.
                            Last edited by NinjaTrader_Jim; 01-18-2021, 06:51 AM.
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              thanks, good idea

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Working...
                              X