Announcement

Collapse
No announcement yet.

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 timmbbo, Yesterday, 10:27 PM
          1 response
          7 views
          0 likes
          Last Post tgn55
          by tgn55
           
          Started by zacharydw00, Yesterday, 11:13 PM
          0 responses
          2 views
          0 likes
          Last Post zacharydw00  
          Started by luxurious_04, Yesterday, 10:55 PM
          0 responses
          1 view
          0 likes
          Last Post luxurious_04  
          Started by 7robert, Yesterday, 07:48 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by saltminer, Yesterday, 06:32 PM
          0 responses
          6 views
          0 likes
          Last Post saltminer  
          Working...
          X