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

Issue with code in Help

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

    Issue with code in Help

    Hi

    Trying to explore AddOn's and in your support pagehere you outline various ideas which are very helpful.
    However when I copied the code for the Add Button scenario it comes up with some errors regarding panellength, location and direction.


    I wonder if you could help me resolve this?

    thank you
    Last edited by Mindset; 01-05-2022, 07:38 AM.

    #2
    Hello Mindset,

    If you can provide the specific errors you had received or a .cs file containing the code you copied/pasted that would give a better idea on what the solution is. It may just be that you are missing a using statement.

    The code you linked to is also not a full sample, that is an explanation of what is being done in the basic addon sample file from this link: https://ninjatrader.com/support/help...t_overview.htm

    The samples in the addon help guide basically all assume that you have used the basic addon sample as a starting point to learn those various parts of the addon framework.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Errors are lines 93 and 111

      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.Gui.Tools;
      #endregion
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      using NinjaTrader.Cbi;
      using System.Windows.Controls;
      using NinjaTrader.Core;
      using NinjaTrader.Gui.NinjaScript.AtmStrategy;
      using System.Linq;
      using System.Xml.Linq;
      #endregion
      
      //This namespace holds Add ons in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.AddOns
      {
      public class MyCustomAddOn1 : NinjaTrader.NinjaScript.AddOnBase
      {
      
      // Variables
      // // Declare a Chart, ChartTrader, and UI elements to add to Chart Trader
      //Gui.Chart.Chart myChart;
      //Gui.Chart.ChartTrader chartTrader;
      //Button sampleButton;
      //Grid myGrid;
      //Grid mainGrid;
      
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Add on here.";
      Name = "MyCustomAddOn1";
      }
      else if (State == State.Configure)
      {
      }
      }
      protected override void OnWindowCreated(Window window)
      {
      // Obtain a reference to any chart that triggered OnWindowCreated
      Chart Window = window as Chart;
      
      // Instantiate a grid to hold a reference to the content of the chart window
      Grid mainWindowGrid = Window.Content as Grid;
      
      // Add existing row definition for existing row if it is not present
      if (mainWindowGrid.RowDefinitions.Count == 0)
      {
      mainWindowGrid.RowDefinitions.Add(new RowDefinition());
      }
      
      // Instantiate a RowDefinition and set its height
      RowDefinition row = new RowDefinition();
      row.Height = new GridLength(30);/// changed from panellength
      
      // Insert the new row into the chart's main window grid
      mainWindowGrid.RowDefinitions.Insert(0, row);
      
      //Move Existing Elements down one row, since our new content will take the top row
      foreach (UIElement element in mainWindowGrid.Children)
      {
      element.SetValue(Grid.RowProperty, (int)element.GetValue(Grid.RowProperty) + 1);
      }
      
      //Create the Top Panel grid and add it to our newly defined row
      Grid Panel = new Grid();
      Panel.SetValue(Grid.RowProperty, 0);
      mainWindowGrid.Children.Add(Panel);
      
      //Create a sample text block and add it to the Top/Bottom Panel Grid.
      TextBlock TextBlock = new TextBlock();
      // TextBlock.Text = PanelDirection.ToString() + " Panel (" + PanelLocation.ToString() + ") Sample Text Block";
      TextBlock.Foreground = Brushes.Red;
      TextBlock.SetValue(Grid.RowProperty, 0);
      Panel.Children.Add(TextBlock);
      }
      
      
      }
      
      }

      Comment


        #4
        Hello Mindset,

        I tried the code and don't see any compile errors. If you are seeing a runtime error II would need more details on what the specific errors are or what use case was used. It is helpful if you can provide the specific errors you see with the code so that we have a better idea of what you are seeing.

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

        Comment


          #5
          sorry - I commented out the two lines that were the problem - lines 93 and 111. If you uncomment them you get the compile error which is that the name panelLocation, etc don't exist

          Comment


            #6
            Hello Mindset,

            For the panel Text you would replace that with whatever text you had intended to display.

            Code:
             TextBlock.Text =  "your text here";
            I don't see anything commented for line 93 with the given code, if you are seeing additional errors please post the error message.

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

            Comment


              #7
              Hi Jesse

              not sure why you don't get this issue - here is my very basic code that fails to compile

              Code:
              #region Using declarations
              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.ComponentModel.DataAnnotations;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using System.Windows;
              using System.Windows.Input;
              using System.Windows.Media;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Gui;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Gui.SuperDom;
              using NinjaTrader.Gui.Tools;
              using NinjaTrader.Data;
              using NinjaTrader.NinjaScript;
              using NinjaTrader.Core.FloatingPoint;
              using NinjaTrader.NinjaScript.DrawingTools;
              using NinjaTrader.Cbi;
              using System.Windows.Controls;
              using NinjaTrader.Core;
              using NinjaTrader.Gui.NinjaScript.AtmStrategy;
              using System.Linq;
              using System.Xml.Linq;
              #endregion
              
              //This namespace holds Add ons in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.AddOns
              {
              public class MyCustomAddOn1 : NinjaTrader.NinjaScript.AddOnBase
              {
              
              // Variables
              // // Declare a Chart, ChartTrader, and UI elements to add to Chart Trader
              //Gui.Chart.Chart myChart;
              //Gui.Chart.ChartTrader chartTrader;
              //Button sampleButton;
              //Grid myGrid;
              //Grid mainGrid;
              
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Add on here.";
              Name = "MyCustomAddOn1";
              }
              else if (State == State.Configure)
              {
              }
              }
              protected override void OnWindowCreated(Window window)
              {
              // Obtain a reference to any chart that triggered OnWindowCreated
              Chart Window = window as Chart;
              
              // Instantiate a grid to hold a reference to the content of the chart window
              Grid mainWindowGrid = Window.Content as Grid;
              
              // Add existing row definition for existing row if it is not present
              if (mainWindowGrid.RowDefinitions.Count == 0)
              {
              mainWindowGrid.RowDefinitions.Add(new RowDefinition());
              }
              
              // Instantiate a RowDefinition and set its height
              RowDefinition row = new RowDefinition();
              row.Height = new GridLength(30);/// changed from panellength
              
              // Insert the new row into the chart's main window grid
              mainWindowGrid.RowDefinitions.Insert(0, row);
              
              //Move Existing Elements down one row, since our new content will take the top row
              foreach (UIElement element in mainWindowGrid.Children)
              {
              element.SetValue(Grid.RowProperty, (int)element.GetValue(Grid.RowProperty) + 1);
              }
              
              //Create the Top Panel grid and add it to our newly defined row
              Grid Panel = new Grid();
              Panel.SetValue(Grid.RowProperty, 0);
              mainWindowGrid.Children.Add(Panel);
              
              //Create a sample text block and add it to the Top/Bottom Panel Grid.
              TextBlock TextBlock = new TextBlock();
              //***********************************************************************************************************************
              TextBlock.Text = PanelDirection.ToString() + " Panel (" + PanelLocation.ToString() + ") Sample Text Block";
              TextBlock.Foreground = Brushes.Red;
              TextBlock.SetValue(Grid.RowProperty, 0);
              Panel.Children.Add(TextBlock);
              }
              
              
              }
              
              }

              Comment


                #8
                Hello Mindset,

                The variables you are trying to print don't exist, please see my prior post about how to set a custom string of your own. I otherwise don't see an error after making that change for your use case. After making that change if you see an error message please post that instead.


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

                Comment


                  #9
                  Jesse

                  Changing the text string doesn't alter the fact that PanelLocation for instance doesn't exist and that's where I need some guidance - what is the code syntax to set a PanelLocation, etc?

                  Error - the name PanelLocation does not exist in the current context

                  Comment


                    #10
                    Hello Mindset,

                    Those variables don't exist where you tried to use them so that's not valid. You need to replace that with your own string and not use the panel variables as they don't exist.

                    To set a location of a WPF control you would generally use WPF techniques like setting a grid column or row. Panels are reserved for indicators being displayed in a chart and would not be something you would access with WPF.


                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Jesse

                      Forgive me for being dim but if you put them in a code in the help section shouldn't they exist? If you put code that doesn't compile it doesn't help idiots like me lol.
                      That's the bit I am really interested in and don't truly understand.

                      Comment


                        #12
                        Hello Mindset,

                        Unfortunately I couldn't comment as I don't know who made that sample, the solution is simply to use your own string here as shown previously.

                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rocketman7, Today, 02:12 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post rocketman7  
                        Started by dustydbayer, Today, 01:59 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post dustydbayer  
                        Started by inanazsocial, Today, 01:15 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post inanazsocial  
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        5 responses
                        22 views
                        0 likes
                        Last Post trilliantrader  
                        Started by Davidtowleii, Today, 12:15 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post Davidtowleii  
                        Working...
                        X