Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limiting results on a backtest

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

    Limiting results on a backtest

    I have a strategy that requires four days of data (Ex. June 1st - June 4th) to be loaded for the strategy to work as designed. I get some errant results from earlier days that I want to avoid.

    Is there code that I can include in the strategy that will only show results on the most recent day (June 4th) of backtesting? Can this code remain in a live trading strategy and not effect the outcome?

    Thanks.
    Last edited by ArmKnuckle; 07-20-2016, 11:54 PM.

    #2
    Hello,

    Thank you for the question.

    I am unsure of the full extent of the scripts logic, but could a From and To time work in this case?

    I.E. you could add two inputs to the strategy to enter in two dates, or a from and to time. This could be used in the logic to prevent the strategy from running except for between these dates. Can you confirm if something like this would be of use? If so I could provide a simple example of that.

    You can certainly add more logic to the script and give that logic conditions in which control if it is used or not, so adding an item specific for backtesting is certainly possible.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      "To and From" sounds like it would work well, but I am hoping to not have to type in new dates every time I want to backtest from a different part of the calendar. That will a never ending re-coding and compiling scenario.

      I am trying to find a way around a perceived shortcoming on the Strategy Analyzer. Only seeing results from the day(s) you want. (This is big problem when backtesting hundreds of stocks.)

      As stated in a previous post:
      Basically, my strategy requires a look back analysis of 3 trading days of data get results for the final fourth day. (390 min./day)

      That does make sense, but I end up with results for more than just the one trading day that I am looking for.

      It would be very helpful if there were separate settings under "Time Frame" for days of data needed to load, and the day(s) of trade results that you want to see.

      I would like to submit a formal request to have day(s) of trade results that you want to see added to NT8.

      In the mean time, I am hoping to find a way to restrict backtesting results to the most recent day loaded without typing a date in the code before every backtest.

      (Please disregard the need to keep any new code that you provide in a live trading strategy. Backtesting is my main focus, at this point.)
      Last edited by ArmKnuckle; 07-21-2016, 12:57 PM.

      Comment


        #4
        Originally posted by ArmKnuckle View Post
        "To and From" sounds like it would work well, but I am hoping to not have to type in new dates every time I want to backtest from a different part of the calendar. That will a never ending re-coding and compiling scenario.

        I am trying to find a way around a perceived shortcoming on the Strategy Analyzer. Only seeing results from the day(s) you want. (This is big problem when backtesting hundreds of stocks.)

        As stated in a previous post:
        Basically, my strategy requires a look back analysis of 3 trading days of data get results for the final fourth day. (390 min./day)

        That does make sense, but I end up with results for more than just the one trading day that I am looking for.

        It would be very helpful if there were separate settings under "Time Frame" for days of data needed to load, and the day(s) of trade results that you want to see.

        I would like to submit a formal request to have day(s) of trade results that you want to see added to NT8.

        In the mean time, I am hoping to find a way to restrict backtesting results to the most recent day loaded without typing a date in the code before every backtest.

        (Please disregard the need to keep any new code that you provide in a live trading strategy. Backtesting is my main focus, at this point.)
        You can programmatically read the last test date, and use a filter on orders that will only take orders on that date. IOW, it will calculate all trades, but not actually take any order unless the date is the same as the date of interest.

        Comment


          #5
          Any input on how to programmatically acquire the last test date and use it to trade in the strategy would be greatly appreciated.

          Thanks!

          Comment


            #6
            Originally posted by ArmKnuckle View Post
            Any input on how to programmatically acquire the last test date and use it to trade in the strategy would be greatly appreciated.

            Thanks!
            I am not on front of my test system now, but generally speaking the number of bars we query is Count - 2, so try Print()ing this to the output window and see what you get.
            Code:
            if (CurrentBar == Count - 2) Print("Date on bar: " + Time[0].Date);
            Then see if it matches the last date you are testing. For sure that is true on a chart, but I have never tested it in the Strategy Analyzer. I might just take a look when I get back in front of a system. Kindly let me know if that gives you traction.

            There are some undocumented methods to get that information, but I would have to look it up in my notes, if I can find it, and I am generally leery of teaching undocumented stuff.

            Comment


              #7
              Thanks. I will try that once trading closes today.

              If it does Print() the most recent date, my next question how to stop Strategy Analyzer from reporting trades from the days before that date.

              Comment


                #8
                Originally posted by ArmKnuckle View Post
                Thanks. I will try that once trading closes today.

                If it does Print() the most recent date, my next question how to stop Strategy Analyzer from reporting trades from the days before that date.
                Use it as a filter to not take the trades. Strategy Analyzer will only report trades taken.

                Comment


                  #9
                  Originally posted by ArmKnuckle View Post
                  Thanks. I will try that once trading closes today.

                  If it does Print() the most recent date, my next question how to stop Strategy Analyzer from reporting trades from the days before that date.
                  Actually that code does not quite work, as it would require a complete pass through the bars to get (CurrentBar == Count - 2)

                  Try this instead to get the date of the last bar on the chart.
                  Code:
                  BarsArray[0].GetTime(Count - 2).Date;
                  Here is how you would use it.
                  Code:
                  			bool LastDayOnChart = (Time[0].Date == BarsArray[0].GetTime(Count - 2).Date) ? true : false;
                  			if (LastDayOnChart /*&& other entry conditions here*/)
                  			{
                  				//Enter trade
                  			}
                  You could also use:
                  Code:
                  BarsArray[0].BarsData.To
                  Both are undocumented. Be advised accordingly.

                  This code should show you in the Output Window:
                  Code:
                  			Print("LastDateOnChart: " + BarsArray[0].GetTime(Count - 2).Date);
                  			Print("LastDateOnChart: " + BarsArray[0].BarsData.To);
                  Last edited by koganam; 07-25-2016, 12:06 AM.

                  Comment


                    #10
                    Thanks for doing all of that coding!

                    I will give this a shot.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    11 responses
                    1,421 views
                    0 likes
                    Last Post jculp
                    by jculp
                     
                    Started by RubenCazorla, Today, 09:07 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post RubenCazorla  
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    29 views
                    1 like
                    Last Post BarzTrading  
                    Started by devatechnologies, 04-14-2024, 02:58 PM
                    3 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by tkaboris, Today, 08:01 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post tkaboris  
                    Working...
                    X