Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        600 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X