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

Duplicate in new tab

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

    Duplicate in new tab

    Hi,

    What code/method can I use to duplicate the current chart on a new tab that an indicator is operating on.

    e.g

    if(mylogic)
    {duplicate in new tab}


    Thanks

    #2
    Hello b16_aln,

    Thank you for the post.

    There is currently no means to open new charts/tabs from NinjaScript so I will put in a feature request here.


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

    Comment


      #3
      what about using the following to action the hotkey to duplicate in new tab?

      System.Windows.Forms.Sendkeys.Send(insert duplicate in new tab hotkey);

      Comment


        #4
        Hello b16_aln,

        You could try doing that however in NT8 windows forms is no longer used so sendkeys usually does not work if the specific control needed for the event is not in focus. I am unsure if that applies for that command, you could certainly give it a try.

        Because hotkeys are user specific and there is not a default for new tab this would be something you could try but would require additional steps of configuration before it could work.

        You could take a look at the rollover indications indicator to see how it manages sending keys to the chart to change instrument, a similar approach would be needed to send other keys. As noted I am not certain what needs focus for the new tabs hotkey event, so it may just work or it may not when targeting the ChartControl that is something you could test.
        https://ninjatraderecosystem.com/use...indications-2/


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          thanks, it does work but you have to make sure the new duplicated chart does not have the logic trigger or you get an endless amount dupicated charts. So before using send keys have to set the trigger to false.

          In developing this i have a couple if questions you might be abke to helo with;

          1. How do I make sure the send keys is only actioned on the chart. When i tested it there and clicked on another pc windows, the hotkeys were still being actioned e.g word wouls be typing the hotkeys out. I found someone had used the following code on nt7 so is there an nt8 equivalent?


          // Make sure chart window is active.
          ChartControl.ParentForm.Activate();


          2. Is there a way to lookup the correct hotkey within ninjascript, e.g the way you can use chartcontrol to look up bar period etc?

          Comment


            #6
            Hello b16_aln,

            1. How do I make sure the send keys is only actioned on the chart. When i tested it there and clicked on another pc windows, the hotkeys were still being actioned e.g word wouls be typing the hotkeys out. I found someone had used the following code on nt7 so is there an nt8 equivalent?
            This would be the information I provided in the last post, that indicator contains a sample of how you could send keys in NT8. To send keys to a control you need to specify what control and focus it like show in the linked indicator. SendKeys is not specific and just sends keys which often will not work in NT8/WPF applications.

            Is there a way to lookup the correct hotkey within ninjascript, e.g the way you can use chartcontrol to look up bar period etc?
            Not that I am aware of, the hotykey system is not currently documented/exposed for NijnaScript use.

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

            Comment


              #7
              I tried the ChartControl.OwnerChart.Focus(); as per the sample you provided however I am getting error in output, says "calling thread must be STA, because many UI components require this." How do I get it to work?

              Comment


                #8
                Hello b16_aln,

                Where are you using this code from?

                You may need to utilize a dispatcher depending on where it is being used, in the indicator this comes from this is being used in a buttons event handler which seems to not require any dispatching where it is used.

                For testing purposes I would suggest to just use the indicator as is because that already works. You could modify what it is doing for the button click to test and find the logic needed. Once you are satisfied with your modifications you could move into more advanced items like making conditions as you previously noted.

                There is a dispatcher being used for the chart control on line 72 in case you require a dispatcher where you are using it, that would be the format of how a dispatcher is used the code goes inside the { } braces.


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

                Comment


                  #9
                  Thanks but i cannot read and understand the code referenced to, it's fairly complex.

                  I am trying to call from onbarupdate. Could you just provide the script that i need to enter that will ensure the tab running my indicator is selcted before I run the send keys method. I also tried ChartPanel.Focus(); but getting the same error.

                  Comment


                    #10
                    Hello b16_aln,

                    From OnBarUpdate that would require a dispatcher, there is an example of a dispatcher on line 72 which would go around the other code you are writing. The line 74 code is how wrapped code would look, inside of the curly braces. Wherever you use the Focus method you would need the dispatcher syntax surrounding it like on line 72.

                    Code:
                    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                    {
                                        ChartControl.OwnerChart.Focus();
                                        //other code still in the dispatched context
                     }));
                    Alternatively you could execute the code from the buttons event instead which should not require a dispatcher there.

                    I wouldn't be able to code this for you however all of what would be required to execute the task is in the sample that I had provided. This is a more advanced programming task which is not specific to NinjaScript so there is no specific supported help or samples that I can provide for this concept, this is something you can explore and create if you wish.

                    The code being used in this sample is general C# code used for WPF applications to target a UIControl and then execute a key press, if you wanted to learn more about this framework you can search online for WPF learning materials surrounding UI controls and automation.


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

                    Comment


                      #11
                      Removed my post here. Continued below
                      Last edited by b16_aln; 01-02-2020, 01:53 AM. Reason: Frustrated outburst

                      Comment


                        #12
                        Jesse, apologies for my previous post and thanks for your input here. I realised you did actually include the dispatcher code above. I was getting frustrated with my failed attempts here and this is more advanced than I am used too. I will keep pressing on with it.

                        Comment


                          #13


                          Thanks for your assistance in solving this.
                          Last edited by b16_aln; 05-23-2020, 06:16 AM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by renewsaltwater, Today, 01:15 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post renewsaltwater  
                          Started by cyberpete76, 03-27-2023, 12:29 AM
                          6 responses
                          262 views
                          1 like
                          Last Post slightly  
                          Started by slightly, Today, 12:49 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post slightly  
                          Started by sdauteuil, 09-23-2021, 10:16 AM
                          4 responses
                          1,209 views
                          0 likes
                          Last Post jacobpescaia44  
                          Started by agclub, 04-21-2024, 08:57 PM
                          5 responses
                          34 views
                          0 likes
                          Last Post agclub
                          by agclub
                           
                          Working...
                          X