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

Code Snipet: Show to show one Dropdown InstrumentList selectable in chart

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

    Code Snipet: Show to show one Dropdown InstrumentList selectable in chart

    Hello:

    The default instrument list on the left of chart have only 'Defaults List' instruments. I'm working on one indicator to show one new Dropdown with All Instrument Lists and, on click, fill the default instrument list with the instruments..

    I'm in the last step. I have one new Intruments Lists Dropdown working, and i fill the default instrument list ok. But, when i click into one item of default instrument list, anythink occurs.

    May be The items object (ToolStripDropDownItem) of default item have attached one event on click.

    Ok, i don't remove items, for test, i change only 'Text' property to one new Instrument Text. But on click, the chart try to reload, but seems it's only find Item Text click on the 'Default list'...

    ¿Any idea?

    Here two indicators.

    The first one (jaToolBarInstrumentList), i show two new dropdown lists, one with instrument lists and another with instruments of item selected in the first dropdown. But i don't know how to change chart instrument on click...

    The second one (jaToolBarInstrumentListTest2), i try to use the default dropdown list named ('btnInstrument):
    ddInstruments=(ToolStripDropDownButton) myToolBar.Items.Find("btnInstrument",false)[0];

    For test, i set the 'text' property of the second item in the list to: "AAPL Default", and add one new last instrument with this Text too.
    The last item never works. And the second item changed, only works if 'AAPL' instrument it's in the Default List.

    May be, this declaration in the Class CharControl can give us an idea:
    internal event InstrumentNotifyEventHandler InstrumentSelected;

    Thank you to Richard Todd from www.movethemarkets.com for his ToolBarExample, and to zweistein for his Wilson.ORMapper.GetReader sample.

    Of course, all in this post it's indocumented and can to hang NT
    Attached Files

    #2
    Hi jatubio,

    Thanks for sharing on this information!

    While this is unsupported material, I hope you get some good feedback from other users.
    TimNinjaTrader Customer Service

    Comment


      #3
      Post it if you figure it out. I'd like to check it out. I haven't seen it done before....

      Last edited by mountainclimber; 05-07-2010, 10:02 AM.

      Comment


        #4
        Of course, if i ever get it to work, I'll post in this thread. But now I don't see the light ..

        Comment


          #5
          Hello jatugo,

          You write:
          >>The first one (jaToolBarInstrumentList), i show two new dropdown lists, one with instrument lists >>and another with instruments of item selected in the first dropdown. But i don't know how to >>change chart instrument on click...

          You just need to find the ChartForm : ChartForm chartform= FindCF();
          then you do chartform.Instrument = yourselectedinstrument;

          this will reload the new instrument on the chart.

          Actually I above code snipped is from my code to select a chart and copy the screen shot of the chart via NinjaTinyMobileTrader to a mobile phone.

          To your code hanging: check for cross threading problems and always execute your request on the correct thread.

          good luck

          andreas

          Comment


            #6
            andreas:

            What is the object on which the FindCF function is called?

            Comment


              #7
              Originally posted by jatubio View Post
              Of course, if i ever get it to work, I'll post in this thread. But now I don't see the light ..
              Did you ever get it to work?

              Thanks!
              Daniel

              Comment


                #8
                How to Programmatically Chg Indicator Public Property Value And Refresh Chart?

                Hello,

                I was able to use jatubio's excellent code sample from his original post below to put a button on the righthand side of the NinjaTrader ToolBar, and was able to subscribe to the button's click event and show a simple MessageBox when I clicked on the button.

                Then, I created a simple "MySMA" Indicator that displays a simple SMA on the chart, and my goal is to change the SMA's Period value from its default value of 25 to 100 in the Indicator's Property Grid when I click the button, and have the indicator on the chart refresh and display the SMA with a period of 100.

                Unfortunately, when I simply set MySMA's public property called "MySMAPeriodValue" from the button click event by writing...

                this.MySMAPeriodValue = 100;

                ...it neither refreshes the chart with the new SMA Period, nor does it even change the value of "MySMAPeriodValue" that is shown in the Property Grid
                when I right click on the chart, choose "Indicators", and select my indicator. This is in spite of the fact that when I Print() the value of this.MySMAPeriodValue after I set it, it is correctly 100.

                Does anybody know how I could force my "MySMA" indicator's Property Grid field for "MySMAPeriodValue" to change from 25 to 100 programmatically from a button click?

                Thank you very much in advance,

                Equity Trader

                Comment


                  #9
                  Originally posted by EquityTrader View Post
                  Hello,

                  I was able to use jatubio's excellent code sample from his original post below to put a button on the righthand side of the NinjaTrader ToolBar, and was able to subscribe to the button's click event and show a simple MessageBox when I clicked on the button.

                  Then, I created a simple "MySMA" Indicator that displays a simple SMA on the chart, and my goal is to change the SMA's Period value from its default value of 25 to 100 in the Indicator's Property Grid when I click the button, and have the indicator on the chart refresh and display the SMA with a period of 100.

                  Unfortunately, when I simply set MySMA's public property called "MySMAPeriodValue" from the button click event by writing...

                  this.MySMAPeriodValue = 100;

                  ...it neither refreshes the chart with the new SMA Period, nor does it even change the value of "MySMAPeriodValue" that is shown in the Property Grid
                  when I right click on the chart, choose "Indicators", and select my indicator. This is in spite of the fact that when I Print() the value of this.MySMAPeriodValue after I set it, it is correctly 100.

                  Does anybody know how I could force my "MySMA" indicator's Property Grid field for "MySMAPeriodValue" to change from 25 to 100 programmatically from a button click?

                  Thank you very much in advance,

                  Equity Trader
                  Can you post your code?

                  Comment


                    #10
                    Hi Sledge,

                    Good idea. I have attached the code to my post. Lines 64-68 show my attempt to change the Public Property of my Indicator programmatically:

                    private void toolStripButton_Click(object sender, EventArgs e)
                    {
                    MySMAPeriodValue = 100;
                    Print("MySMAPeriodValue=" + MySMAPeriodValue);
                    }

                    If you run this code and click on the "Change MySMAPeriodValue from 25 to 100" button on the right side of the NinjaTrader toolbar, you will notice that the "Print()" statement prints "MySMAPeriodValue=100", but when I look at my indicator in its property grid, the MySMAPeriodValue field is still 25. Also, the indicator on the chart doesn't get refreshed and redrawn as a 100-period SMA. It just stays as a 25-period SMA.

                    Thank you very much!

                    Equity Trader
                    Attached Files

                    Comment


                      #11
                      Question #1

                      Do you have toolStripButton_Click in any other code you have worked on?

                      Originally posted by EquityTrader View Post
                      Hi Sledge,

                      Good idea. I have attached the code to my post. Lines 64-68 show my attempt to change the Public Property of my Indicator programmatically:

                      private void toolStripButton_Click(object sender, EventArgs e)
                      {
                      MySMAPeriodValue = 100;
                      Print("MySMAPeriodValue=" + MySMAPeriodValue);
                      }

                      If you run this code and click on the "Change MySMAPeriodValue from 25 to 100" button on the right side of the NinjaTrader toolbar, you will notice that the "Print()" statement prints "MySMAPeriodValue=100", but when I look at my indicator in its property grid, the MySMAPeriodValue field is still 25. Also, the indicator on the chart doesn't get refreshed and redrawn as a 100-period SMA. It just stays as a 25-period SMA.

                      Thank you very much!

                      Equity Trader

                      Comment


                        #12
                        Originally posted by sledge View Post
                        Question #1

                        Do you have toolStripButton_Click in any other code you have worked on?


                        Q#2 Have you restarted NT?

                        Comment


                          #13
                          Originally posted by sledge View Post
                          Q#2 Have you restarted NT?
                          OK - it's late and I'm confusing myself now haha (I duplicated your code with SAVE AS, and it looked like it was calling the previous registered click place)... I would need to retest. Keep these callbacks unique?

                          Anyways, it looks like your "this" is in the wrong spot. It isn't need into the onbarupdate, but it is needed here on assignment.




                          private void toolStripButton_Click(object sender, EventArgs e)
                          {

                          this.MySMAPeriodValue = 100;
                          Print("1MySMAPeriodValue=" + MySMAPeriodValue );
                          }

                          Comment


                            #14
                            Hi Sledge,

                            A+, Man! Your insight about event registration fixed the first half of my problem!

                            The problem was that my code said "if there is no button on the toolbar, then add the button and subscribe THIS INSTANCE of the MySMA indicator to its click event". The problem with that logic was that when new instances of the MySMA indicator were added to the chart, they never subscribed to the button click event since my logic said to only subscribe if there is no button. So only the first instance of the indicator ever subscribed!!! I have uploaded the NEW code, where I make sure that each new indicator subscribes to the button click event, in case it could help anybody else.

                            Once this fix was in place, the MySMAPeriodValue field in the MySMA Indicator's Property Grid shows a value of 100, as it should! That fixed the first half of my problem.

                            The next half of my problem is that even though the property grid displays 100 when I click the button, the chart doesn't automatically get updated with the new 100-period MySMA until I press "F5" or click on the "Reload NinjaScript" context menu item.

                            Sledge, or anybody, do you have any ideas about how to cause "Reload NinjaScript" to occur programmatically? You should be able to reproduce the problem using the indicator code I uploaded.


                            Gold medal for sledge!

                            Thank you so much!

                            Equity Trader
                            Attached Files

                            Comment


                              #15
                              Yes, I saw that. I kept new bars off the screen then added the indicator, and then scrolled over and they were in 100.

                              But yes, I can see your need for reload the whole chart instead.

                              hmmmm



                              Originally posted by EquityTrader View Post
                              Hi Sledge,

                              A+, Man! Your insight about event registration fixed the first half of my problem!

                              The problem was that my code said "if there is no button on the toolbar, then add the button and subscribe THIS INSTANCE of the MySMA indicator to its click event". The problem with that logic was that when new instances of the MySMA indicator were added to the chart, they never subscribed to the button click event since my logic said to only subscribe if there is no button. So only the first instance of the indicator ever subscribed!!! I have uploaded the NEW code, where I make sure that each new indicator subscribes to the button click event, in case it could help anybody else.

                              Once this fix was in place, the MySMAPeriodValue field in the MySMA Indicator's Property Grid shows a value of 100, as it should! That fixed the first half of my problem.

                              The next half of my problem is that even though the property grid displays 100 when I click the button, the chart doesn't automatically get updated with the new 100-period MySMA until I press "F5" or click on the "Reload NinjaScript" context menu item.

                              Sledge, or anybody, do you have any ideas about how to cause "Reload NinjaScript" to occur programmatically? You should be able to reproduce the problem using the indicator code I uploaded.


                              Gold medal for sledge!

                              Thank you so much!

                              Equity Trader

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gentlebenthebear, Today, 01:30 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by Kaledus, Today, 01:29 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              56 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Working...
                              X