Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar Question

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

    CurrentBar Question

    Hi

    I have a strategy where an entry condition occurs and if a secondary condition occurs within 3 bars of the first condition then the trade should be entered.

    On the first condition I set a variable, triggerBar, equal to CurrentBar. To check it's OK to enter on the second condition I have:

    if (CurrentBar - triggerBar < 4)
    then do something...

    This works fine on historical data but I had an instance on Friday whilst live trading where the trade was entered even though my triggerBar occurred 5 bars ago.

    So my question is, does CurrentBar refer to the currently forming bar or the last completed bar? I notice from NT Help that CurrentBar value is guaranteed to be <= Count - 1.

    The strategy was running on a one minute timeframe.

    #2
    Hi FatCanary,

    This depends on your CalculateOnBarClose setting...

    with COBC = true, CurrentBar refers to the last completed bar.

    with COBC = false, CurrentBar refers to the bar currently being formed.
    TimNinjaTrader Customer Service

    Comment


      #3
      Thanks Tim.

      COBC == false.

      So would you have any idea as to why the trade would have entered beyond my 3 bar limit and why is CurrentBar always < Count?

      Comment


        #4
        Hi FatCanary,

        Count is number representing the total number of bars, so if there are 100 bars, Count == 100 for last bar.

        CurrentBar labels the first bar "0" then increases, so if there are 100 bars, CurrentBar == 99 for last bar.

        More info at - http://www.ninjatrader-support.com/H...ide.html?Count

        and - http://www.ninjatrader-support.com/H...tml?CurrentBar

        As for your entry, I suggest using Print() statement to check when the tiggerbar is being set, and that it is not being changed.

        You can also use TraceOrders to check how your orders are being submitted and filled.

        More info at - http://www.ninjatrader-support2.com/...ead.php?t=3418
        TimNinjaTrader Customer Service

        Comment


          #5
          Thanks for the help Tim.

          Comment


            #6
            Hi Tim,
            I want to backtest strategy on day bars to buy on open + some part of ATR of previous days. When I place COBC = false, then Open[0] is open of actual tradet bar and High[0], Low[0] and Close[0] are not available?

            Comment


              #7
              smkal, CalculateOnBarClose is always set to 'true' in backtesting, if you want to backtest intrabar daily chart fills, please see this sample here -

              You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by

              Comment


                #8
                Thanks, but this doesnt help me much. I have 15 years of day data, but only year of minute. I'm not interested in intraday graphs at all. I know, that open price is first and I want to place order at open price + part of ATR (for long entry). When stop loss is higher than low of day => loss. When my entry price is lower than close => the day finish with profit. When my entry price is higer than high => the day has no entry. Can I backtest this strategy in NT with day data only?

                Comment


                  #9
                  Hello,

                  I do not understand your question for the most part. Yes, if you have daily data you can backtest over daily data. You cannot "fill" at a certain price unless it is available in the backtester.
                  DenNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Ben View Post
                    Hello,

                    I do not understand your question for the most part. Yes, if you have daily data you can backtest over daily data. You cannot "fill" at a certain price unless it is available in the backtester.
                    So in NT there is no way how to get Open price of actual day in backtest? How can I for example backtest the condition:
                    If today open is below yesterday close, then buy on this open price.

                    Comment


                      #11
                      Hi smkal,

                      You could certainly do this, with something like....

                      if (Open[0] < Close[1])
                      {
                      enter at Open[0]
                      }

                      However, with daily data only, the condition would not be fulfilled until the end of current day, then submitted on the next bar.
                      TimNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      647 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      369 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      108 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      572 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      573 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X