Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set QuantityUpDown value from keyboard
Collapse
X
-
if I want to change the colour of the background
if(quantitySelector.Value > 1)
quantitySelector.Background. = Brushes.Red;
doesn't work?
What's the correct approach for this?
-
Thanks #PaulMohn and NT - this was really useful.Originally posted by PaulMohn View PostHello Jesse, how could I set the default QuantitySelector value to 1? Currently it is 0 when loading the indicator on the chart and ?'d like to to set it to one if possible as default. Thanks!
I tried setting it to 1 just above the method but it's not working.
PHP Code:NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = null; // QS private bool Is_ToolBar_Controls_Added; private int qs; protected override void OnStateChange() {
PHP Code:NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown; qs.Value = 1; private void On_quantitySelector_PreviewKeyDown(object sender, KeyEventArgs p) { NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown; if (p.Key == Key.Delete || p.Key == Key.Back) { p.Handled = true; qs.Value = 0; } if (p.Key >= Key.D0 && p.Key <= Key.D9) { p.Handled = true; string number = p.Key.ToString(); string newnumber = qs.Value.ToString(); number = number.Replace("NumPad", ""); number = number.Replace("D", ""); int num = int.Parse(newnumber + number); if (qs != null) qs.Value = num; } }
Leave a comment:
-
Hello PaulMohn,
Correct, after the control is created you can modify any of its properties and then add it to the chart.
- Likes 1
Leave a comment:
-
Got it many thanks!
I removed
qs.Value = 1;
from the State.DataLoaded
PHP Code:else if (State == State.DataLoaded) { // qs.Value = 1; REMOVED
And I added
quantitySelector.Value = 1;
At the end of the #region Add Controls To Toolbar
PHP Code:#region Add Controls To Toolbar private void Add_Controls_To_Toolbar() { // Use this.Dispatcher to ensure code is executed on the proper thread ChartControl.Dispatcher.InvokeAsync((Action)(() => { //Obtain the Chart on which the indicator is configured chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart; if (chartWindow == null) { Print("chartWindow == null"); return; } quantitySelector = new NinjaTrader.Gui.Tools.QuantityUpDown(); //quantitySelector.ValueChanged += On_quantitySelector_ValueChanged; quantitySelector.PreviewKeyDown += On_quantitySelector_PreviewKeyDown; chartWindow.MainMenu.Add(quantitySelector); Is_ToolBar_Controls_Added = true; quantitySelector.Value = 1; })); } #endregion
So that it sets the value at the time it adds the Control? Thanks?
Leave a comment:
-
Hello
You made a new variable named qs but its an int, that is not what you need to do. You need to remove that variable to avoid that error. The qs variable needs to be your quantity selectors variable. If you added the quantity selector then you should already have a variable for that in your script. That is going to be where you add the control to the chart. You should be able to find that by looking for where you initially subscribe to the preview key method: += On_quantitySelector_PreviewKeyDown;
- Likes 1
Leave a comment:
-
Ok thanks I've moved it to the State.DataLoaded scope and removed NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown;
PHP Code:NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = null; // QS private bool Is_ToolBar_Controls_Added; private int qs; protected override void OnStateChange() {
PHP Code:else if (State == State.DataLoaded) { qs.Value = 1;
now I get the error
How do I get it working? Thanks!NinjaScript File Error Code Line Column
Testa.cs 'int' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) CS1061 624 8
i've checked Chelsea's InsertWPFControls() below
ChartCustomToolbarExample_NT8.zip (3.9 KB, 1073 views)
PHP Code:protected void InsertWPFControls() { if (panelActive) return; if (chartGrid.RowDefinitions.Count == 0) chartGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); tabControlStartColumn = System.Windows.Controls.Grid.GetColumn(chartWindow .MainTabControl); tabControlStartRow = System.Windows.Controls.Grid.GetRow(chartWindow.Ma inTabControl); chartGrid.ColumnDefinitions.Insert(tabControlStart Column, new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(30) }); chartGrid.RowDefinitions.Insert(tabControlStartRow , new System.Windows.Controls.RowDefinition() { Height = new GridLength(20) }); // including the chartTabControl move all items right of the chart and below the chart to the right one column and down one row for (int i = 0; i < chartGrid.Children.Count; i++) { if (System.Windows.Controls.Grid.GetColumn(chartGrid. Children[i]) >= tabControlStartColumn) System.Windows.Controls.Grid.SetColumn(chartGrid.C hildren[i], System.Windows.Controls.Grid.GetColumn(chartGrid.C hildren[i]) + 1); if (System.Windows.Controls.Grid.GetRow(chartGrid.Chi ldren[i]) >= tabControlStartRow) System.Windows.Controls.Grid.SetRow(chartGrid.Chil dren[i], System.Windows.Controls.Grid.GetRow(chartGrid.Chil dren[i]) + 1); } // set the columns and rows for our new items System.Windows.Controls.Grid.SetColumn(topMenu, System.Windows.Controls.Grid.GetColumn(chartWindow .MainTabControl)); System.Windows.Controls.Grid.SetRow(topMenu, tabControlStartRow); System.Windows.Controls.Grid.SetColumn(leftInnerGr id, tabControlStartColumn); System.Windows.Controls.Grid.SetRow(leftInnerGrid, System.Windows.Controls.Grid.GetRow(chartWindow.Ma inTabControl)); chartGrid.Children.Add(topMenu); chartGrid.Children.Add(leftInnerGrid); // let the script know the panel is active panelActive = true; }
But I'm not sure how to make use of it since it doesn't uses QuantitySelector variable in the InsertWPFControls().Last edited by PaulMohn; 03-17-2022, 11:00 AM.
Leave a comment:
-
Hello PaulMohn,
When you create the instance of the selector you would need to set the value at that point.
Generally UI controls can be created in State.DataLoaded and beyond. In most of the UI samples from the forum all of the UI work is done in a method called InsertWPFControls, that would be a good point to set a default.
This code would be too late to set a default:
NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown;
qs.Value = 1;
The sender is from an event so that would be after the control was created.
Leave a comment:
-
Hello Jesse, how could I set the default QuantitySelector value to 1? Currently it is 0 when loading the indicator on the chart and ?'d like to to set it to one if possible as default. Thanks!
I tried setting it to 1 just above the method but it's not working.
PHP Code:NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = null; // QS private bool Is_ToolBar_Controls_Added; private int qs; protected override void OnStateChange() {
PHP Code:NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown; qs.Value = 1; private void On_quantitySelector_PreviewKeyDown(object sender, KeyEventArgs p) { NinjaTrader.Gui.Tools.QuantityUpDown qs = sender as NinjaTrader.Gui.Tools.QuantityUpDown; if (p.Key == Key.Delete || p.Key == Key.Back) { p.Handled = true; qs.Value = 0; } if (p.Key >= Key.D0 && p.Key <= Key.D9) { p.Handled = true; string number = p.Key.ToString(); string newnumber = qs.Value.ToString(); number = number.Replace("NumPad", ""); number = number.Replace("D", ""); int num = int.Parse(newnumber + number); if (qs != null) qs.Value = num; } }
Leave a comment:
-
Thanks Jesse for letting me know. I'll test it asa.Originally posted by NinjaTrader_Jesse View PostHello PaulMohn,
The quantity selector is a WPF control so that could not be used in the property grid, you would need to use an int or double public property to make a input for the user.
Leave a comment:
-
Hi omololu. Thanks for letting me know. I see what you mean I've just downloaded it to check. There are 2 extra .zips (the ones from Jim's post I links in the share post)Originally posted by omololu View Post
Hi PaulMohn,
There are some contents in the submitted file in the User App Share that are not meant to be there ... please, review the contents.
omololu
Hi guys, Are there available order entry hot key that is based on the previous bar? Would like to implementorders by hot keys which could be quick & less noticeable. Cheers, Leo
I think moderation added them as I linked the zips links in the description.
Should be ok as the titles are distinct. Thanks.
Leave a comment:
-
Hi PaulMohn,Originally posted by PaulMohn View PostChelsea I was getting errors (missing ";" end ")") with the anonymous function. I found your other post
Access Chart Trade QTY input from an indicator
The anonymous function fix (added a pair of parenthesis at (Window.... and at ...})); )
PHP Code:ChartControl.Dispatcher.InvokeAsync((Action)(() => { quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown); }));
Great many thanks Chelsea i got it working thanks to your help and Jesse's.
I've submitted it to the User App Share.
The full script attached
There are some contents in the submitted file in the User App Share that are not meant to be there ... please, review the contents.
omololu
Leave a comment:
-
Hello PaulMohn,
The quantity selector is a WPF control so that could not be used in the property grid, you would need to use an int or double public property to make a input for the user.
Leave a comment:
-
Chelsea I had that extra idea in post #19 after omololu feedback.
Do you know if it is possible to add the Quantity Selector to the Properties as User Input field?
The goal would be to use it as an alternative to the hardcoded version (so users could type in their sizes in the properties rather that edit the script). Thanks!
Leave a comment:
-
Chelsea I was getting errors (missing ";" end ")") with the anonymous function. I found your other post
Access Chart Trade QTY input from an indicator
The anonymous function fix (added a pair of parenthesis at (Window.... and at ...})); )
PHP Code:ChartControl.Dispatcher.InvokeAsync((Action)(() => { quantitySelector = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown); }));
Great many thanks Chelsea i got it working thanks to your help and Jesse's.
I've submitted it to the User App Share.
The full script attached
Attached FilesLast edited by PaulMohn; 02-24-2022, 09:25 AM.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
90 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
144 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
83 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
257 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
335 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
Leave a comment: