Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy shortly before close (1Min vs. daily data)

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

    Buy shortly before close (1Min vs. daily data)

    Hey guys,

    I am currently backtesting a strategy which generates signals on a daily basis (Calculate on Bar Close = true) and purchases on the market opening the next day. In addition, I also backtested the same strategy with 1Minute data in order to check, whether it would be better to buy already at 15:59 on the previous day (15:58 in backtest). As there is only 1 Minute left, the probability that a daily signal will be reversed within this Minute is quite low.

    However, the difference in the results of the daily and 1Minute data is much higher than I expected. As I am running out of ideas to explain this phenomenom, I wanted to ask you whether my Multitimeframe-coding for the 1Minute data is correct?! Once again, it should generate a daily signal which is generated shortly before close.
    Or do you know any issues, which may explain these differences?

    Thank you very much for your help!

    Code:
         protected override void Initialize()
            {
             Add(PeriodType.Day, 1);
             CalculateOnBarClose = false;
            }    
    
         protected override void OnBarUpdate()
            {
            // Enter Long    
                    if (ToTime(Time[0]) == 215800)       
                    && entryOrder == null                                      
                    && StochasticMod(BarsArray[1],5, 9).D[0] < 30)    
    
                    {
                      entryOrder = EnterLong(OrderQuantity,"Long");
                    }
    
    
             // Exit Long 1
                     if (ToTime(Time[0]) == 215800)
                     && StochasticMod(BarsArray[1],5, 9).D[0] > 70
                                
                     {
                      ExitLong();
                     }
    
    }

    #2
    Hello,

    I'm not 100% clear on exactly what is going wrong with the strategy. Can you please clarify exactly what is expected to happen, and what is actually happening? Or the exact difference that is showing up between live deployment and backtesting?

    Are you finding that your strategy is missing trades entirely? If this is the case, I recommend checking for a small range of time, rather than an exact minute, just in case there is not a call to OnBarUpdate() in that specific minute. This should not be an issue with a popular, high-volume instrument, but it could certainly come into play if you are trading a very low-volume instrument.

    I look forward to your reply.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hey Dave,

      thanks for your quick reply. The problem is, that the performance and amount of trades is quite differenent. 19200 trades (daily data) vs. 17700 (minute data) is too high from my expectation. In the meantime, I figured out that the price data seems to be different, which may explain the arising discrepancy and different signals (see screenshot).

      I just wanted to make sure: Is my posted code correct that it generates a DAILY signal based Minute data already on 21:58 at the current day instead of waiting for daily close and trading the next day?
      Attached Files

      Comment


        #4
        Yes, your code looks like it accomplishes what you are looking for. The only piece of advice I would add is that you might consider encapsulating all of your logic within a BarsInProgress check, to ensure that the conditions are only being checked when a specific data series (the primary or the one you've added) is calling OnBarUpdate(). For example, if you wish to only place those orders (on the minute bars) within an OnBarUpdate() called by the higher-timeframe bars, then you could place all of your logic within "if (BarsInProgress == 0) {}.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          ok thanks Dave for the tip

          Just to make sure that I understand "BarsInProgress == 0" correctly:

          In my example, my code may generate signals only on the previous day at 21:58 (On Bar Update of the 1Min). However, at Close at 22:00 the daily series triggers the "On Bar Update", so It checks the conditions once again at market opening of the next day. However, due to the "if (ToTime(Time[0]) == 215800)" restriction, the daily data series will never be able to cause a signal, correct?

          Again thanks for your answer!

          Comment


            #6
            Yes, that would be the case. On daily bars, BarsInProgress == 0 should never be true at that exact time, so perhaps that would not be the right approach. You would want to filter for BarsInProgress == 1 to make sure that you are testing conditions on the smaller timeframe.
            Dave I.NinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 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