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 stafe, 04-15-2024, 08:34 PM
        6 responses
        30 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by adeelshahzad, Today, 03:54 AM
        4 responses
        25 views
        0 likes
        Last Post adeelshahzad  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        17 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X