Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order of Code Execution when Testing Multiple Instruments?

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

    Order of Code Execution when Testing Multiple Instruments?

    Hi,

    I'm backtesting a strategy on multiple instruments, say ES and NQ.

    In the first line of OnBarUpdate(), I'm printing

    Code:
    string instrumentName = Instrument.FullName;
    Print($"{instrumentName} | {Time[0]} | Close[0] {Close[0]}");
    What puzzles me is that the output only every prints ES 12-24 and no NQ.

    Why is this?

    Many thanks for your help!

    Click image for larger version

Name:	image.png
Views:	64
Size:	137.1 KB
ID:	1323039

    #2
    Hello yannickwe,

    Have you used AddDataSeries in the code and also re applied the script after making that change? If you added that and did not re apply the script it will not observe the change until you do.

    Comment


      #3
      Oh, sorry, I think we're misunderstanding each other!

      I haven't nor want to add a secondary data series. My system runs on one single data series, but I'm basket testing (https://ninjatrader.com/support/help...asket_test.htm) it across two instruments (ES and NQ).

      Yet, I'm only getting prints for ES.

      Comment


        #4
        Hello yannickwe,

        Are you using a basket test? The script will only print for a single instrument if you are only using the primary.

        Comment


          #5
          Yes, I'm using a basket test. In fact, in the previous post I wrote:

          My system runs on one single data series, but I'm basket testing (https://ninjatrader.com/support/help...asket_test.htm) it across two instruments (ES and NQ).
          So prints should appear for both instruments, right?

          Comment


            #6
            Hello yannickwe,

            When using a basket test you will see prints for each instrument, did you select a specific contract with the NQ? Have you opened a chart and confirmed you have historical data for that instrument? ​

            Comment


              #7
              I'm selecting an instrument list in Strategy Analyzer. Like this:

              Click image for larger version

Name:	image.png
Views:	61
Size:	27.9 KB
ID:	1323141

              And in the code, I have:

              Click image for larger version

Name:	image.png
Views:	45
Size:	13.4 KB
ID:	1323142​

              Yet, the backtest only prints this (even when I scroll up or down, there are no NQ 12-24 prints in this output):

              Click image for larger version

Name:	image.png
Views:	53
Size:	137.1 KB
ID:	1323143​

              Comment


                #8
                Hello yannickwe,

                Do you have ClearOutputWindow() anywhere in the script? I tried your print in a new empty strategy and this is what I get from the default futures list:

                F
                DAX 09-24 | 4/24/2024 9:37:00 AM | Close[0] 18470
                ZW 09-24 | 5/9/2024 9:13:00 AM | Close[0] 658.5
                ZS 11-24 | 3/19/2024 11:52:00 PM | Close[0] 1162.25
                GC 08-24 | 3/6/2024 4:33:00 PM | Close[0] 2199.7
                ZW 09-24 | 5/9/2024 9:14:00 AM | Close[0] 658.25
                ZS 11-24 | 3/19/2024 11:53:00 PM | Close[0] 1162
                ZW 09-24 | 5/9/2024 9:15:00 AM | Close[0] 658.25
                ZS 11-24 | 3/19/2024 11:54:00 PM | Close[0] 1162
                GC 08-24 | 3/6/2024 4:34:00 PM | Close[0] 2199.7
                FDAX 09-24 | 4/24/2024 9:38:00 AM | Close[0] 18473
                ZW 09-24 | 5/9/2024 9:16:00 AM | Close[0] 659
                FDAX 09-24 | 4/24/2024 9:39:00 AM | Close[0] 18473
                ZS 11-24 | 3/19/2024 11:55:00 PM | Close[0] 1162.25
                ZW 09-24 | 5/9/2024 9:17:00 AM | Close[0] 659.75
                GC 08-24 | 3/6/2024 4:35:00 PM | Close[0] 2199.1
                FDAX 09-24 | 4/24/2024 9:40:00 AM | Close[0] 18472
                ZS 11-24 | 3/19/2024 11:56:00 PM | Close[0] 1162.5
                ZW 09-24 | 5/9/2024 9:18:00 AM | Close[0] 659.25
                GC 08-24 | 3/6/2024 4:36:00 PM | Close[0] 2199.5
                FDAX 09-24 | 4/24/2024 9:41:00 AM | Close[0] 18468
                GC 08-24 | 3/6/2024 4:37:00 PM | Close[0] 2199.4
                FDAX 09-24 | 4/24/2024 9:42:00 AM | Close[0] 18467
                GC 08-24 | 3/6/2024 4:38:00 PM | Close[0] 2199.2
                ZW 09-24 | 5/9/2024 9:19:00 AM | Close[0] 659.5
                GC 08-24 | 3/6/2024 4:39:00 PM | Close[0] 2199.3​
                Additionally you will see 1 instrument only initially until later in the test when more instances are started. If no concurrency happens you would see one instrument fully process after another in the prints.

                Comment


                  #9
                  Hi Jesse,

                  you hit the nail on the head: I did use ClearOutputWindow(). And without it both instruments are being printed. Thanks!

                  One question about concurrency. Is there a way to make the strategy not use it?

                  Regards!

                  Comment


                    #10
                    Hello yannickwe,

                    No that would be part of how the platform works, there is no way to change that from NinjaScript.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    19 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    119 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    63 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    41 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    45 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X