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

NT 7 and ChartControl

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

    NT 7 and ChartControl

    My understanding is that ChartControl is not supported in NT 7. However, I have been given a script to modify and it is supposed to run on NT 7. Its OnStartup method starts like this:
    Code:
            protected override void OnStartUp()
            {
                if( ChartControl != null )
                {
                    System.Windows.Forms.Control[] controls = ChartControl.Controls.Find("tsrTool", false);
                ....
                ...
                }
            }
    When I run it I get an error message in the log stating "Error on calling OnStartup method for Strategy xyz: Controls created on one thread cannot be parented to a control on a different thread". (The invoke method is not used anywhere, hence the error message I assume.) When I comment out the code in OnStartup it runs fine.
    So my question is, should I be able to check
    Code:
    if( ChartControl != null )
    in a script to determine if I can use ChartControl? If so why am I getting the error message? If not, how could this ever have run on NT 7?
    Thanks.

    #2
    Hello,

    In general that check should be valid, is there any type of threading used in the script its self? You can find another example of ChartControl being used in this file: http://ninjatrader.com/support/forum...d=6&linkid=530

    If the file you are using is programmed in a similar way it should work, otherwise is the item you are using freely available or could you post a sample that demonstrates the error?

    The one difference I see is that this uses a Find method, the other file uses a direct call
    Code:
    (ToolStrip)ChartControl.Controls["tsrTool"]
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Below is the code in OnStartup(). I have investigated further and found that the error occurs when the tradeDirBox is added to the ToolStrip
      Code:
      strip.Items.Add( tradeDirBox );
      The code works for other people, however, so perhaps something is missing in my environment, but I have no idea what. I have .Net 4.6 installed.
      Thanks for your help.

      Code:
                  if( ChartControl != null )
                  {
                      System.Windows.Forms.Control[] controls = ChartControl.Controls.Find("tsrTool", false);
                      if( controls.Length > 0 ) 
                      {
                          strip = (System.Windows.Forms.ToolStrip)controls[0];
      
                          sepL = new ToolStripSeparator();
                          strip.Items.Add(sepL);                
      
                          // Trading in one direction only drop list
                          tradeDirBox = new System.Windows.Forms.ToolStripComboBox();
                          tradeDirBox.DropDownStyle = ComboBoxStyle.DropDownList;
                          List<string> items = new List<string>{"Both", "Long", "Short"};
                          tradeDirBox.ComboBox.DataSource = items;
                          tradeDirBox.AutoSize = false;
                          Size boxSize = new Size();
                          boxSize.Height = tradeDirBox.Height;
                          boxSize.Width = 60;
                          tradeDirBox.Size = boxSize;
                          tradeDirBox.ToolTipText = "Select to enforce only Long or Short trades, or both";
                          
                          strip.Items.Add( tradeDirBox );
                          tradeDirBox.SelectedIndexChanged += ForcedTrade_TextChanged;
      
                          // Flatten button - flattens all trades
                          sep1 = new ToolStripSeparator();
                          strip.Items.Add(sep1);
      
                          btnFlatten = new System.Windows.Forms.ToolStripButton("btnFlatten");
                          btnFlatten.Font = boldFont;
                          btnFlatten.ForeColor = Color.White;
                          btnFlatten.BackColor = Color.DarkGoldenrod;
                          btnFlatten.Text = "Flatten";
                          btnFlatten.ToolTipText = "Flattens your position";
      
                          strip.Items.Add(btnFlatten);
                          btnFlatten.Click += btnFlatten_Click;
      
                          sepR = new ToolStripSeparator();
                          strip.Items.Add(sepR);
                          
                          buttonsLoaded = true;
                      }
                  }

      Comment


        #4
        Hello,

        Thank you for the reply.

        I am not seeing anything specific that sticks out, although this would not compile on my end so I am unsure based on this sample.

        NinjaTrader 7 uses .net 3.5 which is installed already on your computer, having .net 4.6 would have no effect on the platform. If you are trying to use assemblies or code that is 4.6 specific in NT7 that would cause problems in NT7.

        If you could provide a more complete sample that includes variables and can compile, I could at least test it on my end to see if I have the same result or not. If we have the exact same test and one is different that may indicate something on the computer, otherwise we could likely identify what is happening in the code used.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        6 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by gbourque, Today, 06:39 AM
        2 responses
        14 views
        0 likes
        Last Post gbourque  
        Started by rexsole, Today, 08:39 AM
        0 responses
        6 views
        0 likes
        Last Post rexsole
        by rexsole
         
        Started by trilliantrader, Yesterday, 03:01 PM
        3 responses
        31 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by Brevo, Today, 01:45 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X