• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart Trader account ID

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

    Chart Trader account ID

    Is there a way using ninjascript (documented or not) to retrieve the Account string currently selected in the Chart Trader panel?

    Thanks

    #2
    Hello,
    Thank you for the question.

    I would like to post a snippet of code but I would like to start by saying this is by no means supported and not tested under all scenarios so any support or follow up questions regarding this may not get answered.

    This should at the very least give you an Idea on how to access windows form controls from a indicator or strategy.

    The chart trader is loaded when the chart starts, so when it is closed this will get the default in the list. If you open and change the account it should reflect the change in the list upon refresh.

    I have only tested this using the Sim101 and Market replay accounts as this was tested using the Sim key. Please let me know if your live account in the list works or not so that it is documented on the forum of the results.

    Code:
    protected override void OnStartUp()
            {
                for (int i = 0; i < ChartControl.Controls.Count; i++)
                {
                    if (ChartControl.Controls[i].Name == "pnlChartTrader")
                    {
    
                        Control ct = ChartControl.Controls[i];
                        ComboBox a = null;
    
                        for (int x = 0; x < ct.Controls["ctrChartTraderControl"].Controls.Count; x++)
                        {
                            a = (ComboBox)ct.Controls["ctrChartTraderControl"].Controls["cboAccount"] as ComboBox;
                        }
    
                        NinjaTrader.Cbi.Account d = a.SelectedItem as NinjaTrader.Cbi.Account;
    
                        Print(d.Name); //this is the name of the selected item in the dropdown box
                    }
                }
            }
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,

      The code works fine with a live account too. One more question and I have everything I need, how would one be able to tell when the Account is changed by the user, some kind of event handler for instance?

      Comment


        #4
        Hello,
        Thank you for letting me know if that worked on the Live account too,

        Again this is just a warning stating that all the code posted below is undocumented and unsupported and any questions pertaining to this may or may not be answered.

        I was unable to test this because I have a SIM key but this should work because all you are doing is adding an event handler to the ComboBox, again please let me know if this does or does not work .

        This required a slight change, the ComboBox control needs to be moved from the loops scope to the entire scripts scope so that you can remove the handler when the indicator or strategy exits. This is needed so that the event handler is not running after the script exits.


        Code:
         ComboBox accountBox = null;
        
                protected override void OnStartUp()
                {
                    for (int i = 0; i < ChartControl.Controls.Count; i++)
                    {
                        if (ChartControl.Controls[i].Name == "pnlChartTrader")
                        {
                            Control ct = ChartControl.Controls[i];
                            for (int x = 0; x < ct.Controls["ctrChartTraderControl"].Controls.Count; x++)
                            {
                                accountBox = (ComboBox)ct.Controls["ctrChartTraderControl"].Controls["cboAccount"] as ComboBox;
                                accountBox.SelectedIndexChanged += new EventHandler(Account_Selection_Changed_Handler);
                            }
                        }
                    }
                }
        
                private void Account_Selection_Changed_Handler(object sender, System.EventArgs e)
                {
                    NinjaTrader.Cbi.Account d = accountBox.SelectedItem as NinjaTrader.Cbi.Account;
                    Print(d.Name);
                }
        
                protected override void OnTermination()
                {
                    accountBox.SelectedIndexChanged -= new EventHandler(Account_Selection_Changed_Handler);
                }

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          The code worked like a charm, thanks very much....

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by johnnybegoode, Today, 11:35 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by NickyD, Today, 09:07 AM
          3 responses
          14 views
          0 likes
          Last Post NickyD
          by NickyD
           
          Started by 7robert, Today, 06:46 AM
          3 responses
          62 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by ElMagoR, Today, 07:49 AM
          4 responses
          31 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by Nabil, 09-13-2019, 11:44 AM
          5 responses
          35 views
          0 likes
          Last Post Nabil
          by Nabil
           
          Working...
          X