This is really cool and already gives me plenty of new ideas for development!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
First Add On
Collapse
X
-
Originally posted by gregid View PostI 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!
I keep getting errors with
NTMenuItem
NTWindow,
Is there a "using" you needed to add or is the On-Line instructions wrong?
Comment
-
Originally posted by NJA_MC View Postgregid,
I keep getting errors with
NTMenuItem
NTWindow,
Is there a "using" you needed to add or is the On-Line instructions wrong?
After implementing this you should be fine just commenting out the remaining offending code to get it work for the first time.
Comment
-
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
-
-
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 FilesMatthewNinjaTrader Product Management
Comment
-
Originally posted by NinjaTrader_Matthew View PostThanks 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.
Edit.. Previous comment I believe was user error..
Last edited by -=Edge=-; 05-12-2015, 06:01 PM.
Comment
-
Originally posted by -=Edge=- View PostAlso 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'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
-
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
-
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 adeelshahzad, Today, 11:49 AM
|
4 responses
14 views
0 likes
|
Last Post
by mcosta72
Today, 01:21 PM
|
||
Started by spottysallrite, Today, 11:31 AM
|
5 responses
12 views
0 likes
|
Last Post Today, 01:20 PM | ||
Started by yaniv, Today, 12:50 PM
|
1 response
2 views
0 likes
|
Last Post Today, 01:15 PM | ||
Started by Lele2k24, Yesterday, 11:24 AM
|
10 responses
32 views
0 likes
|
Last Post Today, 01:04 PM | ||
Started by Padan, Today, 02:02 AM
|
7 responses
19 views
0 likes
|
Last Post Today, 12:59 PM |
Comment