Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First Attempt at Multi Timeframe

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

    First Attempt at Multi Timeframe

    Hello,

    I've been trying to code a strategy that uses a multi timeframe for the first time and have run into a problem:

    For some reason, simply adding any "Add()" to my Initialize function seems to completely change my backtesting results.

    In my OnBarUpdate(), I have

    Code:
    if(BarsInProgress > 0)
         return;
    else if (BarsInProgress == 0)
    {
         //everything else
    }
    More specifically, when my Initialize function has nothing in it but "CalculateOnBarClose = true;", the backtesting returns 13 trades. However, when I add "Add(PeriodType.Day, 1);", it reduces to 3 trades. And, "Add(PeriodType.Day, 10);" reduces it to 0 trades.

    However, if I'm understanding multi timeframes correctly, none of those Adds() should even do anything due to the "if(BarsInProgress > 0) return;" in my OnBarUpdate(), right?

    Do you see something obvious I'm doing wrong, or do you need more information and for me to post the complete code?


    By the way, is there a way to change the default Backtesting values in Strategy Analyzer, or to at least save my last used ones? Every time I start NinjaTrader and run backtesting in the Strategy Analyzer, I have to reset my session begins and ends times, account size, slippage, etc.

    Thanks for any help you can provide,

    Michael

    #2
    Hi Michael,

    What is most likely happening is that the Strategy will use the setting "Minimum Bars Required" for all bars in the series. This is 20 by default.

    This means for your 10-day bars series, it requires 200 days before the strategy will start. You're inadvertenly reducing the history available to test by using the add method here.

    Unfortunately there is no way to save backtest settings in between sessions. This is coming with NinjaTrader 7.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Great - thanks, Ryan!

      One more question: I haven't been able to get commissions to work.

      I use Ameritrade, and in Tools->Options->Commission, under Stocks - TD AMERITRADE, I set Minimum Commission to 5, with "no commission levels defined" since it's a flat fee of $5 per trade. Similarly, in Instrument Manager, under the Misc tab I set the Ameritrade commissions for the specific stock that I'm using in my backtesting.

      However, when I backtest, the Strategy Analyzer reports $0 total commission. I'm connected to Ameritrade and I've set include commission to true.

      What am I doing wrong?

      Thank you,

      Michael

      Comment


        #4
        Hi Michael,

        You will have to define a commission level. You should be able to define one level at $5 with Units at 0.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Ryan.

          I tried that and it gives an error and says the program needs to be restarted.

          I just emailed tech support with my log file.

          Thanks,

          Michael

          Comment


            #6
            Thanks, Michael. We'll continue from the email you sent to support.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Returning an MTF value

              Hi,

              Can someone tell me where I can find out more info about returning a value for an indicator in one time frame (larger) to use in a strategy for another time frame (smaller)?

              thanks

              Comment


                #8
                Hello Sjmuk,

                Please see these articles on this topic.

                Multi time frame and instruments.

                Exposing Indicator values that are not plots.
                Ryan M.NinjaTrader Customer Service

                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
                574 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X