Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiinstrument startegy - no show of instruments after backtest

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

    Multiinstrument startegy - no show of instruments after backtest

    Hello Ninjas

    I'm trying to back-test simple multinstrument strategy. I do this because I was advised this is the only way to have a table of back-test trades in one place - handy for export. Please find the attached code.

    Problem: Back-test results are blank if I add more than one instrument. For example the attached code returns no back-test results. However, if I delete 2 out of 3 instruments, then the back-test results show results for that 1 remaining instrument as if the strategy can work with only a single instrument.

    Please advise

    ionaz
    Attached Files

    #2
    Hello ionaz,

    Thank you for your note.

    I notice there is no use of the barsInProgress index in your strategy, is this intentional?

    Do you receive any error messages in your Log tab of the Control Center after attempting a backtest?

    I look forward to your response.

    Comment


      #3
      Hello Patrick

      Thank you for your help.

      • I didn't receive any error messages on the log tab (pls see picture).
      • I tried adding/removing the below code, hope this is the right one
      Code:
      if (BarsInProgress != 0)
                      return;
      It didn't make much difference I should say. It seems to me that the main reason why I don't get any trades at all is the addition of more instruments in the script, I might be wrong. (Please review attached: the script don't return any trades when I add the the block of "Adds").

      There's one more issue which is kind of the most important to me since my goal is a SINGLE list of ALL trades generated by the back-test. I believe I do not get this list or I get it but incomplete, please review the picture ''backtest results'. What I do is select the Dow30 on the left and run the back-test expecting I'd get the list of trades as per above. So I see 68 total trades under combined results, it's a pity that once I click on this line the window below doesn't show all those 68 trades. It would only show the trades when selecting separate lines.
      • So as far as I can understand the solution to this is adding instruments like I do in the script and go from there, correct?


      • If yes, then please advise what else in the attached code prevents me from having all trades in 1 place.


      • Finally, just for clarity, the list of trades I'm talking about here would contain those instruments I add via the script only or those I select on the left in the back-test window as well? Or both perhaps? It confuses me why do I need to add instruments in the script but I'm OK if this is the only way to get the full list of trades in 1 place.


      I hope not too many questions, I thought it might be good to give you some context. Thanks again and look forward to your message.
      Attached Files

      Comment


        #4
        I gave your strategy a run here on the DOW30, 1 minute series and I'm getting trades.

        I'm happy to answer your questions and get you on the right track however in terms of why you may not get getting trades as per your first post, you should look at the data series you're running on. In order for OnBarUpdate to run, you must have data for all instruments you have added to your script. This means if you are running this strategy on a 1-minute data series, you must be able to download data for all instruments you have in your Add()'s. If any of these instruments do not meet your Minimum Bars Required, the backtest will not run.

        Now, as far as how you're attempting to accomplish your goal, you can use either approach: You can just use a single series script with no Added instruments and run on the list of the DOW30, as outlined on the following link:

        http://www.ninjatrader.com/support/h...asket_test.htm.

        However, if you do not like the way this information is presented, you can consider adding the instruments through Add(). However, this creates a few dependency issues and you'll need to add a series of run time checks such as checking CurrentBars[] and BarsInProgress to ensure that you're only taking action on events that you desire. You sohuld review the concepts mentioned above on the following link to ensure you are adding proper error checking to your strategy:



        However again, if one or more of the instruments you have Added do not meet bars required, the strategy will not work and no trades will be made.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Many thanks for your guidance, Matthew

          With regards to download data for all instruments I have in my Add()'s - what I do is I've imported the tickers of my interest and can see these tickers as a basket (Same as DOW30). I also connect to Kinetick EOD - is there anything else I need to do to get this data?

          Thank you for summarizing 2 methods for reaching my goal. I'd obviously choose the 1st one for its simplicity. But I can't afford clicking on each line to retrieve the trades. So if there's a workaround to this, perhaps enabling trades data retrieve programatically - it would be great if you'd share any knowledge around that.

          Otherwise, thanks for the links to the checks in case I do method 2 - multiinstruments, using add(). Before I go there, can you please advise if there's any smarter way to retrieve trades data using method 1.

          Comment


            #6
            To clarify, when you connected to Kinetick End of Day, you are using a Daily time frame for the primary series, correct? If you were to try a minute or tick chart, no data would be obtained by this feed. You have to use a Daily interval such as Day, Week, Month, Year.

            If you are using all Daily data, you would need to open a chart for each symbol you want to trade to ensure you have chart data for the periods requested and debug/analyze from there.

            There's no straight forward method to obtain this information as you seek. It's possible to use the TradeCollection to obtain the information, and you could write that information to an external file as you needed to, but this may be more code involved than just using either of the two methods we discussed
            MatthewNinjaTrader Product Management

            Comment


              #7
              Not sure how/where to check if I'm using using Daily time frame for the primary series? So once again, what i do:
              1. in a Backtest menu, under Data series/Type i select 'Day'
              2. Add("MSFT",PeriodType.Day, 1);
              3. connect to kinetick EOD

              • Did I missed anything?


              I read through all the links you've sent and have a few comments/queries.
              So my goal is all trades in 1 place and I'm using the 2nd method.
              • Why I only see trades for 3 instruments? I made use of BarsInProgress as you advised and i've got an improvement - now I see trades for 3 instruments (attached picture). However' I believe my code (attached) allows to show more instruments. What am I missing here?

              However, if you do not like the way this information is presented, you can consider adding the instruments through Add(). However, this creates a few dependency issues and you'll need to add a series of run time checks such as checking CurrentBars[] and BarsInProgress to ensure that you're only taking action on events that you desire. You sohuld review the concepts mentioned above on the following link to ensure you are adding proper error checking to your strategy

              • Also, looking into my simple code (attached), and given I only need all trades for all the instruments added in 1 place, would you say I made good use of BarsInProgress to achieve that?

              • I read through the materials you suggested, so with regards to other run time checks. I wonder what is it CurrentBars[] can help me with now - can it help/is it potentially a reason why I don't see more instruments in the trades list now? (pic attached)?


              If you are using all Daily data, you would need to open a chart for each symbol you want to trade to ensure you have chart data for the periods requested and debug/analyze from there.

              • Do I really need to do this? I believe I don't need to do this, please correct me if I'm wrong, because if you look into the new version of code (attached) and the trades it generates (attached picture) it shows trades for symbols ASBCW, ACST, AFH - none of which I had to open a chart to load the data. It would be really really sad if I had to open say 2000 charts just to run a single back-test - I have roughly 2000 NASDAQ symbols imported on top of default NT installation. Please confirm there's no need for me to open each of 2000 charts if I want to achieve my goal of all trades in 1 place - my goal is to add about 2000 instruments to the code once I clarify these questions.



              There's no straight forward method to obtain this information as you seek. It's possible to use the TradeCollection to obtain the information, and you could write that information to an external file as you needed to, but this may be more code involved than just using either of the two methods we discussed
              Ok, thank you! I leave this for the future then and go with method 2, using add(), I hope it can work for me.

              Attached Files

              Comment


                #8
                Hello ionaz,

                You did not missing anything for the Primary Series.

                As for the data, you do not have to have a chart opened up but you will need to make sure that you have Data for all of the instruments which if it is placing trades it looks like you do have data.

                My guess would be that this is going to be due to the "Entries Per Direction" Handling set inside of the Strategy Parameters.

                Using a Multi-Series approach like this the "Entries Per Direction" handling will be used across all of the instruments meaning that if you have "Entries Per Direction" set to 1 which is the default, you can only be in a Trade 1 at a time so that you can only ever be Long in one instrument of your more than 19 instruments.

                You may want to either increase this, or use the "Instrument.MasterInstrument.Name" as a Order name so that you can set the "EntryHandling" to "UniqueEntries" to get more orders.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Thank you for the explanation of how the "Entries Per Direction" works with Multi-Series strategy. I increased the value and the trades for other symbols came as well as expected.

                  However, there are 2 things I don't understand now.

                  1.
                  I now have doubts whether I really need BarsInProgress at all in the code because, now that the EntriesPerDirection is sorted, I get trades with or without BarsInProgress conditions (this is the 1st condition line under onbarupdate - simplified code attached). So do I really need it? My problem is that I don't really understand what it does for me now that the trades are generated with or without the BarsInProgress conditions.

                  2.
                  Another thing I don't get (barsinprogress line switched off):
                  entries per direction=1 >>> the first trade I see is for CSCO
                  entries per direction=2 >>> the first trade I see is for XOM
                  So I don't see why it jumps to XOM, I think it should still be CSCO, no?
                  To start a backtest I always click on the same instrument in the GUI - instrument 'AA' under DOW30.
                  I've attached the backtest settings so that you could replicate.
                  Attached Files
                  Last edited by ionaz; 05-01-2014, 01:08 AM.

                  Comment


                    #10
                    Hello ionaz,

                    1. The BarsInProgress / CurrentBars check that Matthew was referring I believe is going to be if you are going to be using other instruments for all of your Trading. If you wanting to run the same code on all of your instruments separately you should not need this.

                    2. This is just going to be because the of the Time that the Trades and how NinjaTrader organizes them. If you look at the Executions tab you will see that the "CSCO" was still executed first and "XOM" entered a trade at the same time but "XOM" exited first before "CSCO" which is why you see it at the top of the Trades tab.
                    JCNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

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