Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Open, High, Low, Close values on uncompleted bar if Calculate.OnBarClose?

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

    How to get Open, High, Low, Close values on uncompleted bar if Calculate.OnBarClose?

    Hello.

    If indicator (or strategy) work with Calculate = Calculate.OnBarClose, but need High and Low prices of very last uncompleted bar - how can it be accessed?

    In NT7 it was simple: High[-1], Low[-1].
    But, NT8 generate exception.
    So, what is correct way?

    High.GetValueAt( CurrntBar+1) ?
    Last edited by fx.practic; 08-11-2017, 11:12 AM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Thanks for opening the thread.

    Since Calculate.OnBarClose iterates OnBarUpdate() after the bar has closed, there would not be an iteration happening while the bar is developing and you would not be able to reference the bar while it is developing.

    The advised solution would be to use Calculate.OnEachTick to get the value of the developing bar.

    You could use logic to in OnBarUpdate() to make the NinjaScript perform certain actions on each tick, and you can also restrict your logic to perform on the first tick of a bar.

    Using Calculate.OnEachTick with IsFirstTickOfBar can give you effectively the same results as Calulcate.OnBarClose if you look at the previous bar on that first tick of a new bar.

    Code:
    protected override void OnBarUpdate()
    {
        // Only process entry signals on a bar by bar basis (not tick by tick)
        // This can mimic Calculate.OnBarClose
        if (IsFirstTickOfBar)
        {
            Print(Close[1]);
        }
    
        // All other code will process witch each tick
        Print(Close[0]);
    }
    IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

    Please let me know if I can be of further help.

    Comment


      #3
      Thank You.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      244 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      157 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      165 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      250 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      201 views
      0 likes
      Last Post CarlTrading  
      Working...
      X