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

Sample AddOn?

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

    Sample AddOn?

    Hello,

    I found this article in your help guide:



    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.


    Also, below is a link to a simplified starter example that I've posted on the forums previously.
    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

        Last edited by NinjaTrader_Matthew; 01-09-2017, 11:59 AM.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Aviram Y, Today, 05:29 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeForge, Today, 02:09 AM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by elirion, Today, 01:36 AM
        2 responses
        14 views
        0 likes
        Last Post elirion
        by elirion
         
        Working...
        X