Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

BarsRequest with DateTime

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

    BarsRequest with DateTime

    I've been trying to do a BarsRequest for a short timeframe for a period of 1 day. I added a Datetime parameter to the function, which seems to be working, but the bars that are returned are from the wrong date. Am I missing something to do this?

    This is a sample from the output window:
    Time was: 22/11/2016 12:00:00 AM High was: 2202.25 Low was: 2191.75
    datetime: 22/11/2016 12:00:00 AM
    Primary Series: Time: 5/12/2016 5:01:01 AM Open: 2181.25 High: 2181.25 Low: 2181.25 Close: 2181.25 Volume: 0
    Primary Series: Time: 5/12/2016 5:01:02 AM Open: 2181.5 High: 2181.5 Low: 2181.5 Close: 2181.5 Volume: 0
    Primary Series: Time: 5/12/2016 5:01:03 AM Open: 2181.75 High: 2181.75 Low: 2181.75 Close: 2181.75 Volume: 0
    Primary Series: Time: 5/12/2016 5:01:09 AM Open: 2182 High: 2182 Low: 2182 Close: 2182 Volume: 0
    Primary Series: Time: 5/12/2016 5:01:13 AM Open: 2182.25 High: 2182.25 Low: 2182.25 Close: 2182.25 Volume: 0
    Primary Series: Time: 5/12/2016 5:01:32 AM Open: 2182 High: 2182 Low: 2182 Close: 2182 Volume: 0
    Code:
    public BarsRequest RequestPrimaryBars(DateTime datetime)
    		{
    			Print("datetime: " + datetime);
    			primaryBarsRequest = new BarsRequest(Cbi.Instrument.GetInstrument(Instrument.FullName), datetime, datetime.AddDays(1));
    			    	
    			// Parametrize your request. 
    			primaryBarsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Second, Value = 1 };
    			primaryBarsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
    			
    			  // Request the bars
    			primaryBarsRequest.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
    			for (int i = 0; i < bars.Bars.Count; i++)
    			{
    			  // Output the bars
    			  NinjaTrader.Code.Output.Process(string.Format("Primary Series: Time: {0} Open: {1} High: {2} Low: {3} Close: {4} Volume: {5}",
    			                                  bars.Bars.GetTime(i),
    			                                  bars.Bars.GetOpen(i),
    			                                  bars.Bars.GetHigh(i),
    			                                  bars.Bars.GetLow(i),
    			                                  bars.Bars.GetClose(i),
    			                                  bars.Bars.GetVolume(i)), PrintTo.OutputTab1);
    			}
    			}));
    			return primaryBarsRequest;
    		}

    #2
    Hello,

    Thank you for the post.

    From what has been posted I am unable to tell what may be happening, could you try the attached sample to see if you have the same result? The attached sample is a combination of what you had provided along with the existing method we document here: http://ninjatrader.com/support/helpG...r_an_addon.htm

    I added this into a toolbar button example for easy control over the request, it adds a Wrench icon to the chart toolbar where you apply the indicator. Clicking the button runs the BarsRequest once and prints the results. I have attached an image of the results that I had seen.



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

    Comment


      #3
      I tried using the attached file, and it says button is working. The only problem is that I don't have up to date data, so it didn't generate any bars, as it uses DateTime.Now. I attached a screenshot of the output, using market replay data.

      I should also disclose that I made a previous BarsRequest for daily data prior to executing this one, so it might be causing a conflict. They are using separate objects and functions.
      Attached Files
      Last edited by Matts; 04-06-2017, 03:16 AM. Reason: added screenshot

      Comment


        #4
        Hello Matts,

        Thank you for the additional details.

        Would you be able to modify this sample script to use the date you had originally and also the bar settings? I was unable to see the occurrence you had originally as I was not certain on the overall scope of how you were using the BarsRequest. Also it could be that I was testing on historical/realtime data where you were using market reply. I will try this again on my side as well but if you could modify the date and re test that would be good.

        If you are able to otherwise make a sample out of your existing script and how you are using the BarsRequest, I could try running that in replay as well to see if we get similar results over the same instrument/timeframe.

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

        Comment


          #5
          I hardcoded the date, and changed the bar settings in the attached file which produces the same result, when run with market replay on 6/12/2016. I haven't used the returned bars yet, as I couldn't get them to output correctly.
          Attached Files

          Comment


            #6
            Hello Matts,

            Thank you for providing the sample.

            I wanted to check, you have a date hard coded for 11/22/2016, do you have replay data available for this instrument for this day? I am unable to download replay data for this date on this instrument. I do see that when doing a request and there is no data available the base series is returned. Potentially this is what you are seeing in the case that you do not have data for that date.

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

            Comment


              #7
              Looks like I've randomly chosen a US holiday for the date, but I do have data for that date. I'm using historical downloaded data, not from market replay button. If I used another date. E.g. 12/2/2016 it still reproduces the error.

              Comment


                #8
                Hello Matts,

                Thank you for the reply.

                After using a different date I can see a difference between the results of using a data feed and playback mode while doing the BarsRequest. Because there is currently no documentation surrounding using a playback connection and a bars request I will need to gather further details if this would be expected or if we need to change how we are approaching this or if we have run into a bug.

                Once I have more details on this I will reply back.

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

                Comment


                  #9
                  Hello,

                  I just wanted to reply back on this item.

                  It appears that the output we are getting in Playback modes specifically would be expected. Development had further reviewed this case and determined that the request of the bars would not work correctly in this situation. This will be documented with the next release. In this case, I don't believe there would be any solution for playback modes specifically.

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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Irukandji, Today, 09:34 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Irukandji  
                  Started by TraderBCL, Today, 04:38 AM
                  3 responses
                  25 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  11 responses
                  1,423 views
                  0 likes
                  Last Post jculp
                  by jculp
                   
                  Started by RubenCazorla, Today, 09:07 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post RubenCazorla  
                  Started by BarzTrading, Today, 07:25 AM
                  2 responses
                  29 views
                  1 like
                  Last Post BarzTrading  
                  Working...
                  X