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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        57 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X