Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference Between Calculate on Close and On Incoming Tick

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

    Difference Between Calculate on Close and On Incoming Tick

    I have had some unexpected behaviour when trading live and I think it could be due to not calculating on bar close when trading live as opposed to caluating on bar close when backtesting. My problem relates to an exit condition.

    What is supposed to happen is if the price exceeds the high of the previous bar (when short) plus the ATR, the position closes.

    It works as expected on backtesting but as it is calculating live and not on the close of the bar should "High[1]" still be [1] ? Or should it be High [0]?

    Thanks

    Mark


    if (GetCurrentAsk() > High[1] + (ATR(14)[0])
    && Avalue ==
    2)

    {
    ExitShort();
    PrintWithTimeStamp(
    "Exit Short ATR");
    }

    #2
    Hi Mark,

    High[0] when CalculateOnBarClose = true in real time refers to the most recent closed bar. This will be one bar prior to the bar that's currently forming.

    For help with bar referencing issues, I suggest to get familiar with CurrentBar. It will indicate the bar index and can be printed or plotted. It's helpful for putting a reference to the values you access.

    Print(CurrentBar + " " + High[0]);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan - what about when CalculateOnBarClose = False?

      Comment


        #4
        If COBC = false and real time, then High[0] is the high of the bar that's currently forming.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        65 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Working...
        X