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

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 rocketman7, Today, 09:41 AM
      2 responses
      4 views
      0 likes
      Last Post rocketman7  
      Started by traderqz, Today, 09:44 AM
      1 response
      2 views
      0 likes
      Last Post traderqz  
      Started by rocketman7, Today, 02:12 AM
      7 responses
      31 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by guillembm, Yesterday, 11:25 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by junkone, 04-21-2024, 07:17 AM
      10 responses
      149 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X