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

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 algospoke, 04-17-2024, 06:40 PM
          3 responses
          26 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by bmartz, 03-12-2024, 06:12 AM
          3 responses
          30 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by Aviram Y, Today, 05:29 AM
          2 responses
          10 views
          0 likes
          Last Post Aviram Y  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X