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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        93 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        138 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        123 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        73 views
        0 likes
        Last Post PaulMohn  
        Working...
        X