• 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

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.
      Patrick H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by babouin77, Today, 12:41 PM
      0 responses
      2 views
      0 likes
      Last Post babouin77  
      Started by punkiy2111, Today, 12:17 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Tabor  
      Started by GLFX005, Today, 11:22 AM
      2 responses
      18 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by mintxom, Today, 10:25 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Melissa  
      Started by Matts7, Today, 08:27 AM
      4 responses
      42 views
      0 likes
      Last Post Matts7
      by Matts7
       
      Working...
      X