Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error in Strategy Builder when an indicator uses an Instrument Selector

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

    Error in Strategy Builder when an indicator uses an Instrument Selector

    I'm writing an indicator that has an Instrument as input parameter, based on examples provided in various threads of this forum.

    Code:
    [NinjaScriptProperty]
    [XmlIgnore()]
    [TypeConverter(typeof(NinjaTrader.Gui.Tools.InstrumentSelector))]
    [Display(Name = "Instrument2", GroupName = "Parameters", Order = 1, Description = "Other instrument")]
    public NinjaTrader.Cbi.Instrument Instrument2
    {
    get; set;
    }
    ​
    It's working fine when the indicator is added directly to a Chart.

    Then I'd also like it to be supported by the Strategy Builder, but it fails: an error popup appears as soon as I click on the indicator in the list proposed by the strategy builder, complaining about a null object:
    Unhandled exception: Object reference not set to an instance of an object.
    A reduced example showing the behaviour is attached: open the strategy builder, in "Conditions and Actions" add a condition then select Indicator named "An Error related to InstrumentSelector when used in Strategy Builder !!!".
    (In the attached example, the Instrument serialization code has been removed as it does not seem related to the issue).

    Attaching Visual Studio debugger does not help to find the origin of the error, as it usually does when a null object is in my source code, which makes me think it might be in the platform code.

    Please tell me if I'm doing something the wrong way, or if additional code is required to support this kind of indicator in the strategy builder.

    By the way, I'm aware that Instrument input is not intended to be used in AddDataSeries... and that's exactly what I use it for... As far as I've been testing, it seems to be working fine, but as it's not officially supported, please add my vote to the already existing feature request (SFT-882 mentioned in other threads).
    Attached Files

    #2
    Hello naranja,

    If the purpose is for using it with AddDataSeries there is nothing I can suggest, that goes against how the AddDataSeries method is intended to work and can end up failing to load data. If you are trying to assume the instrument from the strategy you can use null as the instrument name instead of a string, that will pick up the primary instrument.

    Comment


      #3
      Hello Jesse,

      Thanks for your answer.
      Actually the issue I'm facing is not about AddDataSeries, the attached example does not call AddDataSeries and the bug is present nonetheless.
      It happens during the editing of the strategy, when the Strategy Builder tries to display the parameters of the strategy.

      If you could please test the attached sample, you will reproduce the error:
      - import the attached sample
      - open the strategy builder
      - in "Conditions and Actions" add a condition
      - select the Indicator named "An Error related to InstrumentSelector ..."
      => the parameters are not displayed and the error pops up.

      Comment


        #4
        Hello naranja,

        The strategy builder has to use the indicator in code which works differently than using it in the chart where you have a property grid to select the instrument. The builder has no ability to use an instrument type as a user input so that use case would not be supported. To manually select an instrument you would need to first find an instrument and set a default to avoid the object reference not set error. To use this indicator with a strategy provided input it would need to be manually coded so a valid Instrument object can be found and passed as the input when the indicator is created.
        Last edited by NinjaTrader_Jesse; 06-03-2024, 11:01 AM.

        Comment


          #5
          Thanks for this insightful answer, I understand that my first intention was not relevant in the context of the strategy builder.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          563 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          329 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X