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

Access Instrument Lists from Indicator Code

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

    Access Instrument Lists from Indicator Code

    I want to calculate some correlations between all of the futures in a custom instrument list I created.


    I've created an indicator to do this. I need to AddDataSeries for all of the instruments in my list so the data is accessible.


    But I'd like to do this without having to hard code all of the instrument names.


    Is there a way to access the instrument names from an existing instrument list?


    Thanks

    #2
    Hello BarzTrading,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    It is possible through unsupported code to add an entire instrument list through the code. However, the only implementation that I know of would break the warning we provide in the Help Guide linked and listed below.

    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 in 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.
    - AddDataSeries: https://ninjatrader.com/support/help...dataseries.htm

    Please let me know if you have any questions.

    Comment


      #3
      Well, I'm not looking to sell this indicator and it's only for an analysis study so I don't care if it suddenly breaks at some point in the future.

      Would you be willing to message me the unsupported code. I certainly understand not wanting to post it here.

      Also, while I'm a C# developer I'm new to Ninja Trader. As I mentioned I'm just trying to do an analysis. This is not an indicator per se. I just need to analyze several data series in code.

      From what I can tell an indicator is really the only framework to use for this. Is there some other kind of framework that doesn't have to support a chart or existing data series? In other words, a way to call a certain method to begin the analysis and maybe print some output?

      I can do this in an indicator, but it's not what the indicator is designed for. Is an AddOn the way to go here?

      Thanks.
      Last edited by BarzTrading; 08-10-2018, 11:28 AM.

      Comment


        #4
        Hello BarzTrading,

        Thank you for your response.

        An Add On may be the best approach, but this depends on the end goal. Can you describe the reason for needing the Instrument List? What will this be used for in practice?

        I look forward to your response.

        Comment


          #5
          Hi Patrick,

          I want to create a correlation matrix. It's a 2D array (like a grid in excel) that compares the correlation of the price history between one instrument in a list and every other instrument in the list.

          I've done this in another platform by adding all of the data series to a chart, then waiting until the last bar in the Indicator and calculating all of the correlations and writing them out to a csv file. Then I can import into excel for viewing.

          But that's a pain.

          * adding ten, twenty and more instruments to a chart is time consuming so I'd like to automate it somehow.
          * I'd also like to be able to easily apply the calculations to different sets of instruments. One easy way to do that would be to create instrument lists and just type the new list name and run the indicator. (When I say instrument list I'm referring specifically to Tools->Instrument Lists in NinjaTrader.)
          * Third, maybe someday in the future (but not now) I'd like to make it more streamlined so that I could draw the grid in a control or something without having to write to a file and open in excel.

          This is a calculation I might run every few weeks just to see the state of things.

          Thanks.
          Last edited by BarzTrading; 08-10-2018, 12:49 PM.

          Comment


            #6
            Hello BarzTrading,

            Thank you for your response.

            The unsupported code below is intended for use in an indicator only. Using this code in a strategy is highly likely to cause issues in Optimization functions in the Strategy Analyzer per our Help Guide warnings for AddDataSeries().
            Code:
            else if (State == State.Configure)
            {
                Collection<NinjaTrader.Cbi.InstrumentList> list1 = NinjaTrader.Cbi.InstrumentList.All;
                 
                foreach (InstrumentList l in list1)
                {
                    Print(l.Name);
                    if (l.Name == "Futures")
                    {
                        Collection<Instrument> list2 = l.Instruments;
                         
                        foreach (Instrument i in list2)
                        {
                            Print(i.FullName);
                            AddDataSeries(i.FullName);
                        }
                    }
                }
            }
            Please let me know if you have any questions.

            Comment


              #7
              Thanks, Patrick. Works perfectly!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Johnny Santiago, 10-11-2019, 09:21 AM
              95 responses
              6,193 views
              0 likes
              Last Post xiinteractive  
              Started by Irukandji, Today, 09:34 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by RubenCazorla, Today, 09:07 AM
              1 response
              5 views
              0 likes
              Last Post RubenCazorla  
              Started by TraderBCL, Today, 04:38 AM
              3 responses
              25 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X