Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem Adding Daily Bars to Minute Strategy

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

    Problem Adding Daily Bars to Minute Strategy

    Hi all,
    I'm trying to add a daily series for strategy using multi-instruments. I'm using a loop to display in the output window the results of the historical data. It does not seem to be working when I ask for daily bars.

    Add ("YM 09-10", PeriodType.Day, 1);

    I use the following code to display the data for me.

    protected override void OnBarUpdate()

    for (int x = 0; x < 21; x++)
    {
    Print("In for Loop " + x);
    Print (Closes[2][x] + " " + Times[2][x]);
    }

    This is the output I get when I try to load and print daily bars

    In for Loop 0
    10141 6/14/2010 12:00:00 AM
    In for Loop 1

    NT seems to freeze here after the last print. Although I don't have to quit NT, I just stop the strategy and everything seems to work OK.

    However, when I change the ADD to minute bars, things seem to work well.
    Add ("YM 09-10", PeriodType.Minute, 1);

    Here's the output:
    In for Loop 0
    10084 6/28/2010 4:51:00 PM
    In for Loop 1
    10090 6/28/2010 4:49:00 PM
    In for Loop 2
    10085 6/28/2010 4:48:00 PM
    In for Loop 3
    10082 6/28/2010 4:47:00 PM
    In for Loop 4
    10082 6/28/2010 4:46:00 PM
    In for Loop 5
    10084 6/28/2010 4:45:00 PM
    In for Loop 6
    10083 6/28/2010 4:44:00 PM
    In for Loop 7
    10079 6/28/2010 4:43:00 PM
    In for Loop 8
    10079 6/28/2010 4:42:00 PM
    In for Loop 9
    10072 6/28/2010 4:41:00 PM
    In for Loop 10
    10072 6/28/2010 4:40:00 PM
    In for Loop 11
    10078 6/28/2010 4:39:00 PM
    In for Loop 12
    10080 6/28/2010 4:38:00 PM
    In for Loop 13
    10080 6/28/2010 4:37:00 PM
    In for Loop 14
    10081 6/28/2010 4:36:00 PM
    In for Loop 15
    10082 6/28/2010 4:35:00 PM
    In for Loop 16
    10081 6/28/2010 4:34:00 PM
    In for Loop 17
    10081 6/28/2010 4:33:00 PM
    In for Loop 18
    10080 6/28/2010 4:32:00 PM
    In for Loop 19
    10081 6/28/2010 4:31:00 PM
    In for Loop 20
    10088 6/28/2010 4:15:00 PM

    A few questions:
    1) Why does daily not work, it seems to load only 1 day pretty far back in the past? I expect to get the most recent close first, then earlier closes.
    2) How can I control which data is loaded historically, i.e. can I load just regular trading hours and not extended? Can I have a data series with both regular and extended trading hours for the same security?
    3) The strategy seems to freeze if I attempt calculations on a bar with no data. How can I check for data before running the calcs?
    4) How can I increase the number of bars loaded?

    Thanks for your help! I am using NT 6.5 on windows 7 64 bit.

    #2
    GiantHogweed, are you adding the daily bars as the 2nd additional instrument? Because the instrument array is zero-indexed (the first instrument has an index of 0), your code here:
    Code:
    for (int x = 0; x < 21; x++)       
    { 
       Print("In for Loop " + x);    
       Print (Closes[2][x] + "     " + Times[2][x]);
    }
    is actually looking to loop through the tertiary (3rd) instrument, even though you specify Closes[2][x].

    If the only Add(...) statement in your strategy is for the daily bars, then replace the 2 with a 1 in your for loop.

    2) You can select the session template you'd like to use. If you put the strategy on a chart, the data series of the chart will determine the session template. If you start the strategy from the tab, you get to pick. Please see the screenshot for the location of the selection.

    3) If your code is running in OnBarUpdate(), then the bar data is guaranteed to be there (meaning Open[0], High[0], Low[0], Close[0], Volume[0], and Time[0] will have values). Could you please be more specific on what you mean by "data"?

    4) If you're loading your strategy from the strategy tab, then take a look at the same screenshot (Days To Load property). If you're loading it from the chart, again, it will be determined by the data series on the chart.
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply Austin. I am running the strategy from the control center and not a window. Some replies to your replies!
      1) I have 2 instruments loaded in 0 and 1, so the daily bars are index #2

      2) See the attached screen print, these are the options I have. I've been trying 30 bars but it doesn't seem to grab more than 20 or 21 using the ADD command. Also, I am curious how I could get index 2 to be daily closes using regular trading hours and index 3 to be daily closed using extended trading hours. Is this supported using the control center to run the strategy?

      3) Here by data I mean [IMG]file:///C:/Users/Mike/AppData/Local/Temp/moz-screenshot.png[/IMG]having values in the historical bars that I attempted to load using the ADD command. If the ADD command doesn't work as expected, I get here to bar update, try to run calcs on the historical data and get errors if there's no data from the ADD command.

      4) Similar to #2, if I use this menu setting, does it apply to just the instrument listed in the menu, index 0? How can I affect the amount of bars loaded into index 1 and higher?
      Attached Files

      Comment


        #4
        GiantHogweed, my apologies, I thought you were using NT7.

        Since you are using NT6.5, you will have to set up the strategy to have the longest timeframe (daily) as the primary instrument and each additional instrument should be a shorter timeframe.

        Using different times for the start and end of each instrument unfortunately isn't possible.

        Please try re-writing the strategy with the above information in mind and they trying it again. If you're still running into trouble, let us know and we'll see what we can do.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin,

          I am rewriting the strategy using your suggestion. I am now loading 2 instruments worth of daily bars correctly.

          These are the closes for 0 and 1. I am not sure why the time is midnight but it appears the date is correct.

          In for Loop 0
          1831.75 6/28/2010 12:00:00 AM 1069.5
          In for Loop 1
          1839.5 6/25/2010 12:00:00 AM 1074.75
          In for Loop 2
          1848.75 6/24/2010 12:00:00 AM 1070.25
          In for Loop 3
          1873.5 6/23/2010 12:00:00 AM 1087
          In for Loop 4
          1878.25 6/22/2010 12:00:00 AM 1090.25
          In for Loop 5
          1899 6/21/2010 12:00:00 AM 1110.5
          In for Loop 6
          1908.75 6/18/2010 12:00:00 AM 1110.25
          In for Loop 7
          1910.75 6/17/2010 12:00:00 AM 1111.75
          In for Loop 8
          1905.5 6/16/2010 12:00:00 AM 1109.75
          In for Loop 9
          1893.75 6/15/2010 12:00:00 AM 1109.25
          In for Loop 10
          1845.25 6/14/2010 12:00:00 AM 1086
          In for Loop 11
          1842.25 6/11/2010 12:00:00 AM 1085
          In for Loop 12
          1820.25 6/10/2010 12:00:00 AM 1079.5
          In for Loop 13
          1780.75 6/9/2010 12:00:00 AM 1050.75
          In for Loop 14
          1790.25 6/8/2010 12:00:00 AM 1054.5
          In for Loop 15
          1794.5 6/7/2010 12:00:00 AM 1043.25
          In for Loop 16
          1833 6/4/2010 12:00:00 AM 1062.25
          In for Loop 17
          1895.75 6/3/2010 12:00:00 AM 1099.25
          In for Loop 18
          1876.5 6/2/2010 12:00:00 AM 1092.5
          In for Loop 19
          1829.75 6/1/2010 12:00:00 AM 1065
          In for Loop 20
          1856.75 5/31/2010 12:00:00 AM 1085.25

          However, I now have 2 problems.
          1) I am getting IB pacing violations when trying to load the minute data for index 2 and 3. NT appears to be trying to load at least back to 5/29/10 when the violation occurs. Minimum bars required is set to 15 with period to days on the strategy menu, so I'm not sure why NT is trying to go that far back in time.
          2) The minute data is not behaving as the daily data is. This is the contents of index 2 and 3. Instrument 0 is NQ daily, 2 is NQ minute. Instrument 1 is ES daily, 3 is ES minute.
          I am not sure why [2][0] is 4 weeks ago. Also the data series ends at [2][16].....

          In for Loop 0
          1861.75 5/31/2010 12:15:00 AM 1090.25
          In for Loop 1
          1861.75 5/31/2010 12:14:00 AM 1090.25
          In for Loop 2
          1861.75 5/31/2010 12:13:00 AM 1090.25
          In for Loop 3
          1861.75 5/31/2010 12:12:00 AM 1090.25
          In for Loop 4
          1861.75 5/31/2010 12:11:00 AM 1090.25
          In for Loop 5
          1861.75 5/31/2010 12:10:00 AM 1090.25
          In for Loop 6
          1861.75 5/31/2010 12:09:00 AM 1090.25
          In for Loop 7
          1861.75 5/31/2010 12:08:00 AM 1090.25
          In for Loop 8
          1861.75 5/31/2010 12:07:00 AM 1091.5
          In for Loop 9
          1861.75 5/31/2010 12:06:00 AM 1091.5
          In for Loop 10
          1861.75 5/31/2010 12:05:00 AM 1091.5
          In for Loop 11
          1861.75 5/31/2010 12:04:00 AM 1091.5
          In for Loop 12
          1861.75 5/31/2010 12:03:00 AM 1091.5
          In for Loop 13
          1861.75 5/31/2010 12:02:00 AM 1091.5
          In for Loop 14
          1861.75 5/31/2010 12:01:00 AM 1091.5
          In for Loop 15
          1861.75 5/31/2010 12:00:00 AM 1091.5
          In for Loop 16

          Comment


            #6
            Would you mind posting the code (along with a few steps describing what you're doing) so I can try this out on my end?
            AustinNinjaTrader Customer Service

            Comment


              #7
              Here's the code I'm working on. It's a simple spread strategy between NQ and ES, I have more work to do but I'm just trying to get a feel for how the data is retrieved by NT while the strategy is running. I will be doing calcs on the daily data in order to set triggers for entry/exit using the intraday data.

              The code to print spread bid and ask to the output window works, but I am struggling getting the historical data loaded to set the entry/exit points.

              Thanks.
              Attached Files

              Comment


                #8
                Thanks for the file and patience. Austin will be in in the afternoon today and will continue reviewing the strategy then. We will get back to you then.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  GiantHogweed, first of all, I would recommend upgrading to the NinjaTrader 7 beta because multi-instrument, multi-timeframe strategies and indicators have more options now, and you don't have to structure your strategies with the longest time frame being primary.

                  That being said, I stripped down your strategy to the bare minimums in order to show you how the data is loaded. I changed the minute data to 60 minute bars so there is less information to wade through.

                  This code:
                  Code:
                  protected override void Initialize()
                  {
                      Add(ES, PeriodType.Day, 1);                
                      Add (NQ, PeriodType.Minute, 60);
                      Add (ES, PeriodType.Minute, 60);
                                      
                      CalculateOnBarClose = false;
                      Print ("Init Done");
                  }
                  
                  protected override void OnBarUpdate()
                  {
                      Print("BIP: " + BarsInProgress + " Time[0]: " + Time[0] + " Close[0]: " + Close[0]);
                  }
                  Generates this output:
                  Code:
                  BIP: 0 Time[0]: 5/31/2010 12:00:00 AM Close[0]: 1856.75
                  BIP: 1 Time[0]: 5/31/2010 12:00:00 AM Close[0]: 1085.25
                  BIP: 2 Time[0]: 6/1/2010 12:00:00 AM Close[0]: 1850
                  BIP: 3 Time[0]: 6/1/2010 12:00:00 AM Close[0]: 1079.5
                  BIP: 2 Time[0]: 6/1/2010 1:00:00 AM Close[0]: 1849.75
                  BIP: 3 Time[0]: 6/1/2010 1:00:00 AM Close[0]: 1080.25
                  BIP: 2 Time[0]: 6/1/2010 2:00:00 AM Close[0]: 1834.5
                  BIP: 3 Time[0]: 6/1/2010 2:00:00 AM Close[0]: 1069.5
                  BIP: 2 Time[0]: 6/1/2010 3:00:00 AM Close[0]: 1826.75
                  BIP: 3 Time[0]: 6/1/2010 3:00:00 AM Close[0]: 1067
                  BIP: 2 Time[0]: 6/1/2010 4:00:00 AM Close[0]: 1828.75
                  BIP: 3 Time[0]: 6/1/2010 4:00:00 AM Close[0]: 1068.5
                  BIP: 2 Time[0]: 6/1/2010 5:00:00 AM Close[0]: 1829
                  BIP: 3 Time[0]: 6/1/2010 5:00:00 AM Close[0]: 1069
                  BIP: 2 Time[0]: 6/1/2010 6:00:00 AM Close[0]: 1834
                  BIP: 3 Time[0]: 6/1/2010 6:00:00 AM Close[0]: 1069
                  BIP: 2 Time[0]: 6/1/2010 7:00:00 AM Close[0]: 1839
                  BIP: 3 Time[0]: 6/1/2010 7:00:00 AM Close[0]: 1070
                  BIP: 2 Time[0]: 6/1/2010 8:00:00 AM Close[0]: 1845.25
                  BIP: 3 Time[0]: 6/1/2010 8:00:00 AM Close[0]: 1075.75
                  BIP: 2 Time[0]: 6/1/2010 9:00:00 AM Close[0]: 1866
                  BIP: 3 Time[0]: 6/1/2010 9:00:00 AM Close[0]: 1085.75
                  BIP: 2 Time[0]: 6/1/2010 10:00:00 AM Close[0]: 1853.75
                  BIP: 3 Time[0]: 6/1/2010 10:00:00 AM Close[0]: 1079
                  BIP: 2 Time[0]: 6/1/2010 11:00:00 AM Close[0]: 1861
                  BIP: 3 Time[0]: 6/1/2010 11:00:00 AM Close[0]: 1080.25
                  BIP: 2 Time[0]: 6/1/2010 12:00:00 PM Close[0]: 1862.25
                  BIP: 3 Time[0]: 6/1/2010 12:00:00 PM Close[0]: 1083
                  BIP: 2 Time[0]: 6/1/2010 1:00:00 PM Close[0]: 1860.5
                  BIP: 3 Time[0]: 6/1/2010 1:00:00 PM Close[0]: 1081.25
                  BIP: 2 Time[0]: 6/1/2010 2:00:00 PM Close[0]: 1830.75
                  BIP: 3 Time[0]: 6/1/2010 2:00:00 PM Close[0]: 1065.75
                  BIP: 2 Time[0]: 6/1/2010 3:00:00 PM Close[0]: 1830
                  BIP: 3 Time[0]: 6/1/2010 3:00:00 PM Close[0]: 1064.75
                  BIP: 3 Time[0]: 6/1/2010 4:00:00 PM Close[0]: 1064
                  BIP: 2 Time[0]: 6/1/2010 5:00:00 PM Close[0]: 1830.25
                  BIP: 3 Time[0]: 6/1/2010 5:00:00 PM Close[0]: 1065.25
                  BIP: 2 Time[0]: 6/1/2010 6:00:00 PM Close[0]: 1834.25
                  BIP: 3 Time[0]: 6/1/2010 6:00:00 PM Close[0]: 1066.5
                  BIP: 2 Time[0]: 6/1/2010 7:00:00 PM Close[0]: 1838.25
                  BIP: 3 Time[0]: 6/1/2010 7:00:00 PM Close[0]: 1067.75
                  BIP: 2 Time[0]: 6/1/2010 8:00:00 PM Close[0]: 1841.25
                  BIP: 3 Time[0]: 6/1/2010 8:00:00 PM Close[0]: 1071
                  BIP: 2 Time[0]: 6/1/2010 9:00:00 PM Close[0]: 1841.75
                  BIP: 3 Time[0]: 6/1/2010 9:00:00 PM Close[0]: 1071
                  BIP: 2 Time[0]: 6/1/2010 10:00:00 PM Close[0]: 1836.75
                  BIP: 3 Time[0]: 6/1/2010 10:00:00 PM Close[0]: 1067.25
                  BIP: 2 Time[0]: 6/1/2010 11:00:00 PM Close[0]: 1831.25
                  BIP: 3 Time[0]: 6/1/2010 11:00:00 PM Close[0]: 1065.5
                  BIP: 0 Time[0]: 6/1/2010 12:00:00 AM Close[0]: 1829.75
                  BIP: 1 Time[0]: 6/1/2010 12:00:00 AM Close[0]: 1065
                  BIP: 2 Time[0]: 6/2/2010 12:00:00 AM Close[0]: 1836
                  BIP: 3 Time[0]: 6/2/2010 12:00:00 AM Close[0]: 1068.75
                  BIP: 2 Time[0]: 6/2/2010 1:00:00 AM Close[0]: 1838.5
                  BIP: 3 Time[0]: 6/2/2010 1:00:00 AM Close[0]: 1070
                  BIP: 2 Time[0]: 6/2/2010 2:00:00 AM Close[0]: 1843.25
                  BIP: 3 Time[0]: 6/2/2010 2:00:00 AM Close[0]: 1068.25
                  BIP: 2 Time[0]: 6/2/2010 3:00:00 AM Close[0]: 1834.25
                  BIP: 3 Time[0]: 6/2/2010 3:00:00 AM Close[0]: 1067
                  BIP: 2 Time[0]: 6/2/2010 4:00:00 AM Close[0]: 1844.5
                  BIP: 3 Time[0]: 6/2/2010 4:00:00 AM Close[0]: 1070.75
                  BIP: 2 Time[0]: 6/2/2010 5:00:00 AM Close[0]: 1842.75
                  BIP: 3 Time[0]: 6/2/2010 5:00:00 AM Close[0]: 1071.25
                  BIP: 2 Time[0]: 6/2/2010 6:00:00 AM Close[0]: 1845
                  BIP: 3 Time[0]: 6/2/2010 6:00:00 AM Close[0]: 1070.75
                  BIP: 2 Time[0]: 6/2/2010 7:00:00 AM Close[0]: 1838
                  BIP: 3 Time[0]: 6/2/2010 7:00:00 AM Close[0]: 1068.25
                  BIP: 2 Time[0]: 6/2/2010 8:00:00 AM Close[0]: 1837
                  BIP: 3 Time[0]: 6/2/2010 8:00:00 AM Close[0]: 1070
                  BIP: 2 Time[0]: 6/2/2010 9:00:00 AM Close[0]: 1845.75
                  BIP: 3 Time[0]: 6/2/2010 9:00:00 AM Close[0]: 1074
                  BIP: 2 Time[0]: 6/2/2010 10:00:00 AM Close[0]: 1855.75
                  BIP: 3 Time[0]: 6/2/2010 10:00:00 AM Close[0]: 1079.5
                  BIP: 2 Time[0]: 6/2/2010 11:00:00 AM Close[0]: 1861.75
                  BIP: 3 Time[0]: 6/2/2010 11:00:00 AM Close[0]: 1081.25
                  BIP: 2 Time[0]: 6/2/2010 12:00:00 PM Close[0]: 1856.25
                  BIP: 3 Time[0]: 6/2/2010 12:00:00 PM Close[0]: 1078.25
                  BIP: 2 Time[0]: 6/2/2010 1:00:00 PM Close[0]: 1864.5
                  BIP: 3 Time[0]: 6/2/2010 1:00:00 PM Close[0]: 1085.5
                  BIP: 2 Time[0]: 6/2/2010 2:00:00 PM Close[0]: 1876.75
                  BIP: 3 Time[0]: 6/2/2010 2:00:00 PM Close[0]: 1093.75
                  BIP: 2 Time[0]: 6/2/2010 3:00:00 PM Close[0]: 1875.75
                  BIP: 3 Time[0]: 6/2/2010 3:00:00 PM Close[0]: 1093
                  BIP: 2 Time[0]: 6/2/2010 4:00:00 PM Close[0]: 1878.5
                  BIP: 3 Time[0]: 6/2/2010 4:00:00 PM Close[0]: 1095
                  BIP: 2 Time[0]: 6/2/2010 5:00:00 PM Close[0]: 1876
                  BIP: 3 Time[0]: 6/2/2010 5:00:00 PM Close[0]: 1092.25
                  BIP: 2 Time[0]: 6/2/2010 6:00:00 PM Close[0]: 1876.25
                  BIP: 3 Time[0]: 6/2/2010 6:00:00 PM Close[0]: 1092.25
                  BIP: 2 Time[0]: 6/2/2010 7:00:00 PM Close[0]: 1876.5
                  BIP: 3 Time[0]: 6/2/2010 7:00:00 PM Close[0]: 1093.5
                  BIP: 2 Time[0]: 6/2/2010 8:00:00 PM Close[0]: 1881.5
                  BIP: 3 Time[0]: 6/2/2010 8:00:00 PM Close[0]: 1095
                  BIP: 2 Time[0]: 6/2/2010 9:00:00 PM Close[0]: 1878.25
                  BIP: 3 Time[0]: 6/2/2010 9:00:00 PM Close[0]: 1094
                  BIP: 2 Time[0]: 6/2/2010 10:00:00 PM Close[0]: 1882.5
                  BIP: 3 Time[0]: 6/2/2010 10:00:00 PM Close[0]: 1096.5
                  BIP: 3 Time[0]: 6/2/2010 11:00:00 PM Close[0]: 1097.5
                  So, as you can see, there are some gaps (probably from IB's data), but the general picture is that when a bar update occurs, the OnBarUpdate() method is called once for each bars series that has the update at that specific time. Since this strategy is now using 60 minute and daily bars, there are four updates at midnight, one for each series. Then, on every hour, the two 60 minute bar series update.

                  If you are trying to figure out how the bars are loaded and such, I would recommend starting with as little as possible in your strategy, and then adding on complexity one layer at a time.
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

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