Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting Problem - Code or software problem?

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

    Backtesting Problem - Code or software problem?

    I'm currently using Ninjatrader 7.0.0.16 to backtest a strategy.

    I'm finding that I get some very strange results when backtesting. here is a list of some of the problems:

    • For some reason the system exits the market at 16:00 (GMT) on numerous occassions for no reason. It also exits at a price that is often very different from the market price at the time of exit.
    • If I run the backtest for a different period i.e. for just a week as opposed to the entire year, I get different entry and exits.

    I can't see anything wrong with the code. Am I experiencing bugs with the software or could it be something else?

    Many thanks

    Mark

    [IMG]file:///C:/Users/user/AppData/Local/Temp/moz-screenshot.png[/IMG]

    #2
    I was consider upgrade to version beta 22 ... there were big improvements after beta 17

    Comment


      #3
      Thanks Mark...I'll give it a try.

      Comment


        #4
        MJUK10, yes you'll have to upgrade to the latest beta because there were many changes made between beta 22 and beta 16 in the backtesting area. Please let us know if the issue persists after the update - also, read the upgrade instructions carefully, there could be something specific relating to your update path.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin. I updated to the latest version and it still did not work so I rolled the code back to an ealier version where the bug wasn't present and started again.

          However, after getting it working I seem to have found another bug! All I did was insert the following code at the beginneing (initialize section) to make reference to different timeframes.


          Add(PeriodType.Minute, 60);
          Add(PeriodType.Day, 1);
          I then backtested on the same conditions to make sure there was no problem and the backtesting results were dramtically different. It should not have any affect what so ever as I havn't refered to the code yet.

          I like Ninjatrader and want to use it to trade live in due course but i'm beginning to lose faith in the software due to all these random errors. Can you give me any explanation why this might happen?

          Comment


            #6
            Mark, it will have an effect, even if just added, as the OnBarUpdate() would still be called for those timeframes as well, if you don't return out specifically or filer by the BarsInProgress, please see the SampleMultiTimeFrame or SampleMultiInstrument as examples.

            Comment


              #7
              Bertrand

              I was under the impression it they would only have an affect when the specific bararray is made reference to in the code. What you're saying if I understand it correctly is the entire code will be processed over all the called time frames? How to i stop this?

              Thanks

              Mark

              Comment


                #8
                The OnBarUpdate() is called for all added series, you can just add a print to it to see the sequence of calls - Print(Time[0] + " BIP " + BarsInProgress);

                You would need to work with if sets to only execute logic on a specific BarsInProgress being called :

                if (BarsInProgress == 0)
                {
                do calcs if OBU is called from primary series
                }

                else return; // return out if called from another BIP

                Comment


                  #9
                  so

                  I just add

                  if (BarsInProgress == 0)
                  {
                  enitre code
                  }

                  Or would I have to add BarsInProgress ==0 to each if statement?

                  I am assuming BarsinProgress 0 is equal to the default period and BarsinProgress 1 to array 1 etc etc

                  Comment


                    #10
                    Hello MJUK10,

                    You just need one BarsInProgress check, and can use multiple if statements within.

                    if (BarsInProgress == 0)
                    {
                    enitre code
                    }

                    Yes, BIP 0 is the series that the strategy is run against. BIP 1 is the first added series.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi guys. I'm still having small issues with this. Could you give some advice please? Backtestting results are still marginally different when I put the extra arrays into the code. My code is as follow:


                      protectedoverridevoid Initialize()
                      {
                      CalculateOnBarClose =
                      true;
                      Add(PeriodType.Minute,
                      60);
                      Add(PeriodType.Day,
                      1);



                      }
                      ///<summary>
                      /// Called on each bar update event (incoming tick)
                      ///</summary>
                      protectedoverridevoid OnBarUpdate()

                      {

                      if (BarsInProgress == 0)
                      {







                      PROGRAM CODE


                      }

                      }
                      }}
                      As far as I can see, this should mean the all the code within the BarsInProgress brackets should only trigger on the default timeframe? Based on this, I can't understand where the different results are coming from.

                      Comment


                        #12
                        MJUK10, can you please post the code you're using so we can test this out?
                        AustinNinjaTrader 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
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X