Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First Add On

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

    First Add On

    I have just added my first AddOn - as a New menu item (see the screenshot).

    This is really cool and already gives me plenty of new ideas for development!
    Attached Files

    #2
    Awesome, we're thrilled to offer this toolkit and are very eager to see what you guys are going to be able to do in this area!
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by gregid View Post
      I have just added my first AddOn - as a New menu item (see the screenshot).

      This is really cool and already gives me plenty of new ideas for development!
      gregid,

      I keep getting errors with
      NTMenuItem
      NTWindow,

      Is there a "using" you needed to add or is the On-Line instructions wrong?

      Comment


        #4
        Originally posted by NJA_MC View Post
        gregid,

        I keep getting errors with
        NTMenuItem
        NTWindow,

        Is there a "using" you needed to add or is the On-Line instructions wrong?
        The AddOn instruction is simply not complete, look here to implement NTWindow:


        After implementing this you should be fine just commenting out the remaining offending code to get it work for the first time.

        Comment


          #5
          Thanks,

          That didn't seem to resolve my issue "The type or namespace 'NTWindow' could not be found (....)".

          I will have to wait for better documentation or an example.

          Comment


            #6
            Here you are:

            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.Controls;
            using System.Windows.Input;
            using System.Windows.Media;
            using System.Xml.Linq;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Gui;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Gui.SuperDom;
            using NinjaTrader.Data;
            using NinjaTrader.Gui.Tools;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.Custom;
            
            #endregion
            
            //This namespace holds Add ons in this folder and is required. Do not change it. 
            namespace NinjaTrader.NinjaScript.AddOns
            {
            	public class MyCustomAddOn : NinjaTrader.NinjaScript.AddOnBase
            	{
            		
                 private NTMenuItem myMenuItem;
                 private NTMenuItem existingMenuItem;
             
                 protected override void OnStateChange()
                 {
                      if (State == State.SetDefaults)
                      {
                           Description = "Our custom MyWindow add on";
                           Name        = "MyWindow";
                      }
                 }
             
                 // Will be called as a new NTWindow is created. It will be called in the thread of that window
                 protected override void OnWindowCreated(Window window)
                 {
                      // We want to place our add on in the Control Center's menus
                      ControlCenter cc = window as ControlCenter;
                      if (cc == null)
                           return;
             
                      /* Determine we want to place our add on in the Control Center's "New" menu
                      Other menus can be accessed via the control's Automation ID. For example: toolsMenuItem,  
                      workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
                      existingMenuItem = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
                      if (existingMenuItem == null)
                           return;
             
                      // 'Header' sets the name of our add on seen in the menu structure
                      myMenuItem = new NTMenuItem { Header = "My First Menu Item",
                           Style = Application.Current.TryFindResource("MainMenuItem") as Style };
             
                      // Place our add on into the "New" menu
                      existingMenuItem.Items.Add(myMenuItem);
             
                      // Subscribe to the event for when the user presses our add on's menu item
                      myMenuItem.Click += OnMenuItemClick;
                 }
             
                 // Will be called as a new NTWindow is destroyed. It will be called in the thread of that window
                 protected override void OnWindowDestroyed(Window window)
                 {
                      if (myMenuItem != null && window is ControlCenter)
                      {
                           if (existingMenuItem != null && existingMenuItem.Items.Contains(myMenuItem))
                                existingMenuItem.Items.Remove(myMenuItem);
             
                           myMenuItem.Click -= OnMenuItemClick;
                           myMenuItem = null;
                      }
                 }
             
                 // Open our add on's window when the menu item is clicked on
                 private void OnMenuItemClick(object sender, RoutedEventArgs e)
                 {
                      // Show the NTWindow "MyWindow"
                      Core.Globals.RandomDispatcher.BeginInvoke(new Action(()=> new MyWindow().Show()));
                 }
              }
            	public class MyWindow : NTWindow, IWorkspacePersistence
            {
                 public MyWindow()
                 {
                      // Define our NTWindow. If we want to use tabs, we would attach necessary properties here.
                      Caption = "My First Item Window";
                      Width = 300;
                      Height = 300;
             
                      // TabControl should be created for window content if tab features are wanted
                      TabControl tc        = new TabControl();
             
                      /* Attached properties defined in TabControlManager class should be set to achieve tab moving, 
                      adding/removing tabs */
                      TabControlManager.SetIsMovable(tc, true);
                      TabControlManager.SetCanAddTabs(tc, true);
                      TabControlManager.SetCanRemoveTabs(tc, true);
             
                      // If ability to add new tabs is desired, TabControl has to have attached property "Factory" set.
                      //TabControlManager.SetFactory(tc, new MyWindowFactory());
                      Content = tc;
             
                      /* In order to have link buttons functionality, tab control items must be derived from NTTabPage
                      They can be added using extension method AddNTTabPage(NTTabPage page) */
                      //tc.AddNTTabPage(new MyWindowTabPage());
                      
                      // WorkspaceOptions property must be set
                      Loaded += (o, e) =>
                      {
                           if (WorkspaceOptions == null)
                                WorkspaceOptions = new WorkspaceOptions("MyWindow-" + Guid.NewGuid().ToString("N"), this);
                      };
                 }
             
                 // IWorkspacePersistence member. Required for restoring window from workspaces
                 public void Restore(XDocument document, XElement element)
                 {
                      if (MainTabControl != null)
                           MainTabControl.RestoreFromXElement(element);
                 }
             
                 // IWorkspacePersistence member. Required for saving window to workspaces
                 public void Save(XDocument document, XElement element)
                 {
                      if (MainTabControl != null)
                           MainTabControl.SaveToXElement(element);
                 }
             
                 // IWorkspacePersistence member
                 public WorkspaceOptions WorkspaceOptions { get; set; }
            }
            }

            Comment


              #7
              I could have swarn I tried adding this line:
              using NinjaTrader.Custom;
              using NinjaTrader.NinjaScript;

              NT Support, this is missing from the ADDON template.

              Thank you gregid.

              EDIT: looks like 2 using statements are missing.
              Last edited by NJA_MC; 05-09-2015, 05:20 PM.

              Comment


                #8
                Thanks for the report, we'll have that fixed - NTEIGHT-8213

                I'm attaching a sample addon made by NinjaTrader_Jesse which has some more thorough inline comments which may assist with creating a custom window and implemented the tab features, etc.

                Please expect updates to our AddOn documentation in the next few weeks.
                Attached Files
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Originally posted by NinjaTrader_Matthew View Post
                  Thanks for the report, we'll have that fixed - NTEIGHT-8213

                  I'm attaching a sample addon made by NinjaTrader_Jesse which has some more thorough inline comments which may assist with creating a custom window and implemented the tab features, etc.

                  Please expect updates to our AddOn documentation in the next few weeks.
                  Thanks..


                  Edit.. Previous comment I believe was user error..

                  Last edited by -=Edge=-; 05-12-2015, 06:01 PM.
                  -=Edge=-
                  NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                  Comment


                    #10
                    Also just noticed, and not sure if it's been brought up before.. Starting to loose track of everything I've read.. But would be nice to be able to select a directory tree from the top of the import form, vs to have to manually add the path and/or go thru the hoops of all the clicking..

                    -=Edge=-
                    NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

                    Comment


                      #11
                      Originally posted by -=Edge=- View Post
                      Also just noticed, and not sure if it's been brought up before.. Starting to loose track of everything I've read.. But would be nice to be able to select a directory tree from the top of the import form, vs to have to manually add the path and/or go thru the hoops of all the clicking..

                      I haven't seen it yet but meant to bring it up as well. The file selector dialog box could use some work. It is a pain to move to a different Drive & Path to find the file of interest. Is there still a "FileDialog()" box that can be called from the system level? A quick check on MS website shows that was a WinForm dialog. Here is a C# version, not sure if it has the same feel of it NT8 is already using it:
                      This article shows how to use an OpenFileDialog control in WPF and C# to browse files.

                      I'm trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I don't much care that it has the Windows Forms look to it. However, when I call ShowDialog, I want to pass the o...


                      This seems to be a problem for most WPF applications... Most people recommend using the older FORMs version.

                      Comment


                        #12
                        We had some design requirements to develop our own file loading dialog, and anticipated some feedback in this area to indicate there should be some improvements. We'll be reviewing this feature in the near future - SFT-41
                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          I've been using the SampleAddon provided as a basis in post #8 of this thread, and have run into a problem with threading i don't understand.

                          Using the "marketData_Update" method as provided in the example to update the label content works fine. But if I try to update label content in the "SelectedAccount_ExecutionUpdate" method (again provided in the example) I get a threading error.

                          Ideally I'd like to update labels from that method, as well as a separate timer method (which I haven't tried yet).

                          This probably reflects my lack of knowledge of multi-threading, but can you say why I'm getting this error, and point me in the right direction to fix it?

                          Thanks.

                          Comment


                            #14
                            Hello palinuro,

                            Thank you for writing in.

                            Can you please provide your modified script demonstrating this issue so I may test on my end?
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              If I edit the XAML, what do I need to do to refresh the interface? I've tried reopening the add-on, reconnecting NT, restarting NT, logging back in to windows, restarting windows, making sure the XMAL file is saved and closed. I also tried hitting F5 in the addon, but I'm not sure that would do anything. Thanks...BTW, I've renamed the XMAL file, as well as the calling reference in the addon.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              606 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              470 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Started by aa731, Today, 02:54 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aa731
                              by aa731
                               
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Christopher_R  
                              Working...
                              X