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!
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
NinjaTrader
Trade Buttons NT8
Collapse
X
-
Hello tonynt,
Thanks for your post.
The buttons are added to a grid, so finding where the grid is created will be where its HorizontalAlignment and VerticalAlignment properties can be set. We can see that they are set to Top Right at line 68.
Code:myGrid = new System.Windows.Controls.Grid { Name = "MyCustomGrid", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top };
Please let us know if you have any questions.JimNinjaTrader Customer Service
-
Hello,
thank you for your reply. Sorry that I missed this, I was fixed on the code I had in NT7 that was different.
Thanks a lot for this example, this is a great help!
One question more please: can the size of the buttons be reduced? This will be great when buttons are added.
Thank you!
Tony
Comment
-
Hello tonynt,
These buttons are WPF and not necessarily NinjaScript. As such, external resources on these items could be used for further direction. I have included an external link to Microsoft's documentation on Buttons. You can use the Width, Height, MinWidth/MinHeight, and MaxWidth/MaxHeight properties for customizing size.
WPF Buttons - https://docs.microsoft.com/en-us/dot...tframework-4.5
Please let us know if we can be of further assistance.JimNinjaTrader Customer Service
- Likes 1
Comment
-
Hello,
thank you for your reply. I can add from this sample buttons and work with.
But I have one major problem now that prevents me from continuing: in NT7 I could access buttons properties from onbarupdate, eg when flat then reset the buttons with text and colors.
I can´t get it from this sample. In NT7 I had in variables eg "private ToolStripButton _exits = null;" and working with this "_exits" in the code.
How can this be done in the logic from this example for NT8 please. If you can give me please the idea with an example or string I can go on with all my work.
Thank you!
Tony
Comment
-
Hello tonynt,
NinjaTrader 8 is multithreaded and OnBarUpdate events happen on a different thread than the UI thread. A Dispatcher will have to be used to modify UI elements from another thread.
If I try the following in OnBarUpdate, I do not have issue modifying the button color:
Code:if (CurrentBar % 2 == 0) ChartControl.Dispatcher.InvokeAsync((() => { shortButton.Background = Brushes.Green; })); else ChartControl.Dispatcher.InvokeAsync((() => { shortButton.Background = Brushes.Red; }));
Multi Threading Considerations - https://ninjatrader.com/support/help...-threading.htm
I look forward to being of further assistance.JimNinjaTrader Customer Service
Comment
-
Hello,
thank you for your reply! I meant to have in onbarupdate in the sample script
"if(Position.MarketPosition == MarketPosition.Flat)
{button.Content = "LONG";
button.Name = "LongButton";
longButtonClicked = false;}
This doesnt work and there appears a message concerning "button" when compiling.
Thanks!
Tony
Comment
-
Hello tonynt,
There is no object called "button" in the sample script aside from the local Windows.Controls.Button in OnButtonClick. If you use the snippet from post #6 in the original example, you can observe the buttons getting updated in OnBarUpdate().
Please let us know if you are seeing different behavior when applying the snippet to the original version.JimNinjaTrader Customer Service
Comment
-
Hello,
from that sample and your replies I can work with the buttons for handling conditions, entries, targets, stops...
The only "problem" I have is that I can not reduce the width of the buttons (I found how to change height, even how to center the horizontal alignment for text...) but not the width. Yes, they are getting smaller when chart is resized, but how to have them by default with less width.
Can you give me please an idea how to reduce the width of the buttons because theyoverlay the bars to the right.
Thank you!
Tony
Comment
-
Hello,
yes of course, thank you for the link. I found Font Size, Height, Width, HorizontalAlignment for Text, Border Brushes...
When I change fontsize and height all works fine, but whatever number I set to width its always the same width of buttons when enabling script. I post one button here so that you see that I added to the basic sample
Name = "LongButton", Content = "LONG", Foreground = Brushes.DarkGreen, Background = Brushes.LightGreen, FontSize = 10, Height = 21, Width = 10, HorizontalAlignment = HorizontalAlignment.Center, BorderBrush = Brushes.Transparent
Thank you!
Tony
Comment
-
Hello,
thank you for your reply. Testing with different numbers for width and maxwidth, buttons have same size eg with
longButton = new System.Windows.Controls.Button
{Name = "LongButton", Content = "LONG", Foreground = Brushes.DarkGreen, Background = Brushes.LightGreen, FontSize = 10, Height = 21, Width=5, MaxWidth = 10, HorizontalAlignment = HorizontalAlignment.Center, BorderBrush = Brushes.Transparent};
shortButton = new System.Windows.Controls.Button
{Name = "ShortButton", Content = "SHORT", Foreground = Brushes.DarkRed, Background = Brushes.LightSalmon, FontSize = 10, Height = 21, Width= 10, MaxWidth = 30, HorizontalAlignment = HorizontalAlignment.Center, BorderBrush = Brushes.Transparent};
Thank you!
Tony
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Padan, Today, 02:02 AM
|
0 responses
2 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
405 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
||
Started by yertle, Yesterday, 05:49 PM
|
2 responses
11 views
0 likes
|
Last Post
by yertle
Today, 12:12 AM
|
||
Started by kaywai, Today, 12:06 AM
|
0 responses
8 views
0 likes
|
Last Post
by kaywai
Today, 12:06 AM
|
||
Started by kaywai, 03-25-2024, 10:04 PM
|
3 responses
37 views
0 likes
|
Last Post
by kaywai
Yesterday, 11:57 PM
|
Comment