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

ChartTrader Call Click Button

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

    ChartTrader Call Click Button

    I have this code in "OnStartup" method. I want call the click event of btnMkt from another function. Is this possible?
    Now nothing happend.

    example: btnMkt.PerformClick();



    Code:
    Button btnMkt;
    void clickBuyMKT() {
        btnMkt.PerformClick();
    }
    protected override void OnStartUp() {
        for (int i = 0; i <= ChartControl.Controls.Count - 1; i++) {
            if (ChartControl.Controls[i] == ChartControl.Controls["pnlChartTrader"]) {
                Panel p = (Panel) ChartControl.Controls["pnlChartTrader"];
                for (int j = 0; j <= p.Controls.Count - 1; j++) {
                    if (p.Controls[j] == ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"]) {
                        Control ctrader = ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"];
                        for (int k = 0; k <= ctrader.Controls.Count - 1; k++) {
                            if (ctrader.Controls[k].Name == "btnBuyMarket") {
                                Button btnMkt = (Button) ctrader.Controls[k];
                            }
                        }
                    }
                }
            }
        }
    }

    #2
    Hello nekroart,

    Thanks for your post.

    We do not have any documentation on triggering UI controls in NT7 and could not offer support for such implementations. For NT8, we would recommend using the AddOn framework.

    NT8 AddOn Framework - https://ninjatrader.com/support/help...-us/add_on.htm

    When I tested your code, I was getting a Object reference not set to an instance of an object error since the example is setting a local btnMkt instead of the class level button. With this correction btnMkt is not null, however the PerformClick still does not work.

    PerformClick looks like the prefered way to trigger win forms buttons, but you may wish to investigate some other approaches as you are experimenting. I've included a StackOverflow link below.

    Assume that I have a WinFoms project. There is just one button (e.g. button1). The question is: is it possible to trigger the ButtonClicked event via code without really clicking it?


    I'll leave this thread open ended for any community members that may have experience in triggering button presses in NinjaTrader 7.

    If you have another question involving documented/supported NinjaScript, please feel free to open a new thread.
    JimNinjaTrader 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

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      3 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Working...
      X