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

How to use GetBar on tick charts

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

    How to use GetBar on tick charts

    When I call Bars.GetBar() on a tick chart with an End Date in the past, the bar data for that index is incorrect.

    Eg. I load a 233 Tick chart for CL ##-## with 15 days data ending on Jan 15 2016. The bar index for Bars.GetBar(new DateTime(2016,01,11,9,15,20)) is 7487

    Time[7487] = 1/7/2016 10:50:03 PM, and any bar data or indicator values are also wrong.

    No doubt I'm missing something obvious.. do I need to offset the value from GetBar somehow?

    To test, I have an indicator with just the following code in a mouse up event, and no other indicators in the chart.

    Code:
    var barTime = new DateTime(2016,1,11,9,15,20);
    var barIndex = Bars.GetBar(barTime);
    Print (string.Format("Time: {0}, barIndex: {1}, Time[barIndex]: {2}",
    				barTime, barIndex, Time[barIndex]));
    Output window shows:
    Time: 1/11/2016 9:15:20 AM, barIndex: 7487, Time[barIndex]: 1/7/2016 10:50:03 PM

    thanks.

    #2
    Originally posted by pj17903 View Post
    When I call Bars.GetBar() on a tick chart with an End Date in the past, the bar data for that index is incorrect.

    Eg. I load a 233 Tick chart for CL ##-## with 15 days data ending on Jan 15 2016. The bar index for Bars.GetBar(new DateTime(2016,01,11,9,15,20)) is 7487

    Time[7487] = 1/7/2016 10:50:03 PM, and any bar data or indicator values are also wrong.

    No doubt I'm missing something obvious.. do I need to offset the value from GetBar somehow?

    To test, I have an indicator with just the following code in a mouse up event, and no other indicators in the chart.

    Code:
    var barTime = new DateTime(2016,1,11,9,15,20);
    var barIndex = Bars.GetBar(barTime);
    Print (string.Format("Time: {0}, barIndex: {1}, Time[barIndex]: {2}",
    				barTime, barIndex, Time[barIndex]));
    Output window shows:
    Time: 1/11/2016 9:15:20 AM, barIndex: 7487, Time[barIndex]: 1/7/2016 10:50:03 PM

    thanks.
    RTF(ree)Manual. That statement returns the bar's index, not the number of bars ago. To get the number of bars ago, you would have to deduct the index from CurrentBar. In other words, Bars.GetBar returns the index of the bar; Time[] returns the value of a number of bars ago from the CurrentBar.

    The example in the manual shows this very nuance.

    ref: http://ninjatrader.com/support/helpG...nt7/getbar.htm

    NB: To confuse matters further, the undocumented GetBar() does return the barsAgo value. Note that this latter is not a property of the Bars object.

    ref: http://ninjatrader.com/support/forum...45&postcount=3

    Not a very good idea to have a method named the same that returns values based on opposite concepts, precisely because it is so easy to use the wrong construct by mistake. You leave out the object specifier, and you get the opposite effect. But that is the way this cookie crumbles.
    Last edited by koganam; 01-08-2017, 01:04 PM.

    Comment


      #3
      So I was right --
      No doubt I'm missing something obvious..
      :-)

      Thanks koganam - I thought I had tried that but obviously not.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by geddyisodin, 04-25-2024, 05:20 AM
      8 responses
      58 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      4 responses
      3,285 views
      1 like
      Last Post jgualdronc  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      5 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      22 views
      0 likes
      Last Post halgo_boulder  
      Started by mishhh, 05-25-2010, 08:54 AM
      19 responses
      6,189 views
      0 likes
      Last Post rene69851  
      Working...
      X