Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What's the control for the ChartTrader position change tracker?

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

    What's the control for the ChartTrader position change tracker?

    I'm trying to get a copy of the ChartTrader position change tracker into the ToolBar.

    Click image for larger version

Name:	positiondifference.png
Views:	288
Size:	2.6 KB
ID:	1194142

    What's its doc/ control? Thanks!

    #2
    Hello PaulMohn,

    Using MSInspect this shows as a NinjaTrader.Gui.Tools.PositionDisplay with the automationid ChartTraderControlPnLDisplay.

    Below is a link to a forum post about using MSInspect to get automation ids.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea and thanks for the reference. I found your other reference with demo about the Windows inspect tool
      Customizing Chart Trader - NT8

      thanks but I'm not sure what the automationID is used for. Can you please explain? Thanks!
      Following my previous code below, I used it as "label" in
      PHP Code:
      ChartControl.Dispatcher.InvokeAsync((Action)(() =>
      {
      PnLDisplay = (Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlPnLDisplay") as NinjaTrader.Gui.Tools.PositionDisplay);
      })); 
      

      but what does it mean?



      I adjusted my other indicator code using QuantitySelector in the Toolbar
      BuyMktSellMktHotkeysQS

      From
      PHP Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
        public class BuyMktSellMktHotkeysQS : Indicator
        {
          private Account myAccount;
      
          // QS Define a Chart object to refer to the chart on which the indicator resides
          private Chart chartWindow;
      
          NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = null;
      
          // QS
          private bool Is_ToolBar_Controls_Added;
      
          protected override void OnStateChange()
          {
            NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector;
      
            if (State == State.SetDefaults)
            {
              AccountName                 = "Sim101";
            }
            else if (State == State.Configure)
            {
            }
            else if (State == State.Historical)
            {
              //Call the custom addButtonToToolbar method in State.Historical to ensure it is only done when applied to a chart
              // -- not when loaded in the Indicators window
              if (!Is_ToolBar_Controls_Added) Add_Controls_To_Toolbar();
            }
            else if (State == State.DataLoaded)
            {
                ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                {
                  quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown);
                }));
              }
      
            }
            else if (State == State.Terminated)
            {
                 DisposeCleanUp();
            }
      
          #region Add Controls To Toolbar
          private void Add_Controls_To_Toolbar()
          {
            // Use this.Dispatcher to ensure code is executed on the proper thread
            ChartControl.Dispatcher.InvokeAsync((Action)(() =>
            {
      
              //Obtain the Chart on which the indicator is configured
              chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart;
              if (chartWindow == null)
              {
                Print("chartWindow == null");
                return;
              }
      
              quantitySelector = new NinjaTrader.Gui.Tools.QuantityUpDown();
              //quantitySelector.ValueChanged += On_quantitySelector_ValueChanged;
              quantitySelector.PreviewKeyDown += On_quantitySelector_PreviewKeyDown;
      
              chartWindow.MainMenu.Add(quantitySelector);
      
              Is_ToolBar_Controls_Added = true;
            }));
          }
          #endregion
      
          #region DisposeCleanUp
          private void DisposeCleanUp()
          {
            //ChartWindow Null Check
            if (chartWindow != null)
            {
              //Dispatcher used to Assure Executed on UI Thread
              ChartControl.Dispatcher.InvokeAsync((Action)(() =>
              {
                if( quantitySelector != null )   chartWindow.MainMenu.Remove(quantitySelector);
              }));
            }
          }
          #endregion
      
          } 
      

      To
      PHP Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
        public class BuyMktSellMktHotkeysQS : Indicator
        {
          private Account myAccount;
      
          // QS Define a Chart object to refer to the chart on which the indicator resides
          private Chart chartWindow;
      
          NinjaTrader.Gui.Tools.PositionDisplay PnLDisplay = null;
      
          // QS
          private bool Is_ToolBar_Controls_Added;
      
          protected override void OnStateChange()
          {
            NinjaTrader.Gui.Tools.PositionDisplay PnLDisplay;
      
            if (State == State.SetDefaults)
            {
              AccountName                 = "Sim101";
            }
            else if (State == State.Configure)
            {
            }
            else if (State == State.Historical)
            {
              //Call the custom addButtonToToolbar method in State.Historical to ensure it is only done when applied to a chart
              // -- not when loaded in the Indicators window
              if (!Is_ToolBar_Controls_Added) Add_Controls_To_Toolbar();
            }
            else if (State == State.DataLoaded)
            {
                ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                {
                  PnLDisplay = (Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlPnLDisplay") as NinjaTrader.Gui.Tools.PositionDisplay);
                }));
              }
      
            }
            else if (State == State.Terminated)
            {
                 DisposeCleanUp();
            }
      
          #region Add Controls To Toolbar
          private void Add_Controls_To_Toolbar()
          {
            // Use this.Dispatcher to ensure code is executed on the proper thread
            ChartControl.Dispatcher.InvokeAsync((Action)(() =>
            {
      
              //Obtain the Chart on which the indicator is configured
              chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart;
              if (chartWindow == null)
              {
                Print("chartWindow == null");
                return;
              }
      
              PnLDisplay = new NinjaTrader.Gui.Tools.PositionDisplay();
      
              chartWindow.MainMenu.Add(PnLDisplay);
      
              Is_ToolBar_Controls_Added = true;
            }));
          }
          #endregion
      
          #region DisposeCleanUp
          private void DisposeCleanUp()
          {
            //ChartWindow Null Check
            if (chartWindow != null)
            {
              //Dispatcher used to Assure Executed on UI Thread
              ChartControl.Dispatcher.InvokeAsync((Action)(() =>
              {
                if( PnLDisplay != null )   chartWindow.MainMenu.Remove(PnLDisplay);
              }));
            }
          }
          #endregion
      
      
          [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
          public string AccountName { get; set; }
        }
      } 
      

      I'll test and be baclk asa. Thanks!
      Last edited by PaulMohn; 03-16-2022, 01:20 PM.

      Comment


        #4
        Chelsea, I got it in the Toolbar as this

        Click image for larger version  Name:	Pnl.png Views:	0 Size:	9.8 KB ID:	1194193

        How can i get only the PnL one and remove the Flat and Entry ones?
        Or if possible get them to display laterally?
        Or if possible get them smaller to fit the normal ToolBar size? Thanks!

        Also how to get to display the orders PnL? I tested submitting an order and it display in the chart trader but not in the ToolBar.
        Last edited by PaulMohn; 03-16-2022, 01:18 PM.

        Comment


          #5
          Hello PaulMohn,

          Thats how the object comes. It wasn't designed for a toolbar, it was designed to fit in Chart Trader.

          Manipulating this may be possible, however this would be outside of the realm of our support.

          This thread will remain open for any community members that would like to assist.

          You could alternatively use regular WPF controls like stackpanels and textboxes and populate those with information from the Account.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Ok thanks. Do you have simple samples and doc about stackpanels and textboxes about specifically getting the PnL box into the toolbar (not on the chart if possible) ?
            Also what is the doc reference of the DisplayPnL Above? i'd like to check if there's more info about getting the PnL box only.
            Also any reason why the PnL doesn't display? Thanks!

            Comment


              #7
              Hello PaulMohn,

              There is one sample you may find helpful.
              https://ninjatrader.com/support/help...ui)-modifi.htm

              StackPanels and TextBlocks are C# which made by Microsoft. Please refer to the Microsoft documentation.

              There is no support using a PositionDisplay. This would be undocumented.

              Below is a link to the help guide with the only documented NinjaTrader Controls that are supported by our support to use.
              https://ninjatrader.com/support/help...8/controls.htm

              For anything else, this would be your custom C# code for you to use at your discretion.
              Last edited by NinjaTrader_ChelseaB; 03-16-2022, 02:28 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks. Is there an equivalent for Indicators of the position_getunrealizedprofitloss ?

                If yes can we display it in the toolbar? Thanks!

                Comment


                  #9
                  Hello PaulMohn,

                  The Account.Positions[instrument index].GetUnrealizedProfitLoss().
                  https://ninjatrader.com/support/help...ns_account.htm

                  A script that uses this.
                  This indicator provides a customizable text box which displays a position’s UnRealized PnL, Realized PnL of a selected account, and the overall cash value of the account.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for the sample. I'll try making room for it on the chart and simplifying using Draw.TextFixed instead of SharpDX (though it might come handy for future reference in case of SharpDX need).

                    Comment


                      #11
                      Hello PaulMohn,

                      The example was just to show getting an account value. You could put that as a TextBlock value if you wanted instead.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      574 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      333 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      553 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      551 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X