Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Will the real current bar please stand up

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

    Will the real current bar please stand up

    Hi,
    I am new to Ninjascript programming but am a developer w/ 20+ years experience.
    What I am wanting to do seems simple enough ... after initialization and startup of my indicator I want to reference the "current" bar in OnBarUpdate. Not CurrentBar as defined in the docs, but rather the most current bar from a time point of view.

    So, I put in the following test code:
    protectedoverridevoid OnBarUpdate()
    {
    Print(CurrentBar.ToString() +
    ", " +
    (Bars.Count - 1).ToString());
    if (CurrentBar == Bars.Count - 1)
    {
    // Do my thing!
    }
    }
    Now, I run it and check the output window for the last entry.
    It shows CurrentBar = 1378 and Bars.Count - 1 = 1379.
    It seems that OnBarUpdate does not get called for the "current/last" bar.
    Am I just missing something? Is there an easier way to determine the right-most bar on a chart on start up? I'm just having too much fun!
    Thanks ... Ed




    #2
    Originally posted by edstaffin View Post
    Hi,
    I am new to Ninjascript programming but am a developer w/ 20+ years experience.
    What I am wanting to do seems simple enough ... after initialization and startup of my indicator I want to reference the "current" bar in OnBarUpdate. Not CurrentBar as defined in the docs, but rather the most current bar from a time point of view.

    So, I put in the following test code:
    protectedoverridevoid OnBarUpdate()
    {
    Print(CurrentBar.ToString() +
    ", " +
    (Bars.Count - 1).ToString());
    if (CurrentBar == Bars.Count - 1)
    {
    // Do my thing!
    }
    }
    Now, I run it and check the output window for the last entry.
    It shows CurrentBar = 1378 and Bars.Count - 1 = 1379.
    It seems that OnBarUpdate does not get called for the "current/last" bar.
    Am I just missing something? Is there an easier way to determine the right-most bar on a chart on start up? I'm just having too much fun!
    Thanks ... Ed
    ref: http://www.ninjatrader.com/support/f...d.php?p=261631

    Comment


      #3
      Hello edstaffin,

      Thank you for your post.

      The CurrentBar will be the current bar OnBarUpdate() is processing. The indicators and strategies will need to pass through each bar on the chart, so CurrentBar will not equal count at all times.

      Koganam provided a link to an unsupported item he provided to another user who asked about the true last bar on the chart, so thank you to Koganam for that as well.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      605 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      351 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      561 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X