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

testing strategies on different baskets of stocks/futures each day

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

    testing strategies on different baskets of stocks/futures each day

    Hi,

    I trade a different list of stocks each day. I'm trying to work out a good way to backtest and am hoping there's a good way that people have thought out for this.

    Manually running the strategy on each instrument for each day and looking at the result, chart, then tabulating is not practical. Each time I make one small change to try and optimise the strategy I would need to re-run. Considering just 2 months of testing for 4 stocks a day would mean I would need to run around 240 separate runs then tabulate.

    I'm hoping there is an easier way than the following.

    The only idea I've come up with is the following:
    - create a single strategy that loops through a number of instruments for each bar (say 1minute) each day
    - for each day, the strategy would need to load the instruments from file (say at 9:29 am each morning) just before the open
    - create a file that the strategy loads on startup. It parses the entire file and loads the instruments for that particular date (for example there may be 2 or 3 stocks on a certain date).
    - every bar / tick update etc, would need to cycle through each instrument and check for entry/exit conditions.

    A few questions:
    1) is there another better way to do the above?
    2) can you load instruments (Add data series) dynamically as the strategy runs? I've only ever done this at initialise time

    #2
    Hello PolarBear,
    Thanks for your post.
    1) is there another better way to do the above?
    The easiest way to accomplish this would likely be to create an instrument list for each unique set of instruments that you would like to test. Then in the Strategy Analyzers "Instrument" dropdown menu you can select the instrument list and then "Select All" from the top of the list to "Basket Test" those instruments.

    Basket Testing
    https://ninjatrader.com/support/help...asket_test.htm

    2) can you load instruments (Add data series) dynamically as the strategy runs? I've only ever done this at initialise time
    AddDataSeries() must be called from within OnStateChange() during State.Configure, so attempting to add a data series dynamically is not guaranteed and therefore should be avoided.

    AddDataSeries()
    https://ninjatrader.com/support/help...dataseries.htm

    Please let me know if you have any further questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply, although your responses unfortunately are not very helpful. I'm looking for some lateral thinking here people. NT is very powerful so there must be a way to do this.

      Creating a list of instruments will not work as far as I understand as all the instruments will run over the same time frame. this will run all the instruments for every day of the test. As per my email there is different symbols each day, so if you run how you explained then you'll get invalid results summary as every instrument will trade every day.

      Adding instruments dynamically is problematic therefore as you've said.

      Solution:
      The only way I can think of now then is to add all the instruments to an instrument list for the strategy analyser. I could then load config from a file that loads instruments and dates to trade. With a comparison I can test if the instrument is to trade on that particular day or not.

      Any other suggestions please let me know.

      Comment


        #4
        Originally posted by PolarBear View Post
        Thanks for the reply, although your responses unfortunately are not very helpful. I'm looking for some lateral thinking here people. NT is very powerful so there must be a way to do this.

        Creating a list of instruments will not work as far as I understand as all the instruments will run over the same time frame. this will run all the instruments for every day of the test. As per my email there is different symbols each day, so if you run how you explained then you'll get invalid results summary as every instrument will trade every day.

        Adding instruments dynamically is problematic therefore as you've said.

        Solution:
        The only way I can think of now then is to add all the instruments to an instrument list for the strategy analyser. I could then load config from a file that loads instruments and dates to trade. With a comparison I can test if the instrument is to trade on that particular day or not.

        Any other suggestions please let me know.
        It seems you're trading based on something happening before 930 am open. Can't you replicate whatever that is within NT8? Because if you can, then you can just insert that within the logic and make your trades on list of securities in nt8, and the ones that give you the trigger will trigger on the days it triggers.

        If you can't replicate it, perhaps, if you have a way to compile the historical data for whatever that trigger is, you could create an indicator and load it into nt8 permanently, but this way, you'd have to create that indicator for each stock, which would be a pain in the bet.

        the idea you have yourself is actually really good, if you can figure out to communicate nt8 with start and end dates for your individual stocks.

        good luck

        Comment


          #5
          Originally posted by calhawk01 View Post
          It seems you're trading based on something happening before 930 am open. Can't you replicate whatever that is within NT8? Because if you can, then you can just insert that within the logic and make your trades on list of securities in nt8, and the ones that give you the trigger will trigger on the days it triggers.

          If you can't replicate it, perhaps, if you have a way to compile the historical data for whatever that trigger is, you could create an indicator and load it into nt8 permanently, but this way, you'd have to create that indicator for each stock, which would be a pain in the bet.

          the idea you have yourself is actually really good, if you can figure out to communicate nt8 with start and end dates for your individual stocks.

          good luck
          Thanks for the reply. You are correct I am looking at overnight action (gaps etc) however ninja has no way of scanning the whole market so I use a specialist stock scanner then will have to load in at day 9:25am. If you know a good way of scanning stocks in the main exchanges then I’d be interested to know

          Thanks for the compliment - I was pretty proud of that thought actually

          Comment


            #6
            Originally posted by PolarBear View Post
            Thanks for the reply. You are correct I am looking at overnight action (gaps etc) however ninja has no way of scanning the whole market so I use a specialist stock scanner then will have to load in at day 9:25am. If you know a good way of scanning stocks in the main exchanges then I’d be interested to know

            Thanks for the compliment - I was pretty proud of that thought actually
            I don’t trade stocks but I’m pretty sure your data provider should be starting to provide bid/ask/last at 8:30 am. Do you see quotes changing at 925 in nt8? If not, I’m not sure if there is a way to receive bid/ask/last information in stocks at 9:25 am. However, if you are getting active quotes,, why not just do this:

            If time is 9:25 am
            && closs(0) / precious day close -1 > 0
            {enter long}

            You can also add additional variables like historical daily volume etc so it excludes illiquid stocks.

            Above would compare price at 925 with previous day close (you’d have to enable 24/7 trading template so you’re getting the quotes), then if it’s greater than zero, it will enter long. You can even set a variable for “0” to see how large of a gap is the best long term.

            Then, you can run this strategy on the entire list, for example sp500 stocks, in strategy analyzer. You should be getting trades for all symbols for that list and for the conditions above.

            Comment


              #7
              The issue is the list / number of stocks. My other scanning software is monitoring all stocks from nasdaq, Amex, nyse so 10,000+ stocks. My data provider won’t allow that many simultaneous connections and unsure anyway how a script would go monitoring that many.
              End result is the list needs to be culled down each morning and what you wrote is correct.

              Thanks for the reply

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              3 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Working...
              X