Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to pass Instrument from Strategy to a hosted Indicator?

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

    Is it possible to pass Instrument from Strategy to a hosted Indicator?

    NT Team,

    Is it possible (advisable) to pass Instrument from a Strategy to a hosted Indicator?

    The question arises where :
    - a Strategy hosts an Indicator,
    - the Indicator must AddDataSeries in State.Configure, and
    - the Series to add is dependant on the Instrument of the Strategy.

    In the forum post (Instrument name for indicator of State.Configure ), it was "recommend to add or call any data based on the Instrument from within the calling strategy or indicator". I believe, an example is included in forum post (Help - Multi-market trading hours indicator ), where String StratExchange is passed to the hosted Indicator.

    So, where in addition to Instrument.Exchange, I require Instrument.FullName and Instrument.MasterInstrument.InstrumentType, is it possible (advisable) to pass Instrument from the Strategy to a hosted Indicator as a single Instrument argument? Or, am I best to add two string arguments, FullName and InstrumentType?

    Thanks
    Shannon

    #2
    Hello Shannon,

    It is possible to pass an instrument in this way (either by using a string input, Instrument object input, or by just referencing the primary instrument in the hosted script, but it is not supported by NinjaTrader support to do so.

    From the help guide:
    "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result into an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."


    The reason is, this will break when attempting to optimize as the optimizer loads all data before running the backtests. If the data is attempted to be loaded dynamically as the script is run, it won't be available when the time comes to perform the backtest.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      Thank you for your complete response.

      I accept any indicator using this approach will not be consumable by the optimizer. The Indicator will not be consumable by the optimiser whether a string input or Instrument object input is used. By passing the Instrument object, I am attempting to write the best code I can and avoid passing three string inputs.

      Unfortunately, the below the below code block results in the below error messages:
      Code:
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
          public Indicators.TrendOC TrendOC(Instrument stratInstrument, string isCalledFrom, int period)
          {
            return indicator.TrendOC(Input, stratInstrument, isCalledFrom, period);
          }
      
          public Indicators.TrendOC TrendOC(ISeries<double> input , Instrument stratInstrument, string isCalledFrom, int period)
          {
            return indicator.TrendOC(input, stratInstrument, isCalledFrom, period);
          }
        }
      }
      • The best overloaded method match for 'NinjaTrader.NinjaScript.Indicators.Indicator.Tren dOC(NinjaTrader.NinjaScript.ISeries<double>, NinjaTrader.Cbi.Instrument, string, int)' has some invalid arguments
      • Argument 2: cannot convert from 'NinjaTrader.NinjaScript.MarketAnalyzerColumns.Ins trument' to 'NinjaTrader.Cbi.Instrument'


      While I believe these errors could be avoided by passing three strings (exchange, FullName, & InstrumentType), I do not believe this is the best solution.

      Please provide guidance on how to remedy this error.

      Again, thanks
      Shannon

      Comment


        #4
        Hello,

        Thank you for the reply.

        In general, this error may be caused if you are not using the fully qualified name on a public property. The error lists you are trying to use One object but the code generated is another object:

        Argument 2: cannot convert from 'NinjaTrader.NinjaScript.MarketAnalyzerColumns.Ins trument' to 'NinjaTrader.Cbi.Instrument'
        Potentially try using NinjaTrader.Cbi.Instrument instead of just Instrument in your code. I am not certain if what you are trying will work but you are free to try it out.

        As configuring dynamic series is not supported, I will add you to the feature request we have for adding series in a dynamic way.

        Please let me know if I may be of further assistance.

        Comment


          #5
          To close this issue out. I've opted to implement passing a String and not an Indicator.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          668 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X