Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to specify an instrument name for custom indicator from a strategy

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

    How to specify an instrument name for custom indicator from a strategy

    Hi!
    I'm using multi-instrument strategy. I'm calling a custom made indicator MyIndicator() from the strategy, but i need to specify the instrument with will be use for the calculations. I tried to do it in the indicator with this code: (this.Instrument.MasterInstrument.Name = "TF 12-15"; ), but I'm sure this is not the right way to do that. May main instrument is (TF 12-15) and the second are ^ADV and ^DECL. When the BarsInProgress == 0 , I call MyIndicatorer(),and it gets the result for he TF 12-15, but when BarsInProgress > 0, i need to do call something like that: MyIndicator("TF 12-15") to force the indicator to make calculation for TF. My question is: is it possible to do that and how.
    Thank you.

    #2
    Hello,
    I would recommend to add the dataseries in Initialize and then call the caluclation of the indicator based of the Close values of the added datasers for the IDataSeries argument of the indicator.
    For example the SMA has the following overload SMA(IDataSeries input, int period)[int barsAgo]
    You could get the SMA to calculate off of the secondary data series by doing the following:
    Code:
    protected override void Initialize()
    {
        Add("TF 03-16" , PeriodType.Minute, 1, MarketDataType.Last);
    }
    protected override void OnBarUpdate()
    {
       SMA(Closes[1], 20)[0];			
    }
    For more information on using multiple time frames and instruments please see the following link: http://ninjatrader.com/support/helpG...nstruments.htm
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Thanks!
      I did not notice that my custom indicator has overload with first parameter IDataSeries Input. I just add the Input DataSeries as a first parameter of MyIndicator(Closes[0], .....), and it works great.
      Thank you for the help.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      41 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X