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

How to trigger a button click in my code

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

    How to trigger a button click in my code

    Hi,
    I have two buttons in my code, a Buy and a Sell that I like to be triggered either by a click or through the code.
    • myBuyButton.Click += OnMyButtonClick;
    • mySellButton.Click += OnMyButtonClick;
    I do believe I need to call the method OnMyButtonClick so I tried the following:
    • OnMyButtonClick(MyBuyButton) to simulate the buy button click
    • OnMyButtonClick(MySellButton) to simulate the sell button click

    None of them works.
    Attached Files

    #2
    Hello GoodBro,

    Welcome to the NinjaTrader forums!

    The OnButtonClick() event handler method will be run when the button is clicked.

    Currently this code sets a variable, like longButtonClicked. In OnBarUpdate() if this variable is set, and a quite a few other conditions are also true at at the same time (&& Close[1] >= MAX(High, 2)[2] + 0 * TickSize && High[1] < CurrentDayOHL().CurrentHigh[1] && High[0] > High[1]), an order is submitted with an order method such as EnterLong().

    Below I am also providing a link to a forum post with helpful information about getting started with programming in C#.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      This is how I find the chart trader buttons in my addon:

      Code:
      Button buyMktButton = parentWindow.FindFirst("ChartTraderControlQuickBuyMarketButton") as Button;
      Button sellMktButton = parentWindow.FindFirst("ChartTraderControlQuickSellMarketButton") as Button;​
      Then I use WPF automation Ids to invoke them like this:
      Code:
      using System.Windows.Automation;
      using System.Windows.Automation.Peers;
      using System.Windows.Automation.Provider;​
      
      ...
      ...
      ButtonAutomationPeer buyMktButtonPeer = new ButtonAutomationPeer(buyMktButton);
      IInvokeProvider buyMktButtonInvokeP = buyMktButtonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
      buyMktButtonInvokeP.Invoke();​
      ...


      See here for reference: https://stackoverflow.com/a/728444/2877168

      Comment


        #4
        I was looking for this solution for some time. ​​Thanks a lot to skipper-flatiron-18 ​​for this post.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ender_wiggum, Today, 09:50 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by rajendrasubedi2023, Today, 09:50 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by geotrades1, Today, 10:02 AM
        0 responses
        4 views
        0 likes
        Last Post geotrades1  
        Started by bmartz, Today, 09:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by geddyisodin, Today, 05:20 AM
        3 responses
        24 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X