• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sample AddOn?

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

    Sample AddOn?

    Hello,

    I found this article in your help guide:

    http://ninjatrader.com/support/helpG..._interface.htm

    There's a lot of good stuff there, but unfortunately it doesn't include a compilable version of the code. I've tried assembling it myself but to no avail.

    Can you please point me to the code for an add-on I can install, or can you please include a complete, compilable version of the example provided in your help guide?

    Thank you,

    Ryan

    By the way, this is where I gave up:

    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 System.Xml.Linq;
    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
    
    //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
    	{
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Add on here.";
    				Name										= "MyCustomAddOn";
    			}
    			else if (State == State.Configure)
    			{
    			}
    		}
    
    		protected override void OnWindowCreated(Window window)
    		{
    		  // We want to place our AddOn in the Control Center's menus
    		  ControlCenter cc = window as ControlCenter;
    		  if (cc == null)
    		      return;
    		 
    		  /* Determine we want to place our AddOn in the Control Center's "New" menu
    		   Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
    		  existingMenuItemInControlCenter = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
    		  if (existingMenuItemInControlCenter == null)
    		      return;
    		 
    		  // 'Header' sets the name of our AddOn seen in the menu structure
    		  addOnFrameworkMenuItem = new NTMenuItem { Header = "AddOn Framework", Style = Application.Current.TryFindResource("MainMenuItem") as Style };
    		 
    		  // Add our AddOn into the "New" menu
    		  existingMenuItemInControlCenter.Items.Add(addOnFrameworkMenuItem);
    		 
    		  // Subscribe to the event for when the user presses our AddOn's menu item
    		  addOnFrameworkMenuItem.Click += OnMenuItemClick;			
    		}
    
    		protected override void OnWindowDestroyed(Window window)
    		{
    		  if (addOnFrameworkMenuItem != null && window is ControlCenter)
    		  {
    		      if (existingMenuItemInControlCenter != null && existingMenuItemInControlCenter.Items.Contains(addOnFrameworkMenuItem))
    		          existingMenuItemInControlCenter.Items.Remove(addOnFrameworkMenuItem);
    		 
    		      addOnFrameworkMenuItem.Click -= OnMenuItemClick;
    		      addOnFrameworkMenuItem = null;
    		  }			
    		}
    
    		// Open our AddOn's window when the menu item is clicked on
    		private void OnMenuItemClick(object sender, RoutedEventArgs e)
    		{
    		  Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => new AddOnFrameworkWindow().Show()));
    		}
    	}
    
    	/* This is where we define our AddOn window. The actual content is contained inside the tabs of the window defined in a custom class inheriting from NTTabPage.
    	   We must create a new window class which inherits from Tools.NTWindow for styling and implements the IWorkspacePersistence interface for the ability to save/restore from workspaces.*/
    	public class AddOnFrameworkWindow : NTWindow, IWorkspacePersistence
    	{
    	  public AddOnFrameworkWindow()
    	  {
    	      // set Caption property (not Title), since Title is managed internally to properly combine selected Tab Header and Caption for display in the windows taskbar
    	      // This is the name displayed in the top-left of the window
    	      Caption = "AddOn Framework";
    	 
    	      // Set the initial dimensions of the window
    	      Width   = 1085;
    	      Height = 900;
    
    	      // 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 AddOnFrameworkWindowFactory());
    	      
    	      Content = tc;
    			  
    	      /* In order to have link buttons functionality, tab control items must be derived from Tools.NTTabPage
    	       They can be added using extension method AddNTTabPage(NTTabPage page) */
    	      tc.AddNTTabPage(new AddOnFrameworkTab());		  
    
    	     // WorkspaceOptions property must be set
    	      Loaded += (o, e) =>
    	      {
    	          if (WorkspaceOptions == null)
    	              WorkspaceOptions = new WorkspaceOptions("AddOnFramework-" + Guid.NewGuid().ToString("N"), this);
    	      };		  
    	  }
    
    	  // IWorkspacePersistence member. Required for restoring window from workspace
    	  public void Restore(XDocument document, XElement element)
    	  {
    	      if (MainTabControl != null)
    	          MainTabControl.RestoreFromXElement(element);
    	  }
    	 
    	  // IWorkspacePersistence member. Required for saving window to workspace
    	  public void Save(XDocument document, XElement element)
    	  {
    	      if (MainTabControl != null)
    	          MainTabControl.SaveToXElement(element);
    	  }
    	 
    	  // IWorkspacePersistence member
    	  public WorkspaceOptions WorkspaceOptions { get; set; }	  
    	}
    
    	/* Class which implements Tools.INTTabFactory must be created and set as an attached property for TabControl
    	in order to use tab page add/remove/move/duplicate functionality */
    	public class AddOnFrameworkWindowFactory : INTTabFactory
    	{
    	  // INTTabFactory member. Required to create parent window
    	  public NTWindow CreateParentWindow()
    	  {
    	      return new AddOnFrameworkWindow();
    	  }
    	 
    	  // INTTabFactory member. Required to create tabs
    	  public NTTabPage CreateTabPage(string typeName, bool isTrue)
    	  {
    	      return new NinjaTraderAddOnProject.AddOnPage();
    	  }
    	}
    
    
    	/* This is where we define the actual content of the tabs for our AddOn window.
    	   Note: Class derived from Tools.NTTabPage has to be created if instrument link or interval link functionality is desired.
    	   Tools.IInstrumentProvider and/or Tools.IIntervalProvider interface(s) should be implemented.
    	   Also NTTabPage provides additional functionality for properly naming tab headers using properties and variables such as @FUNCTION, @INSTRUMENT, etc. */
    	public class AddOnFrameworkTab : NTTabPage, NinjaTrader.Gui.Tools.IInstrumentProvider, NinjaTrader.Gui.Tools.IIntervalProvider
    	{
    	  public AddOnFrameworkTab()
    	  {
    	      Content = AddOnFrameworkWindowFactory.CreateTabPage("AddOnPage",true);
    	  }
    	}
    
    
    }

    #2
    Hello gripload,

    Thanks for your note.

    Below is a link to the Addon example created by the NinjaTrader Product Management team.
    http://ninjatrader.com/support/helpG...t_overview.htm

    Also, below is a link to a simplified starter example that I've posted on the forums previously.
    http://ninjatrader.com/support/forum...059#post477059
    Last edited by NinjaTrader_Matthew; 01-09-2017, 11:56 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you!

      Comment


        #4
        The NinjaScripte Editor AddOn Framework version is now located in our Help Guide, along with a version of this project that works in VisualStudio with dependent Xaml files

        http://ninjatrader.com/support/helpG...t_overview.htm
        Last edited by NinjaTrader_Matthew; 01-09-2017, 11:59 AM.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by onevefiefe, Today, 07:42 AM
        0 responses
        2 views
        0 likes
        Last Post onevefiefe  
        Started by J_o_s, Today, 06:09 AM
        0 responses
        6 views
        0 likes
        Last Post J_o_s
        by J_o_s
         
        Started by jeronymite, 03-23-2020, 12:27 AM
        3 responses
        34 views
        0 likes
        Last Post leontancfa  
        Started by asmmbillah, Today, 04:53 AM
        0 responses
        5 views
        0 likes
        Last Post asmmbillah  
        Started by davidnorton, Today, 04:29 AM
        0 responses
        2 views
        0 likes
        Last Post davidnorton  
        Working...
        X