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

Get Chart Trader account selection from indicator code.

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

    Get Chart Trader account selection from indicator code.

    Hi
    How to get the Account name (account.Name) that is selected in the Chart Trader DropDownBox, so I can use the Account Object or instantiate an account object for the same account in my indicator.

    I want to be able to show in my indicator information about the account that is currently selected in the Chart Trader Account DropDown box.

    Thx

    #2
    Hello jmneto,

    Thank you for writing in.

    I have put together an indicator which will print to the output window what account is selected in the chart trader account drop down.

    To Import a NinjaScript into NinjaTrader 8 do the following:
    From the Control Center window select Tools -> Import-> NinjaScript...
    Find the file location.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      That solved my need. I was also able to subscribe to the SelectionChanged event.

      Comment


        #4
        Heh, any chance you have this for nt 7?

        Comment


          #5
          Hello TickTaker,

          There is no sample for this in NT7 and may be possible however not supported.

          Please let us know if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by TickTaker View Post
            Heh, any chance you have this for nt 7?
            Code:
            Panel panel = (Panel)ChartControl.Controls["pnlChartTrader"];
            
            if (panel != null && panel.Controls["ctrChartTraderControl"] != null)
            {
                 ComboBox comboAccount = (ComboBox)panel.Controls["ctrChartTraderControl"].Controls["cboAccount"];
                 NinjaTrader.Cbi.Account AccountObject = (NinjaTrader.Cbi.Account)comboAccount.SelectedItem;
                 Print("Selected Account: " + AccountObject.Name);
            }

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post

              I have put together an indicator which will print to the output window what account is selected in the chart trader account drop down.

              Please let us know if you need further assistance.
              I loaded this indicator on a chart and it detects the account in the chart trader window
              However, I am trying to find the chart name in an indicator.
              I am using the code shown in another thread.
              This is the code:
              Code:
                              lock (Account.All)
                                  myAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);​
              How do I get the 'AccountName to reflect the account shown in the Chart Account dropdown?

              If I hard code the name i.e. "Sim101" the account name is correct but using 'AccountName' does not work.
              Thanks

              Comment


                #8
                Hello DavidHP,

                Thank you for your post.

                Can you clarify what you mean by "trying to find the chart name"? The code Alan provided demonstrates getting the name of the selected account from the Chart Trader from an indicator.
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Gaby View Post
                  Hello DavidHP,

                  Thank you for your post.

                  Can you clarify what you mean by "trying to find the chart name"? The code Alan provided demonstrates getting the name of the selected account from the Chart Trader from an indicator.
                  I have the following indicator loaded.
                  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.

                  It does not seem to work unless I manually insert the account name i.e. "Sim101" or "Playback101" into the code.

                  Here is the code on lines 73 -74
                  Code:
                                  lock (Account.All)
                                      account = Account.All.FirstOrDefault(a => a.Name == AccountName);​
                  To get it to detect the PNL I must change the code from "AccountName" to the account on the chart manually, otherwise it does nothing.

                  I thought maybe I could use the code from this indicator (PrintChartTraderSelectedAccount.zip) to be able to automatically get the account name instead of needing to manually change the code each time I changed accounts.

                  Is that possible?​

                  Comment


                    #10
                    Hello DavidHP,

                    Thank you for your response.

                    The PositionDisplayIndicator uses the account chosen in the 'Properties' of the indicator. Right-click on the chart > Indicators > click on the Indicator > you can select the account on the right side (Properties section).

                    You can however integrate the code from PrintChartTraderSelectedAccount into this indicator. You can get the account from State.DataLoaded, as long as your script is added to a chart and you are checking that the ChartControl is not null.

                    Please let me know if you have any other questions.
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Gaby View Post
                      Hello DavidHP,

                      Thank you for your response.

                      The PositionDisplayIndicator uses the account chosen in the 'Properties' of the indicator. Right-click on the chart > Indicators > click on the Indicator > you can select the account on the right side (Properties section).

                      You can however integrate the code from PrintChartTraderSelectedAccount into this indicator. You can get the account from State.DataLoaded, as long as your script is added to a chart and you are checking that the ChartControl is not null.

                      Please let me know if you have any other questions.
                      The section in the State.DataLoaded has the code I indicated:
                      Code:
                      lock (Account.All)
                      account = Account.All.FirstOrDefault(a => a.Name == AccountName);​​
                      When I integrate the code from the (PrintChartTraderSelectedAccount.zip) the account name "PRINTS" in the Output Window as in the original indicator.
                      However when I try to pass the code to the 'account' I etiher get Object reference error or a CBI error.
                      It seems the code in the (PrintChartTraderSelectedAccount.zip) is in OnBarUpdate but State.DataLoaded is read before that and is of a differnt type.

                      Perhaps I'm not 'integrating' it properly?
                      What am I missing?

                      Thanks for your suggestions.

                      Comment


                        #12
                        Hello DavidHP,

                        Instead of getting the account from OnBarUpdate(), you should get the account in State.DataLoaded. This should work as long as your script is added to the chart and the ChartControl is not null. Getting the account from OnBarUpdate() would likely cause an object reference error if you are trying to do something with the account from State.DataLoaded but you haven't grabbed the actual account from OnBarUpdate() yet.

                        Please let me know if you have any further questions.
                        Gaby V.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Gaby View Post
                          Hello DavidHP,

                          Instead of getting the account from OnBarUpdate(), you should get the account in State.DataLoaded. This should work as long as your script is added to the chart and the ChartControl is not null. Getting the account from OnBarUpdate() would likely cause an object reference error if you are trying to do something with the account from State.DataLoaded but you haven't grabbed the actual account from OnBarUpdate() yet.

                          Please let me know if you have any further questions.
                          Perhaps you could give an example.
                          I've tried adding to the dataloaded several different ways and each give errors.

                          Comment


                            #14
                            Hello DavidHP,

                            Please see the attached.

                            If you have any further questions, please let me know!
                            Attached Files
                            Gaby V.NinjaTrader Customer Service

                            Comment


                              #15
                              Yo ​What´s going on? pls helpClick image for larger version

Name:	image.png
Views:	28
Size:	85.1 KB
ID:	1293490

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              168 views
                              0 likes
                              Last Post jeronymite  
                              Started by cre8able, Today, 04:22 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X