Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Loading SP500 in one strategy

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

    Loading SP500 in one strategy

    Hey,

    I have a strategy that load up all the stocks in the SP500 on initialization. I then long or short some of them base on certain criteria.

    When I backtest, say since 2009, I only get 3 months with trades (6,7,8 - 2010). I am guessing this is because there might be some missing data at some point (I tried with DOW30 and works fine).

    What is the best way to deal with this. Is there a way to check if Closes[x] has data or something of the sort?

    Cheers,
    Phil

    #2
    Phil,

    Your strategy logic will not process until every single one of your series have met the BarsRequired requirement.

    To see how many bars are in each bars context you can use CurrentBars[] to see. http://www.ninjatrader.com/support/h...urrentbars.htm
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hey Josh,

      Any way we can have error handling for adding a security to a strategy? Basically, I am iterating through the list of stocks in the SP500 and adding them to my strategy. However, sometimes I get an error downloading data from yahoo. This is most likely caused because a stock might have only started trading in 2009 and I am trying to get data for 2005 or something like this. When this happens, my strategy does not work/run.

      I would like to add some try/catch block but the standard C# one does not seem to catch the error that NT throws. Any way to only add instruments that have data for the date range??

      Thanks in advance

      Comment


        #4
        Also, is it possible to ignore barsRequired? I have set it to 0 but my strategy only starts at the date where data is available for the shortest dataset in my strategy (in my case, one ticker is currently in the SP and it just has data starting 6/2010). My strategy handles different starting dates, but the under the hood NT code prevents my code from working properly.

        If there isn't a way around this, is there a way that I can programmatically check if the instrument has data over the period requested and not add it if not?

        Cheers,
        Phil

        Comment


          #5
          Phil,

          Unfortunately none of these are possible. Believe your best bet would be to try to run your strategy once and get the list of instruments that simply don't have data from the error messages and remove them from the strategy manually. After you have removed them all you should not have these problems anymore.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            And what about data date ranges? Any ways to check this?

            Comment


              #7
              Not possible to check it before adding the series. Adding the series means all data needs to be present before you can check anything off of it.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Ok then. Would it be possible to remove a series? Something that removes data that you added in Add() in the initialize region?

                Thanks

                Comment


                  #9
                  Unfortunately not possible.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok may I suggest something along the lines of ignore bars required if you handle the code yourself? Maybe for a future release?

                    In order to create more "creative" strategies, I would need something like this, and I am sure others would appreciate it as well.

                    Comment


                      #11
                      Thanks. I have added it to our feedback list.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok thanks.

                        While I have you here, quick question.

                        I am trying to programmatically create a new list with all the "good" securities (the ones that have data over the period).

                        How do I add the list? I basically want to create a temp list just for backtesting purposes. Do I have to use AddInstrumentList?

                        Comment


                          #13
                          There is no "adding list" concept. To add a list of instruments you would just have to go through and call Add() on each of the instruments.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Ok what I meant to say is that in order to save the user some time, the strategy will automatically identify the instruments to remove and then it will create a new instrument list without these securities. Then the user will have to re-run the backtest using the new "temp" list the strategy just created - the list name is one of the parameters for my strategy by the way.

                            So I have to find a way to create a list programmatically - a list such as default, or SP500...

                            Comment


                              #15
                              Right. This is what is not possible. You cannot programmatically create instrument lists. Those can only be made through the Instrument Manager.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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