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

On The Last Bar Update

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

    On The Last Bar Update

    I'm working on an indicator and if I set the date range of the chart and then only put this:
    Code:
    protected override void OnBarUpdate()
    {
    Print(Time[0].ToShortDateString());
    }
    The output window shows every date in the range (minus weekends and holidays) up to the day before my end date but does not show my end date. However if I look on the chart the end date is there as expected.

    How can I execute code on the last bar update?

    #2
    Thanks for the post LorneCash, this will completely depend on the CalculateOnBarClose setting set for the script - http://www.ninjatrader.com/support/h...onbarclose.htm

    With the default true setting your outcome would be expected, as the bar has not yet fully closed in the sense that the opening of the next was not seen (event based approach here).
    BertrandNinjaTrader Customer Service

    Comment


      #3
      OK so I understand why it's behaving the way it does but my questions still remains...

      How can I execute code only after the last bar update? We have a nice method OnBarUpdate but that gets executed after EVERY bar... I want to execute code only after the LAST bar. I'm guessing I will need to put some sort of IF condition inside the OnBarUpdate method but I'm not sure what that should be.

      I also tried looking for another method to override but there didn't seem to be one that was appropriate.

      Comment


        #4
        The reason I want to do this is that I want to draw stuff on the chart and I really don't need or want to draw it after every bar update... that would be wasted processing power. I use OnBarUpdate to gather data and then at the very end I want to draw a bunch of stuff.

        Comment


          #5
          I see, there's not really an event for the end of the chart, but you can detect via comparing CurrentBar and Count - http://www.ninjatrader.com/support/h.../nt7/count.htm
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thank you that works.

            Comment


              #7
              This is the exact code I was looking for just in case anyone else finds this useful. This allows me to simulate what might be called OnLastBarUpdate or OnBarUpdateComplete event.

              Code:
              if (CurrentBar >= Count - 1 - Convert.ToInt32(CalculateOnBarClose))

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, Yesterday, 09:53 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by Rapine Heihei, Yesterday, 07:51 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by kaywai, Today, 06:26 AM
              1 response
              6 views
              0 likes
              Last Post kaywai
              by kaywai
               
              Started by ct, 05-07-2023, 12:31 PM
              6 responses
              206 views
              0 likes
              Last Post wisconsinpat  
              Started by kevinenergy, 02-17-2023, 12:42 PM
              118 responses
              2,780 views
              1 like
              Last Post kevinenergy  
              Working...
              X