Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculations within current bar

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

    Calculations within current bar

    hi,

    question is:

    I make comparisons within current bar[0] and previous bar[1]. If conditions are true, then i want to execute an order in current bar[0]. In practice it makes comparisons, but at the execution it skips bar[0] and establishes position on next bar.
    I think the problem is that it makses the calculation on bar[0] close.How can I solve this issue?

    My code is:

    if (
    //HHQ3
    //HHQ3->Op<Cp->Hp-L>kv->Cp>O>op->Lp<L
    (High[1] - Low[1]) <=400 * TickSize
    && (High[1]-Low[1])>300*TickSize
    && Open[1]<Close[1]
    && (High[1]-Low[0])>100 * TickSize
    && Close[1]>Open[0]
    && Open[1]<Open[0]
    && Low[1]<Low[0])

    {
    //Enters long position: quantity 1@market
    EnterLongStop(High[1],"Target 50ticks");
    }

    #2
    Hello,

    Can you please clarify if you are running this strategy as CalculateOnBarClose = true or false?

    I look forward to assisting you further.
    MatthewNinjaTrader Product Management

    Comment


      #3
      CalculateOnBarClose = false

      Comment


        #4
        Hello,

        If you are using COBC = false, it should be processed on the current bar in real-time as soon as the condition is true.

        However please note that when backtesting using the Strategy Analyzer, your strategy will be always to calculate on bar close true.

        If you would like to backtest with Intradaybar granularity, please see our refernece sample on this topic for more information:

        Backtesting NinjaScript Strategies with an intrabar granularity
        MatthewNinjaTrader Product Management

        Comment


          #5
          Originally posted by NinjaTrader_Matthew View Post
          Hello,

          If you are using COBC = false, it should be processed on the current bar in real-time as soon as the condition is true.

          However please note that when backtesting using the Strategy Analyzer, your strategy will be always to calculate on bar close true.

          If you would like to backtest with Intradaybar granularity, please see our refernece sample on this topic for more information:

          Backtesting NinjaScript Strategies with an intrabar granularity
          This is crazy how am i supposed to know whether my strategy is profitable now??...I have written my strategies in ESignal that take trades at the open of the current bar and backtest tells me the exact entry points.....why isnt this possible on Ninja's strategy analyzer???????....lets suppose my entry at the current of the open bar is at time 12:57 on a 3 minute chart (Primary bar) what should be the duration of the secondary bar which guarantees my opening price remains the same......

          Comment


            #6
            Hello vipin_cpp,

            Welcome to the NinjaTrader Support Forums!

            The Strategy Analyzer uses Historical Data to process the Backtests and it will use the Data Series that you have the Strategy set to for example 3 Minutes. That means that NinjaTrader will run your Strategy on the Open, High, Low, Close each 3 Minute bars. It will not loading anything in between since it is Historical Data that it is set to. NinjaTrader will not change the Open but using Historical Data the Strategy will run on the Close of a bar which is basically the same event as the start of the next new bar.

            If you would like to have your orders filled within that 3 Minute bar you will just have to tell NinjaTrader to load a series that is smaller to get an Intrabar fill from the 3 Minute series. Note that you can be as granular as you like but you will still need access to that data. For example you can use a "1 Tick" series for the smallest increment or do a "1 Minute" series to have little less intensive backtest results.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, Yesterday, 10:06 AM
            0 responses
            22 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            19 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            14 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            10 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            41 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X