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 Mestor, 03-10-2023, 01:50 AM
      16 responses
      388 views
      0 likes
      Last Post z.franck  
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      31 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Started by yertle, Yesterday, 08:38 AM
      7 responses
      29 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      22 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Working...
      X