Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequest

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

    BarsRequest

    Hello
    I have a question relating to barsRequest.
    I am asking to load data from 5/20/2020 6:00PM to 5/21/2020 9:30AM.
    When I print the start date to load from the barsRequest It shows 5/20/2020. Everything's fine.
    I have a for loop that goes through the bars. On bars.Bars.GetTime(i) when i=0 ( the first bar loaded ) it shows me 5/19/2020 6:00PM.

    Here is the print out :

    new BarsRequest StartDateToLoad 5/20/2020 6:00:00 PM new BarsRequest EndDateToLoad 5/21/2020 9:30:00 AM
    bars.Bars.GetTime(i) when i=0 : 5/19/2020 6:00:00 PM



    Am I missing something ?

    Thank you
    Last edited by blar58; 05-21-2020, 09:39 AM.

    #2
    Hello blar58,

    Thank you for your post.

    Would you be able to provide your code for the bars request so I may test on my end? Just a snippet of when you create the request and then loop through the bars would be fine.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      TradingHours tradingHours = TradingHours.Get(ONSessionTemplate);
      BarsPeriod barsPeriod = new BarsPeriod() { BarsPeriodType = BarsPeriodType.Minute, Value = ChartPeriod };


      barsRequest = new BarsRequest(primaryInstrument, LocalStartDateToLoad, LocalEndDateToLoad)
      {
      BarsPeriod = barsPeriod,
      TradingHours = tradingHours
      };


      barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
      {

      try
      {

      if (errorCode != ErrorCode.NoError)
      {
      // Handle any errors in requesting bars here
      NinjaTrader.Code.Output.Process(string.Format("Err or on requesting bars: {0}, {1}",
      errorCode, errorMessage), PrintTo.OutputTab1);
      return;
      }
      ;
      for (int i = 0; i < bars.Bars.Count; i++)
      {
      if(i==0)
      Print(bars.Bars.GetTime(i)+" "+LocalStartDateToLoad);

      }

      Comment


        #4
        Hello blar58,

        Thank you for your reply.

        Your issue here is that you are using the DateTime fromLocal and toLocal parameters when requesting less than 1 full trading day.

        When using the DateTime fromLocal and toLocal parameters, the dates are converted to local daily timestamps (12:00 AM) and return a BarsRequest representing full trading days. If you need to request less than one full trading day, you'd need to use the barsBack parameter instead.

        Code:
        BarsRequest(Cbi.Instrument instrument, int barsBack)
        Basically you'd need to figure out how many bars that period of time would span and use that in the BarsRequest instead.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          OK Understood Kate

          Thank you very much

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          578 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X