• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequest - a few questions

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

    BarsRequest - a few questions

    Hey there,

    I'm using the BarsRequest class to get bar info. In particular I want to know when the BarUpdate callback is resulting from a Bar closing. I see that the callback is firing with every tick - and but I can't see anything obvious to say when a bar has closed. What would be the best method to derive that a bar has just closed?

    Also what is the situation with this class and Historical Data? Will BarUpdates come in as a result of historical data being played back? I note it takes "FromDate" and "ToDate" params - so I'm not sure how this class will work with Historical data.

    I am presently using both BarRequest and MarketData updates in my addon - as I need bar updates and realtime price updates - but I'm wondering if there is any merit to using both, or if BarsRequest will suffice. I'm only using Bid and Ask from the MarketData Updates.

    Final question, what does this property represent in the BarSeries class: EstimatedFutureBarTimeDiff

    thank you!

    Kevin.

    #2
    Hello reach4thelasers,

    Thanks for writing in.

    You may set the BarsPeriod of the BarsRequest to represent a the time period you wish to have the created MyOnBarUpdate() use. Let's look at the sample code in the sample indicator provided.

    Code:
    private NinjaTrader.Data.BarsRequest DoBarsRequest(Instrument instrument, int lookBackPeriod)
    		{
    		  barsRequest = new NinjaTrader.Data.BarsRequest(instrument, DateTime.Now.AddDays(-lookBackPeriod), DateTime.Now);
    		  barsRequest.BarsPeriod = new NinjaTrader.Data.BarsPeriod { BarsPeriodType = BarsPeriodType.Second, Value = 10 };
    		  barsRequest.TradingHours     = NinjaTrader.Data.TradingHours.Get("Default 24 x 7");
    		  barsRequest.Update     += MyOnBarUpdate;
    		  barsRequest.Request(new Action<NinjaTrader.Data.BarsRequest, ErrorCode, string>((b, errorCode, errorMessage) =>
    		  {
    		      Dispatcher.InvokeAsync(new Action(() =>
    		      {
    		          if (errorCode != ErrorCode.NoError)
    		          {
    					  BarsSeries bs = new BarsSeries(barsRequest.Instrument, barsRequest.BarsPeriod, From, To, TradingHours);
    					  return;
    		          }
    		      }));
    		  }));
    		  return barsRequest;
    		}
    The code above sets the BarsPeriod to a 10 second interval. The code is called in the created MyOnBarUpdate() as:

    Code:
    private void MyOnBarUpdate(object sender, NinjaTrader.Data.BarsUpdateEventArgs e)
    		{
    		  	if (e.BarsSeries.GetTime(e.MaxIndex - 1) > currentTime)
    			{
    				Print(e.BarsSeries.GetTime(e.MaxIndex -1) + " MyOnBarUpdate " + e.BarsSeries.GetClose(e.MaxIndex -1));
    				currentTime = e.BarsSeries.GetTime(e.MaxIndex -1);
    			}
    		}
    The close price for that interval will be printed to the Output window. It should be synchronized with the primary data series you assign it to. If you apply the indicator to another 10 second chart, you will see consistent results. This logic is not documented in the help guide but you should be able to simulate the close of a bar using e.MaxIndex -1.

    To answer your second question, a BarsRequest will download any bars that are not already available locally. This includes historical data in the BarsRequest.

    For your third question, the BarsRequest will receive OHLC (Open High Low Close) data. If you wish to use Bid and Ask, you may subscribe to OnMarketData().

    To answer your final question, EstimatedFutureBarTimeDiff is an undocumented internal property. I was not able to come up with any information on it, but you can place Print() calls to observe this Property's behavior.

    Please let me know if you have any further questions.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for the response Jim. So are you saying that to determine if the bar has just closed I should keep a record of the Time of BarIndex - 1 and when I get an update with a new time then it means it's a new bar? Makes sense.

      My question about historical data was about playback connections. Can this be used on a playback connection the same way as live?

      Comment


        #4
        Hello reach4thelasers,

        Thanks for writing back.

        Yes you understand correctly, keeping track of the time of BarIndex - 1 should coincide with the last bar close.

        As there is no established connection, a BarsRequest will not be able to download new data when it is connected to Market Replay. BarsRequest will only give you results when connected to a live connection or when Market Replay is playing and the historical data exists.

        If you have any other questions, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by franki, Yesterday, 08:10 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by ballboy11, Yesterday, 05:22 PM
        0 responses
        3 views
        0 likes
        Last Post ballboy11  
        Started by ballboy11, Yesterday, 04:33 PM
        2 responses
        4 views
        0 likes
        Last Post ballboy11  
        Started by dedouglas, Yesterday, 03:16 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeMyth, Yesterday, 02:45 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X