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

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.
    JimNinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Kaledus, Today, 01:29 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      13 responses
      45 views
      0 likes
      Last Post frankthearm  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      16 views
      0 likes
      Last Post PaulMohn  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      2 responses
      55 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by yertle, Yesterday, 08:38 AM
      8 responses
      37 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Working...
      X