Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index out of range get_tradingHour

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

    Index out of range get_tradingHour

    Hello

    I have a problem when loading data with BarsRequest.
    I have included the trace file stating the nature of the problem.

    I can send you piece of code if you need to

    Thank you
    Attached Files
    Last edited by blar58; 06-15-2016, 05:57 AM.

    #2
    Hello,

    Thank you for the question.

    I wanted to check, are you specifically calling a BarsRequest or are you referring to a chart getting its data? If you are specifically doing a bars request in your script, If you have a sample of just the BarsRequest you are doing that would be helpful to see what is causing the error. The error is an index error of some kind, possibly related TradingHours.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse
      Here is the code related to the BarsRequest

      I cannot see what cause this index out of range error based on the code.

      I have to say also that it is randomly happening. Sometimes it takes two or three tries and that's it it works ...

      Code:
      public void RequestSeries()
      {
      									
      if (barsRequest != null)
      {
      									     Print(" BarsRequest was not null !");	      			                    barsRequest.Update -= OvernightBarUpdate;
      }
      										
      
      primaryInstrument = Instrument.GetInstrument(Instrument.FullName);
      									
      if (primaryInstrument == null)
      {
      NinjaTrader.Code.Output.Process(string.Format("Invalid instrument {0}",primaryInstrument), PrintTo.OutputTab1);
      									     return;
      }
      										
      									
      TradingHours tradingHours = TradingHours.Get("ES-OvernightOnly");
      BarsPeriod barsPeriod = new BarsPeriod() { BarsPeriodType = BarsPeriodType.Minute, Value = 30 };
      									
      if(tradingHours.Sessions[0].BeginTime < tradingHours.Sessions[0].EndTime)
      BarsBack =  ((( (int)(tradingHours.Sessions[0].EndTime/100) - (int)(tradingHours.Sessions[0].BeginTime/100) ) * 60) + ( (tradingHours.Sessions[0].EndTime % 100) + (tradingHours.Sessions[0].BeginTime % 100) )) / ChartPeriod; 
      else
      BarsBack = (((24 - (int)(tradingHours.Sessions[0].BeginTime/100)) * 60) + (tradingHours.Sessions[0].BeginTime % 100) + ((int)(tradingHours.Sessions[0].EndTime/100) * 60) + tradingHours.Sessions[0].EndTime % 100 ) / ChartPeriod;
      
      barsRequest = new BarsRequest(primaryInstrument, BarsBack)
      {										BarsPeriod = barsPeriod,
      										TradingHours = tradingHours
      };
      								
      barsRequest.Update += OvernightBarUpdate;
      					
      							
      barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
      {
      if (errorCode != ErrorCode.NoError)
      {
      // Handle any errors in requesting bars here
      NinjaTrader.Code.Output.Process(string.Format("Error on requesting bars: {0}, {1}",errorCode, errorMessage), PrintTo.OutputTab1);
      									     return;
      }
      // Output the bars we requested. Note: The last returned bar may be a currently in-progress bar
      								               int count = 0;
      									 for (int i = 0; i < bars.Bars.Count; i++)
      {
      if( bars.Bars.GetTime(i) > TradingHours.GetPreviousTradingDayEnd(DateTime.Now) )
      {
      
      primaryDate = bars.Bars.GetTime(i);
      									    primaryVolume = (int)bars.Bars.GetVolume(i);
      									    primaryOpen = (double)bars.Bars.GetOpen(i);
      									    primaryHigh = (double)bars.Bars.GetHigh(i);
      									    primaryLow = (double)bars.Bars.GetLow(i);
      									    primaryClose = (double)bars.Bars.GetClose(i);
      }
      Last edited by blar58; 06-15-2016, 07:59 AM.

      Comment


        #4
        Hello,

        thank you for providing this, after filling in the missing variables I do see this working on my end. I am able to request the ES and print from the barsRequest.Update event. Also i was able to retrieve the values.

        I wanted to check the following items:
        what is the session you are using defined as? I made a copy of the ES default session for my test.

        Was this being run on the ES or another instrument?
        Was this from an Addon or another type? I tested using the attached indicator.

        If you could try the attached indicator to see if that works, it may help limit the search if this bars request is part of a larger script.

        I look forward to being of further assistance.
        Attached Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          The Session I am using is a custom session that I created and it includes only overnight ES Session from 6PM to 930AM.

          It is run on ES

          It is not from an AddOn it is part of a larger script.
          The BarsRequest has been put in the OnStateChange() State = Historical.

          I see that you have put your RequestSeries method in State = Realtime.
          Could that be the problem ?

          Thanks
          Last edited by blar58; 06-15-2016, 08:41 AM.

          Comment


            #6
            Hello,

            I was only testing on Realtime as that was an easy event to use. I will test with the new information you had provided.

            Were you able to run the sample I had provided or does it still produce the same error?

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Yes
              Works fine.

              But as I said before it happens randomly.
              This morning I had this error when I first loaded the indicator.
              The second try was OK and it works since that time.

              Comment


                #8
                Hello,

                Thank you for the reply.

                I will continue testing this item, if you are able to narrow down a situation where this occurs more frequently I would be interested in the steps to produce that scenario.

                If I have further questions or developments I will reply back here.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  I think that I know what the problem is.

                  Instead of using BarsBack on the request method :
                  barsRequest = new BarsRequest(primaryInstrument, BarsBack)

                  I am using to two dates like this :
                  barsRequest = new BarsRequest(primaryInstrument, From date , To date)

                  and the problem just disappeared.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by adeelshahzad, Today, 03:54 AM
                  5 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by stafe, 04-15-2024, 08:34 PM
                  7 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by merzo, 06-25-2023, 02:19 AM
                  10 responses
                  823 views
                  1 like
                  Last Post NinjaTrader_ChristopherJ  
                  Started by frankthearm, Today, 09:08 AM
                  5 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  43 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X