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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          70 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          152 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          162 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          100 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          288 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X