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

OnInstrumentChanged(object sender, EventArgs e) not working properly

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

    OnInstrumentChanged(object sender, EventArgs e) not working properly

    I am developing Addon and unfortunately can't get NinjaTrader.Gui.Tools.InstrumentSelector EventArgs to work properly for me.

    Currently when I select the grey instrument box in top left corner of chart, make instrument change, EventArgs does work for me. However, when I simply type the instrument symbol inside a chart window which brings up a small change instrument box and hit enter >> EventArgs does not work with this action.

    I will need to either disable the easy instrument change or figure out how to get EventArgs for the easy instrument change.

    Here is my code:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    NinjaTrader.Gui.Tools.InstrumentSelector _cc_Instrument_Selector;
    ...
    _cc_Instrument_Selector = Window.GetWindow( _myChart.ActiveChartControl.Parent).FindFirst("Cha rtWindowInstrumentSelector") as NinjaTrader.Gui.Tools.InstrumentSelector;
    if (_cc_Instrument_Selector != null)
    _cc_Instrument_Selector.InstrumentChanged += _OnInstrumentChanged;
    ...
    private void _OnInstrumentChanged(object sender, EventArgs e)
    {
    var CC_Instrument = _cc_Instrument_Selector.Instrument;
    addon.Print(String.Format("OnInstrumentChanged(2) >>> CC_Instrument = {0}", CC_Instrument));

    MyCustomActions();
    }
    ...
    _cc_Instrument_Selector.InstrumentChanged -= _OnInstrumentChanged;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Really appreciate any help at all on this

    Kind Regards

    #2
    Hello Blairski,

    Thank you for the post.

    Is this being used from an Indicator that is applied to the chart or is this from an Addon :AddOnBase?

    If you have a small .cs file example that shows where this being used from that you can attach that would be helpful in finding a solution.

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

    Comment


      #3
      It is an AddOnBase.

      Is this the expected behaviour from an AddOnBase?

      Unfortunately I do not have small .cs file example. This addon was prepare by consultant awhile ago with over 2000 lines of code. The addon as a whole works however when I add private void _OnInstrumentChanged(object sender, EventArgs e) only the instrument box in the top left corner of chart is working. As in, I have to make instrument change in that instrument box. If the instrument is changed elsewhere and linked into the instrument box in the top left corner of chart - it doesn't work.

      Is there another selection I could make instead of ".InstrumentChanged" which would incorporate quick instrument change box? See attached.

      Maybe I can find the automation ids for this quick instrument change feature in the chart and create another event EventArgs for that? Do you happen to know the automation ids for the instrument change feature I'm talking about?

      Appreciate the help.

      Kind Regards
      Attached Files

      Comment


        #4
        Hello Blairski,

        Thank you for the post.

        It looks like in that case you would need to handle that yourself. I tried getting the popup window and it does appear that it has instrument selected event. You could likely use it in the way that I have shown in the attached script, by the time the event was called in my tests the instrument selector was updated.


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

        Comment


          #5
          Thanks much Jesse.

          This...
          instrumentSelectorPopup = c.FindFirst("ChartWindowInstrumentSelectorPopup") as InstrumentSelectorPopup;
          if (instrumentSelectorPopup != null)
          {
          instrumentSelectorPopup.InstrumentsSelected += InstrumentSelectorPopup_InstrumentsSelected;
          }

          works well. Now if I change the instrument via DropDown or Popup the Addon works as expected.



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          15 responses
          3,270 views
          0 likes
          Last Post xiinteractive  
          Started by Tim-c, Today, 02:10 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          2 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          51 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          10 responses
          403 views
          1 like
          Last Post beobast
          by beobast
           
          Working...
          X