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

Trade Buttons NT8

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

    Trade Buttons NT8

    Hello,

    there is a strategy example from NT-Zachary and I want to ask please how the buttons can be moved to upper left corner. I couldnt find in the code.



    Thank you!
    Tony

    #2
    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
    };
    Changing HorizontalAlignment to HorizontalAlignment.Left will move the grid to the Top Left.

    Please let us know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      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


        #4
        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

        Comment


          #5
          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


            #6
            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;
                }));
            Please see the documentation page below for more information on multi threading considerations.

            Multi Threading Considerations - https://ninjatrader.com/support/help...-threading.htm

            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              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


                #8
                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


                  #9
                  Hello,

                  I wanted to show with the snippet in #7 what I need to do. Got it now with your reply!

                  Thank you for your support!

                  Best regards
                  Tony

                  Comment


                    #10
                    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
                    Last edited by tonynt; 01-24-2019, 09:27 AM. Reason: typing error

                    Comment


                      #11
                      Hello tonynt,

                      Have you used the properties suggested in post #4? I don't have an issue making the buttons smaller changing Width and MinWidth.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        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


                          #13
                          Hello tonynt,

                          You aren't setting MinWidth in your example. Have you tried also using MinWidth/MaxWidth and MinHeight/MaxHeight as mentioned in post #4?

                          Please let me know if you are unable to change the width when setting both Width and MinWidth.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            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


                              #15
                              Jim and colleagues,

                              I have in now Width=5, MaxWidth = 10, but the width of the buttons does not change wjatever value I use.

                              ???

                              Thank you!
                              Toony

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              168 views
                              0 likes
                              Last Post jeronymite  
                              Started by cre8able, Today, 04:22 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X