Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Script is stuck getting daily bars required.

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

    Script is stuck getting daily bars required.

    Hi All,
    I am trying to add daily bars to my 1 minute strategy to calculate OHLC and rang of 5 days of the previous five days. Say for example CL 02-13. Also tried using 1440 as a minute bar.

    Under Initialize();
    Code:
                //Add(PeriodType.Minute, 1440);
                Add(PeriodType.Day, 1);
    Code:
                            PrintWithTimeStamp(Instrument.FullName+" Calculating OHLCR...");
                            Print(" OPEN  0 =" + Opens[1][0]+ " HIGH  0 =" + Highs[1][0]+ " LOW   0 =" + Lows[1][0]
                                + " CLOSE 0 =" + Closes[1][0]+ " RANGE 0 =" + (Highs[1][0] - Lows[1][0]));
                            
                            Print(" OPEN  1 =" + Opens[1][1]+ " HIGH  1 =" + Highs[1][1]+ " LOW   1 =" + Lows[1][1]
                                + " CLOSE 1 =" + Closes[1][1]+ " RANGE 1 =" + (Highs[1][1] - Lows[1][1]));
                            
                            Print(" OPEN  2 =" + Opens[1][2]+ " HIGH  2 =" + Highs[1][2]+ " LOW   2 =" + Lows[1][2]
                                + " CLOSE 2 =" + Closes[1][2]+ " RANGE 2 =" + (Highs[1][2] - Lows[1][2]));
                            
                            Print(" OPEN  3 =" + Opens[1][3]+ " HIGH  3 =" + Highs[1][3]+ " LOW   3 =" + Lows[1][3]
                                + " CLOSE 3 =" + Closes[1][3]+ " RANGE 3 =" + (Highs[1][3] - Lows[1][3]));
                            
                            Print(" OPEN  4 =" + Opens[1][4]+ " HIGH  4 =" + Highs[1][4]+ " LOW   4 =" + Lows[1][4]
                                + " CLOSE 4 =" + Closes[1][4]+ " RANGE 4 =" + (Highs[1][4] - Lows[1][4]));
    
                            Print(" OPEN  5 =" + Opens[1][5]+ " HIGH  5 =" + Highs[1][5]+ " LOW   5 =" + Lows[1][5]
                                + " CLOSE 5 =" + Closes[1][5]+ " RANGE 5 =" + (Highs[1][5] - Lows[1][5]));
    Minimum bars required in the UI are set to 20 and I have the following checks within OnBarUpdate():

    Code:
    if (Historical) {//Print(Instrument.FullName+ " Running on Historical Data");
                    return;}
    if (CurrentBars[0] < BarsRequired) {Print(Instrument.FullName+" Getting Bars[0] Required"); return;}
    if (CurrentBars[1] < BarsRequired) {Print(Instrument.FullName+" Getting Bars[1] Required"); return;}
    My session template in instrument manager is set to Nymex Metals / Energy ETH

    I have tried both IB and ZenFire data feeds but my script is stuck on getting required daily bars.

    Code:
    if (CurrentBars[1] < BarsRequired) {Print(Instrument.FullName+" Getting Bars[1] Required"); return;}
    CL 02-13 Getting Bars[1] Required
    CL 02-13 Getting Bars[1] Required
    CL 02-13 Getting Bars[1] Required
    CL 02-13 Getting Bars[1] Required



    Any help would be greatly appreciated!


    thanks
    Tariq

    #2
    Hi Tariq, thanks for the post - how many days are you loading here on the chart you run the strategy on? If you have BarsRequired set to 20 > this is what you would need to load for all series, so 5 days back would for example not be enough to see the OnBarUpdate() then firing. If you increase the lookback as needed, what outcome would you see?

    Comment


      #3
      Thanks Bertrand for replying to my thread.....

      Never had this issue since I always loaded multi-time frames within a day.........

      The issue is not resolved. I tried changing the days to load to 15 and it did not work!

      "how many days are you loading here on the chart you run the strategy on?"

      I needed 5 days worth of daily candles to get OHLC values.

      In the UI - Lookback period was set to default which is 256 and minimum bars required was 20. Days to load was set to 5
      Last edited by mypkonline; 01-07-2013, 10:17 AM. Reason: Not resolved

      Comment


        #4
        Glad to hear, you could unfortunately not set the DaysToLoad in Initialize() to deal with programmatically. What you can do though is setting MinBarsRequired lower > this could be then set from Initialize().

        Comment


          #5
          Hi Bertrand,

          The issue is not resolved, I thought it did but I had the code for //Add(PeriodType.Minute, 240);.

          I tried changing the days to load to 15 and it did not work.

          Please, help!

          Comment


            #6
            Sorry I'm not following you, what do you mean please by your 'but I had the code for //Add(PeriodType.Minute, 240);' comment?

            You had the minute bars commented out and the daily bars added, to see any OnBarUpdate() call taking place you would need to load more days than then set BarsRequired. The lookback for the dataseries you refer to in your first post would have any affect on this outcome.

            Comment


              #7
              You mean would have no affect of look back period?

              I had the minutes bar un-commented out and the day bar was commented out when it worked. Then I updated the post when it didn't work on the day bar without comments.


              Here is the code:

              Code:
                      protected override void Initialize()
                      {
              //            Print("©2012 Sans Emotions Trading LLC - OHLCR trial version");
                          Add(PeriodType.Day, 1);
                          //Add(PeriodType.Minute, 240);
              
                          ExitOnClose = true;
                          ExitOnCloseSeconds = 61;
                          
                          TimeInForce = Cbi.TimeInForce.Day;
                          
                          //Debugging
                          TraceOrders        = true;
                          CalculateOnBarClose = false; // should be last statement in initialize method
                      }
                      #endregion
                          
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
              //        Print("©2012 Sans Emotions Trading LLC - OHLCR Trial Version");
                      protected override void OnBarUpdate()
                      {
                          
                          if (Historical) {//Print(Instrument.FullName+ " Running on Historical Data");
                              return;}
                          if (CurrentBars[0] < BarsRequired) {Print(Instrument.FullName+" Getting Bars[0] Required"); return;}
                          if (CurrentBars[1] < BarsRequired) {Print(Instrument.FullName+" Getting Bars[1] Required"); return;}
              
                          switch (Position.MarketPosition)
                          {
                              case MarketPosition.Flat:
                                  
                                  previousPrice = 0;
               
                                  if (BarsSinceExit(0,"",0) > 0 || BarsSinceExit(0,"",0) == -1)
                                  {
                                      //Print(Instrument.FullName+" Calculating 4 Hours OHLCR...");
                                      Print(Instrument.FullName+" Calculating daily OHLCR...");
                                      
                                      Print(" OPEN  0 =" + Opens[1][0]+ " HIGH  0 =" + Highs[1][0]+ " LOW   0 =" + Lows[1][0]
                                          + " CLOSE 0 =" + Closes[1][0]+ " RANGE 0 =" + (Highs[1][0] - Lows[1][0]));
                                      
                                      Print(" OPEN  1 =" + Opens[1][1]+ " HIGH  1 =" + Highs[1][1]+ " LOW   1 =" + Lows[1][1]
                                          + " CLOSE 1 =" + Closes[1][1]+ " RANGE 1 =" + (Highs[1][1] - Lows[1][1]));
                                      
                                      Print(" OPEN  2 =" + Opens[1][2]+ " HIGH  2 =" + Highs[1][2]+ " LOW   2 =" + Lows[1][2]
                                          + " CLOSE 2 =" + Closes[1][2]+ " RANGE 2 =" + (Highs[1][2] - Lows[1][2]));
                                      
                                      Print(" OPEN  3 =" + Opens[1][3]+ " HIGH  3 =" + Highs[1][3]+ " LOW   3 =" + Lows[1][3]
                                          + " CLOSE 3 =" + Closes[1][3]+ " RANGE 3 =" + (Highs[1][3] - Lows[1][3]));
                                      
                                      Print(" OPEN  4 =" + Opens[1][4]+ " HIGH  4 =" + Highs[1][4]+ " LOW   4 =" + Lows[1][4]
                                          + " CLOSE 4 =" + Closes[1][4]+ " RANGE 4 =" + (Highs[1][4] - Lows[1][4]));
              
                                      Print(" OPEN  5 =" + Opens[1][5]+ " HIGH  5 =" + Highs[1][5]+ " LOW   5 =" + Lows[1][5]
                                          + " CLOSE 5 =" + Closes[1][5]+ " RANGE 5 =" + (Highs[1][5] - Lows[1][5]));
              Please see UI values in the attached image and advice which ones are needed to changed.



              The strategy is still stuck at getting the daily bars.....even playing around different values in the UI.
              Attached Files

              Comment


                #8
                Correct, meant it would not have any impact.

                You have two options here - decrease BarsRequired or have higher DaysToLoad to exceed BarsRequired.

                For the settings you show here I would expect your outcome.

                Comment


                  #9
                  You have two options here - decrease BarsRequired or have higher DaysToLoad to exceed BarsRequired.
                  I have set BarsRequired = 20 and DaysToLoad = 25

                  Still no luck!

                  CL 02-13 Getting Bars[1] Required
                  CL 02-13 Getting Bars[1] Required
                  CL 02-13 Getting Bars[1] Required
                  CL 02-13 Getting Bars[1] Required
                  CL 02-13 Getting Bars[1] Required
                  CL 02-13 Getting Bars[1] Required


                  Any other suggestion?

                  Comment


                    #10
                    Hello,

                    There may not be 20 bars in a request for 25 days to load, considering the weekends, and holidays.

                    Try increasing the number of days to load to an even higher value to ensure that there are more than 20 bars loaded.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Works perfect! Shoulda Woulda Coulda....................

                      Is there a way to set "Days to load" up in the strategy code as my UI defaults are set to 5? Which might go into the code assembly.

                      Thanks a lot, you guys are awesome!

                      Comment


                        #12
                        There is not a supported method to set the days to load. You will have to set the UI defaults by right clicking on the grid with the desired settings and hitting 'save as default'
                        MatthewNinjaTrader Product Management

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        637 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        366 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
                        572 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X