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

OnBarUpdate is not fired in Multi Instrument Backtest.

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

    OnBarUpdate is not fired in Multi Instrument Backtest.

    This is very weird. I am currently backtesting for a calendar spread for Crude Oil (CL), but OnBarUpdate() is not running at all.

    Here are my settings:
    1. I am backtesting on CL ##-##, DoNotMerge
    2. Test period 1/1/2013 - 3/12/2015
    3. Test on Daily bar chart

    In my Initialize(), I added these instruments:
    Code:
    			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);

    The expected behavior is, OnBarUpdate will run 10 times for each daily bar, but a simple test using Print("Hello world") shows that it is not happening at all.

    If I change the added instrument to:
    Code:
    			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);
    Then Print("Hello world") in OnBarUpdate() can be executed.

    Is this a bug? Or a design?

    #2
    Originally posted by vhanded View Post
    This is very weird. I am currently backtesting for a calendar spread for Crude Oil (CL), but OnBarUpdate() is not running at all.

    Here are my settings:
    1. I am backtesting on CL ##-##, DoNotMerge
    2. Test period 1/1/2013 - 3/12/2015
    3. Test on Daily bar chart

    In my Initialize(), I added these instruments:
    Code:
    			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);

    The expected behavior is, OnBarUpdate will run 10 times for each daily bar, but a simple test using Print("Hello world") shows that it is not happening at all.

    If I change the added instrument to:
    Code:
    			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
    			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
    //			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);
    Then Print("Hello world") in OnBarUpdate() can be executed.

    Is this a bug? Or a design?

    If you want print it 10 times do it like this

    if(BarsInProgress ==0)
    {
    Print(“Hello world”);
    }

    then copy and paste that in the next line then change ==0 to ==1 until how many time frames you added in the initialize section. Also please note that the current CL contract is still 05-15 so there is no data for 06-15 until 09-15.
    Last edited by luxurious_04; 03-14-2015, 08:16 PM.

    Comment


      #3
      Hello vhanded,

      luxurious_04 is correct. However, can you provide the code used in OnBarUpdate() for your Print()?

      The Merge Policy has no effect on the Continuous Contract, but will effect the added contracts. Do you receive data for the Continuous Contract? Please check under Tools > Historical Data Manager > Edit for data for the Continuous Contract.

      Comment


        #4
        Hi Patrick,

        My OnBarUpdate() has only 1 line of code, which is Print("Hello World"). It was not printing with the above settings in Initialize().

        However, I test it with Kinetick Free end of day data, and it works, while switch back to Continuum trial, it is not. Seems like there is some problem with the feed from Continuum.

        Comment


          #5
          Hello vhanded,

          Check your Log tab on the Control Center. Do you see any messages regarding the CL when connected to NinjaTrader Continuum?

          Comment


            #6
            Hi Patrick,

            There is nothing related in the Log.

            I also tested for Kinetick, and also IQFeed, all are having the same behavior. Hereby I post my code that unable to run OnBarUpdate.

            Please use this setting:
            From 1/1/2010
            Till 3/19/2015


            Data Series Type: Day

            You will notice "hello world" is not print out in Output window.

            EDIT:
            I modified the Test.cs, so it don't print "CL XX-XX added", for less confusion.
            Attached Files
            Last edited by vhanded; 03-20-2015, 04:01 AM.

            Comment


              #7
              Hello vhanded,

              Commenting out the for loops works, of course. I would ask if you cannot just add the needed CL contracts as separate lines rather than looping?

              Comment


                #8
                Hi Patrick,

                I followed your suggestion to remove all loops, and replaced with this long list:
                Code:
                Add("CL 03-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-10", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-10", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			Add("CL 01-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 03-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-11", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-11", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			Add("CL 01-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 03-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-12", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-12", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			Add("CL 01-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 03-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-13", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-13", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			
                			Add("CL 01-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 03-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-14", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-14", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			Add("CL 01-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 03-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 04-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 05-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 06-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 07-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 08-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 09-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 10-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 11-15", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 12-15", BarsPeriod.Id, BarsPeriod.Value);
                			
                			
                			Add("CL 01-16", BarsPeriod.Id, BarsPeriod.Value);
                			Add("CL 02-16", BarsPeriod.Id, BarsPeriod.Value);
                But Hello World is still not printing. Only when I removed CL 01-16 & 02-16, then 'Hello World' is printing.

                So in your case, when add by loop, it is not working, but when add line by line, it works? This is so so so weird.

                Comment


                  #9
                  Hello vhanded,

                  Thank you for your response.

                  In general it is not recommended to use BarsPeriod in the Initialize() method as the bars for the main object may not have loaded yet.
                  Try setting these with PeriodType instead and check again.

                  Comment


                    #10
                    Changed as you requested, still no Hello World is printed out.

                    Code:
                    Add("CL 03-10", PeriodType.Day, 1);
                    			Add("CL 04-10", PeriodType.Day, 1);
                    			Add("CL 05-10", PeriodType.Day, 1);
                    			Add("CL 06-10", PeriodType.Day, 1);
                    			Add("CL 07-10", PeriodType.Day, 1);
                    			Add("CL 08-10", PeriodType.Day, 1);
                    			Add("CL 09-10", PeriodType.Day, 1);
                    			Add("CL 10-10", PeriodType.Day, 1);
                    			Add("CL 11-10", PeriodType.Day, 1);
                    			Add("CL 12-10", PeriodType.Day, 1);
                    			
                    			
                    			Add("CL 01-11", PeriodType.Day, 1);
                    			Add("CL 02-11", PeriodType.Day, 1);
                    			Add("CL 03-11", PeriodType.Day, 1);
                    			Add("CL 04-11", PeriodType.Day, 1);
                    			Add("CL 05-11", PeriodType.Day, 1);
                    			Add("CL 06-11", PeriodType.Day, 1);
                    			Add("CL 07-11", PeriodType.Day, 1);
                    			Add("CL 08-11", PeriodType.Day, 1);
                    			Add("CL 09-11", PeriodType.Day, 1);
                    			Add("CL 10-11", PeriodType.Day, 1);
                    			Add("CL 11-11", PeriodType.Day, 1);
                    			Add("CL 12-11", PeriodType.Day, 1);
                    			
                    			
                    			Add("CL 01-12", PeriodType.Day, 1);
                    			Add("CL 02-12", PeriodType.Day, 1);
                    			Add("CL 03-12", PeriodType.Day, 1);
                    			Add("CL 04-12", PeriodType.Day, 1);
                    			Add("CL 05-12", PeriodType.Day, 1);
                    			Add("CL 06-12", PeriodType.Day, 1);
                    			Add("CL 07-12", PeriodType.Day, 1);
                    			Add("CL 08-12", PeriodType.Day, 1);
                    			Add("CL 09-12", PeriodType.Day, 1);
                    			Add("CL 10-12", PeriodType.Day, 1);
                    			Add("CL 11-12", PeriodType.Day, 1);
                    			Add("CL 12-12", PeriodType.Day, 1);
                    			
                    			
                    			Add("CL 01-13", PeriodType.Day, 1);
                    			Add("CL 02-13", PeriodType.Day, 1);
                    			Add("CL 03-13", PeriodType.Day, 1);
                    			Add("CL 04-13", PeriodType.Day, 1);
                    			Add("CL 05-13", PeriodType.Day, 1);
                    			Add("CL 06-13", PeriodType.Day, 1);
                    			Add("CL 07-13", PeriodType.Day, 1);
                    			Add("CL 08-13", PeriodType.Day, 1);
                    			Add("CL 09-13", PeriodType.Day, 1);
                    			Add("CL 10-13", PeriodType.Day, 1);
                    			Add("CL 11-13", PeriodType.Day, 1);
                    			Add("CL 12-13", PeriodType.Day, 1);
                    			
                    			
                    			
                    			Add("CL 01-14", PeriodType.Day, 1);
                    			Add("CL 02-14", PeriodType.Day, 1);
                    			Add("CL 03-14", PeriodType.Day, 1);
                    			Add("CL 04-14", PeriodType.Day, 1);
                    			Add("CL 05-14", PeriodType.Day, 1);
                    			Add("CL 06-14", PeriodType.Day, 1);
                    			Add("CL 07-14", PeriodType.Day, 1);
                    			Add("CL 08-14", PeriodType.Day, 1);
                    			Add("CL 09-14", PeriodType.Day, 1);
                    			Add("CL 10-14", PeriodType.Day, 1);
                    			Add("CL 11-14", PeriodType.Day, 1);
                    			Add("CL 12-14", PeriodType.Day, 1);
                    			
                    			
                    			Add("CL 01-15", PeriodType.Day, 1);
                    			Add("CL 02-15", PeriodType.Day, 1);
                    			Add("CL 03-15", PeriodType.Day, 1);
                    			Add("CL 04-15", PeriodType.Day, 1);
                    			Add("CL 05-15", PeriodType.Day, 1);
                    			Add("CL 06-15", PeriodType.Day, 1);
                    			Add("CL 07-15", PeriodType.Day, 1);
                    			Add("CL 08-15", PeriodType.Day, 1);
                    			Add("CL 09-15", PeriodType.Day, 1);
                    			Add("CL 10-15", PeriodType.Day, 1);
                    			Add("CL 11-15", PeriodType.Day, 1);
                    			Add("CL 12-15", PeriodType.Day, 1);
                    			
                    			
                    			Add("CL 01-16", PeriodType.Day, 1);
                    			Add("CL 02-16", PeriodType.Day, 1);
                    I also removed db/day, db/minute, db/ticks and db/data folders to let iqfeed to redownload the data, but still no luck.

                    First, can you reproduce the issue?

                    Comment


                      #11
                      Hello vhanded,

                      Thank you for your response.

                      Yes, I am seeing the exact same behavior regardless if we use the loops or list each Add() alone.

                      Do you still see the same issue when removing other contracts? Or is it only when you remove 01-15 and 02-15?

                      Comment


                        #12
                        You mean 01-16 and 02-16? Yes, removing CL 01-16 and CL 02-16 will start printing "Hello World"

                        What I learned is, if I only add contract of CL 01-10 into period of 1/1/2010 and 3/19/2015, "Hello World" will not be printed, because CL 01-10 already expired before the beginning of test, thus no bar will be added, and NT decided not to run it.

                        However, CL 01-16 is already start trading by that period, so it should have bars to show.

                        Hope this provide you some clue.

                        Comment


                          #13
                          Hello vhanded,

                          Any call to a contract that there is no data for will cause this behavior. Please remove or comment out any future contracts that the data feed provider would not have data for.

                          Comment


                            #14
                            Hi, this does not make sense at all.

                            For the same testing period (1/1/2010 - 19/3/2015), if I remove all the contracts, and ONLY add CL 01-16 and CL 02-16, "Hello World" is printed.

                            Moreover, CL 01-16 and Cl 02-16 are having data in that period. I can see bars when I add CL 01-16 and CL 02-16 to File->New->Chart.

                            Comment


                              #15
                              Hello vhanded,

                              Thank you for your response.

                              What contract would the Continuous be plotting as it's current close though? Would this be contracts for next year?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by yertle, 04-18-2024, 08:38 AM
                              9 responses
                              40 views
                              0 likes
                              Last Post yertle
                              by yertle
                               
                              Started by techgetgame, Yesterday, 11:42 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post techgetgame  
                              Started by sephichapdson, Yesterday, 11:36 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post sephichapdson  
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,615 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Yesterday, 05:56 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post jaybedreamin  
                              Working...
                              X