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

Accessing scrollBar programatically

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

    Accessing scrollBar programatically

    I have strategy and inside it I want to access scrollBar (marked Yellow). Can someone help me how to access it (somehow like CHartcontrol), I want to access scrollBar and its arrow left (right) and manually click it.

    Thanks for help
    Pavel

    #2
    Hello kujista,

    Thank you for the post.

    While this is not something we would have a sample for, you can access various UI items by their automation ID's. I have a prior post explaining how to find automation ID's along with a sample use for the chart trader. It would be the same process, after finding the ID you could use the FindFirst method from a visual parent to locate the ID and object. The ID of the left arrow is: LineLeft



    To click anything that is a button, you could use the automation framework:


    Code:
    System.Windows.Controls.Button yesButton = window.FindFirst("InsertAutomationIDOfButton") as System.Windows.Controls.Button;
    System.Windows.Automation.Peers.ButtonAutomationPeer peer = new System.Windows.Automation.Peers.ButtonAutomationPeer(yesButton);
    System.Windows.Automation.Provider.IInvokeProvider invokeProv = peer.GetPattern(System.Windows.Automation.Peers.PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider;
    if (invokeProv != null) invokeProv.Invoke();


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      well i am not sure I understand but.. should I be able to get into variable yesButton the left arrow of scrollbar? Can I access it and then manually click it: yesButton.Click()
      or can you please guide me how to?

      Code:
      Code:
      chartWindow = System.Windows.Window.GetWindow(golemObj.ChartControl.Parent) as Chart;
      System.Windows.Controls.Button yesButton = chartWindow.FindFirst("LineLeft") as System.Windows.Controls.Button;
      System.Windows.Automation.Peers.ButtonAutomationPeer peer = new System.Windows.Automation.Peers.ButtonAutomationPeer(yesButton);
      System.Windows.Automation.Provider.IInvokeProvider invokeProv = peer.GetPattern(System.Windows.Automation.Peers.PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider;
      if (invokeProv != null) invokeProv.Invoke();

      Many many thanks
      Paul

      Comment


        #4
        Hello kujista,

        What specifically are you having difficulty with at this point?

        As noted this is not something we would have a specific sample for, but you can certainly explore the WPF structure and access objects in the ways described in the linked page. You will very likely need to dig into the chart windows visual tree similar to the image you had shown. I am unaware of any existing example of grabbing this specific control so likely this will take some experimentation on your end.

        Have you at this point set up a sample to locate the button and confirmed that is working? That would really be the first step before doing anything else. Once you have located the button and have a non-null object, you could work through the clicking logic to click it.

        In general, scrolling the chart is not something that is documented/supported through NinjaScript directly so how you approach this is going to depend on your goal and what you are trying to do with the scroll. Are you simply trying to step back similar to how the Left Arrow on the keyboard does this? If so, you may have more luck using simple keyboard commands however this is also not a NinjaScript concept. Sending keyboard events would just be a WPF/C# concept. You can find examples of how to use keyboard commands in C# and WPF by searching online for C# resources surrounding those concepts.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          As you mentioned using keyboard, i think is also way. To express what I am trying to achieve is shown on picture (attachment).

          I have strategy which also creates window form. In this form is selectBox, which contains every trade date and time i made. When I select item from selectbox I want all charts to scroll to this date and time of trade entry, so I can see how was the situation on each chart (in one workspace) and take screenshot. So I guess that I can move chart by pressing arrow Left or arrow Right.

          My questions are:
          1) if I get chart object, then focus it and send keypress event, will it move the chart? (i just test what is the last painter bar.. and that's it)
          2) If I have strategy in CHART 1, can I also set focus to Chart 2 -> send keypress event to make it scroll, and the same for chart 3, chart,4?

          If answer to question 1 is positive, then I guess I do not have use scrollbar at all. I am not sure if question 2 - can be solved. In NT7 I solved this by clicking the arrow of horizontal scrollbar and it did not work very well. And I did not succeed to access chart 2, chart 3 objects and make them scroll.

          Thanks a lot for reply and your kind support.

          Pavel Kujal

          Comment


            #6
            Hello kujista,

            Thanks for your questions.

            As we can test selecting chart bars or drawing objects and using the keyboard to scroll the chart, this should work. The Rollover indications indicator can provide some direction for focusing elements and invoking keyboard presses.

            For question 2, it would be possible to loop through all open windows, find the window you want to target and then perform your focusing, key presses, and unfocusing. I am not sure how you intend to check the time in view, however. If I were to try this, I would use OnRender() and check if the DateTime of ChartBars.FromIndex and ChartBars.ToIndex would include the DateTime of the execution/trade, and if it is not, to invoke keyboard presses to scroll to that point.

            Since OnRender() would have to be available from a script, you may consider having an indicator added to the target chart so when you want to scroll that chart, you can use the indicator on that chart to monitor the bars in view and set a public bool if the requested execution is in range. When looping through windows, you could reference that indicator in the ChartControl.Indicators collection to check the if that bool is true or not.

            Looping through windows to perform an action on a target window:
            Code:
            foreach (var window in NinjaTrader.Core.Globals.AllWindows)
            {
                //check if the found window is a Chart window, if not continue looking
                if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
            
                window.Dispatcher.InvokeAsync(new Action(() =>
                {
                    //try to cast as a Chart, if it fails it will be null
                    var foundChart = window as NinjaTrader.Gui.Chart.Chart;
                    if (foundChart == null) return;
            
                }));
            }
            Rollover Indications indicator - https://ninjatraderecosystem.com/use...indications-2/

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

            This is getting a ways into unsupported code, so this advice is mostly speculative.

            We look forward to being of further assistance.
            Last edited by NinjaTrader_Jim; 10-21-2019, 06:31 AM.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello Jim,

              Your answer was totally helpful and I am very grateful for it. It solved my problem, thanks a lot and wish you Marry X-Mas.

              Pavel

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Aviram Y, Today, 05:29 AM
              0 responses
              1 view
              0 likes
              Last Post Aviram Y  
              Started by quantismo, 04-17-2024, 05:13 PM
              3 responses
              25 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by ScottWalsh, 04-16-2024, 04:29 PM
              7 responses
              34 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cls71, Today, 04:45 AM
              0 responses
              6 views
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              216 views
              1 like
              Last Post PaulMohn  
              Working...
              X