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

Button issue

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

    Button issue

    Hi
    I used LONGSHORTToolbarButtonsB9 to create a Strategy. All is working but I would like to have an internal code to turn off the Button. IE if the long trade is filled turn the Long trade button off

    I tried many possibilities but none work except just turning the longButtonClicked = false; but that does not change the button on the chart and therefore i have to reset the strategy to get going again

    There must be a way to do that as I was able to in NT7 but really trying to learn NT8

    Thank you in advance

    #2
    Hello richbois,

    Thank you for your post.

    I've created a simple example from the LONGSHORTToolbarButtonsB9 script - in this example, once you click long or short and an order is filled, the button is disabled and also we change the button text to "Long disabled" or "Short disabled". Clicking the opposite button will then reverse the position, re-enable the other button and disable the clicked button.

    Please let us know if we may be of further assistance to you.


    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello richbois,

      Thank you for your post.

      I've created a simple example from the LONGSHORTToolbarButtonsB9 script - in this example, once you click long or short and an order is filled, the button is disabled and also we change the button text to "Long disabled" or "Short disabled". Clicking the opposite button will then reverse the position, re-enable the other button and disable the clicked button.

      Please let us know if we may be of further assistance to you.

      Thank you Kate

      Will work on that tomorrow

      will let you know how it goes

      Richard

      Comment


        #4
        Originally posted by NinjaTrader_Kate View Post
        Hello richbois,

        Thank you for your post.

        I've created a simple example from the LONGSHORTToolbarButtonsB9 script - in this example, once you click long or short and an order is filled, the button is disabled and also we change the button text to "Long disabled" or "Short disabled". Clicking the opposite button will then reverse the position, re-enable the other button and disable the clicked button.

        Please let us know if we may be of further assistance to you.

        i tried many things but none are working maybe i didnt explain myself properly

        When the Strategy starts i get these Long NO Short No buttons
        Then i press on both buttons or only the 1 i want and i get Long ok Short OK

        then when the conditions are met for a trade to be executed the trade is submitted as per the code below

        if (orderId.Length == 0
        && atmStrategyId.Length == 0
        && longButtonClicked == true
        && Close[1] >= Close[2]
        && hMA3indi.SlopeColor[1] >= hMA3indi.SlopeColor[2]
        && hMA3indi.ma2[1] <= hMA3indi.ma2[2]
        )

        {
        isAtmStrategyCreated = false; // reset atm strategy created check to false
        atmStrategyId = GetAtmStrategyUniqueId();
        orderId = GetAtmStrategyUniqueId();
        AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "RTY HMA", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {

        longButtonClicked = false; Print("Long button Not active" + longButtonClicked);
        // button.Content = "Long NO";
        // button.Name = "LongButton";

        as you can see the longButtonClicked goes to false which is what i want but i would also want the button content to change but the system wont accept my 2 lines of code

        I am sure there is a way but i just can see it

        thank you
        Attached Files

        Comment


          #5
          Hello richbois,

          Thank you for your reply.

          In your code you're referring to button generically - it doesn't work because you're not referring to the actual button object you assigned the button to. If you look at the example code I provided you'll see that I change the button Content and Name by referring to the actual object:

          Code:
          private System.Windows.Controls.Button longButton;
          private System.Windows.Controls.Button shortButton;
          
          ...
          
          //in OnButtonClick:
          
          longButton.Content = "Long disabled";
          longButton.Name = "LongDisabled";
          
          shortButton.Name = "ShortButton";
          shortButton.Content = "SHORT";
          See how I'm referring to the variable I stored the button object in? You'd need to mimic that for it to work.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Kate View Post
            Hello richbois,

            Thank you for your reply.

            In your code you're referring to button generically - it doesn't work because you're not referring to the actual button object you assigned the button to. If you look at the example code I provided you'll see that I change the button Content and Name by referring to the actual object:

            Code:
            private System.Windows.Controls.Button longButton;
            private System.Windows.Controls.Button shortButton;
            
            ...
            
            //in OnButtonClick:
            
            longButton.Content = "Long disabled";
            longButton.Name = "LongDisabled";
            
            shortButton.Name = "ShortButton";
            shortButton.Content = "SHORT";
            See how I'm referring to the variable I stored the button object in? You'd need to mimic that for it to work.

            Please let us know if we may be of further assistance to you.
            My issue is that i am trying to have the strategy do the OnButtonClick not me manually to see

            Is your code doing that maybe I am to inexperience to understand your code since it seems to be in the ONButtonClick section

            Comment


              #7
              PS this is what i added to the code


              isAtmStrategyCreated = false; // reset atm strategy created check to false
              atmStrategyId = GetAtmStrategyUniqueId();
              orderId = GetAtmStrategyUniqueId();
              AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "RTY HMA", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {

              longButtonClicked = false; Print("Long button Not active" + longButtonClicked);
              longbutton.Content = "Long NO";
              longbutton.Name = "LongButton";

              Comment


                #8
                here is my script maybe you could help point to the errors in it

                Thank you Kate

                Richard
                Last edited by richbois; 02-26-2021, 01:27 AM.

                Comment


                  #9
                  Hello richbois,

                  Thank you for your reply.

                  We can't debug a script on your behalf, and there's a lot you've got going on here. We would want to see a simplified example script that just focuses on the buttons and what you're trying to do to change them. It's not clear here how the buttons are being triggered so we'd want to see a script that just focuses on that part of the logic. I would suggest focusing on getting the buttons to make the change when clicked on first before attempting to trigger them from the strategy as well.

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Kate View Post
                    Hello richbois,

                    Thank you for your reply.

                    We can't debug a script on your behalf, and there's a lot you've got going on here. We would want to see a simplified example script that just focuses on the buttons and what you're trying to do to change them. It's not clear here how the buttons are being triggered so we'd want to see a script that just focuses on that part of the logic. I would suggest focusing on getting the buttons to make the change when clicked on first before attempting to trigger them from the strategy as well.

                    Thanks in advance; I look forward to assisting you further.
                    Ok let me try to explain my intentions better. At the moment the buttons are working perfectly when I physically press them. What I need to also be able to do is that once a trade is executed the strategy does the equivalent of pressing the button.
                    That is the part of code that I need. I am using the LONGSHORTToolbarButtonsB9 example as a base for my strategy.
                    Thank you
                    Last edited by richbois; 02-26-2021, 04:40 AM.

                    Comment


                      #11
                      Thank you Kate I finally figured it out

                      after the Trade was executed I needed these lines of code to change the Button and stop future trades

                      ChartControl.Dispatcher.InvokeAsync((() =>
                      {
                      longButton.Content = "Long NO";
                      longButton.Name = "LongButton";
                      longButtonClicked = false; Print("auto change long" + longButtonClicked);
                      }));

                      Comment


                        #12
                        Yes it took me forever to work this one out as well!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cre8able, Today, 01:16 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post cre8able  
                        Started by chbruno, 04-24-2024, 04:10 PM
                        3 responses
                        48 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by samish18, Today, 01:01 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by WHICKED, Today, 12:56 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by WHICKED, Today, 12:45 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X