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

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 quantismo, 04-17-2024, 05:13 PM
      4 responses
      30 views
      0 likes
      Last Post quantismo  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      31 views
      0 likes
      Last Post love2code2trade  
      Started by cls71, Today, 04:45 AM
      2 responses
      10 views
      0 likes
      Last Post eDanny
      by eDanny
       
      Started by proptrade13, Today, 11:06 AM
      0 responses
      5 views
      0 likes
      Last Post proptrade13  
      Started by kulwinder73, Today, 10:31 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X