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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        50 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        16 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X