Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First Add On

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

  • NinjaTrader_Matthew
    replied
    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

    Leave a comment:


  • NJA_MC
    replied
    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.

    Leave a comment:


  • gregid
    replied
    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; }
    }
    }

    Leave a comment:


  • NJA_MC
    replied
    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.

    Leave a comment:


  • gregid
    replied
    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.

    Leave a comment:


  • NJA_MC
    replied
    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?

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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!

    Leave a comment:


  • gregid
    started a topic First Add On

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by CortexZenUSA, Today, 12:53 AM
0 responses
1 view
0 likes
Last Post CortexZenUSA  
Started by CortexZenUSA, Today, 12:46 AM
0 responses
1 view
0 likes
Last Post CortexZenUSA  
Started by usazencortex, Today, 12:43 AM
0 responses
5 views
0 likes
Last Post usazencortex  
Started by sidlercom80, 10-28-2023, 08:49 AM
168 responses
2,265 views
0 likes
Last Post sidlercom80  
Started by Barry Milan, Yesterday, 10:35 PM
3 responses
11 views
0 likes
Last Post NinjaTrader_Manfred  
Working...
X