Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Excluding Dates from Backtesting

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

    Excluding Dates from Backtesting

    Does anyone know if it is possible to include a list of days when a strategy should not trade for back-testing purposes? The reason I ask is want to exclude certain days historically from back-testing i.e. FED announcement days and some economic reports.

    Many thanks

    Mark

    #2
    Mark, yes you could for exampe exclude those days as part of your conditions (like a time / trading hours filter) -

    Comment


      #3
      Thanks Bertrand.

      How would I use these functions to exclude a list of dates though?

      Would it be possible to do something like the following:

      If today = excluded date
      then do not trade

      and then list the dates somewhere. Or would I have to write a line of code for each individual date?

      I'm conscious of the amount of dates that will be listed when I back test five or ten years worth of data.

      Thanks

      Mark

      Comment


        #4
        I believe the easiest approach should be defining for example a public method in your strategy returning just a bool where you then check for each date...something along this snippet below:

        Code:
         
        public bool OkToTradeDays()
        { 
        if (ToDay(Time[0]) == YourDateTimeAsInteger) 
        return false;
        else 
        return true;
        }

        Comment


          #5
          Thanks Bernard.

          How would this work, not entirely sure what a public bool is. Would it go before the 'OnBarUpdate()' section.

          The 'YourDateTimeAsInterger' variable, would this be a list of the dates in the varible definition list that have been given a certain integer value?

          The OktoTradeDay bool would presumably be checked before each trade is entered into, could you give me a pointer on the code for this please?

          As you might have guessed, my programming skills are still 'developing'.

          Thanks

          Mark

          Comment


            #6
            Ok, here is a simple snippet with a changed version of our per default shipped SampleMACrossOver where I integrated the check to not trade for example on last Friday, the 2nd July 2010 -

            Code:
             
            protected override void OnBarUpdate()
            {
            if (OkToTradeDay() && CrossAbove(SMA(Fast), SMA(Slow), 1))
            EnterLong();
            else if (OkToTradeDay() && CrossBelow(SMA(Fast), SMA(Slow), 1))
            EnterShort();
            }
            
            public bool OkToTradeDay()
            { 
            if (ToDay(Time[0]) == 20100702) 
            return false;
            else 
            return true;
            }

            Comment


              #7
              makes sense Bertrand.

              In the public bool do I have to repeat every single date i.e.

              public bool OkToTradeDay()
              {
              if (ToDay(Time[0]) == Date A or Date B or Date C etc)
              return false;
              else
              return true;
              }

              Comment


                #8
                Correct, you would need to supply the 'no trading allowed' dates in this method then.

                Comment


                  #9
                  Almost there Bertrand!

                  The only think i'm confused about is where does the OktoTradeDay bool go within the code?

                  If i put it within the main code within the protected override void OnBarUpdate() section it seems to cause all kinds of problems.

                  Thanks

                  Comment


                    #10
                    This is an own method and it would not go into your OnBarUpdate(), you can place it for example after it, like in my sample.

                    Comment


                      #11
                      I've got the code working now bertrand thanks.

                      However, when I put in a list of exclusion dates (as below) it throws up a
                      CS0019 error code, 'operator || cannot be applied to operands bool and int'

                      Any ideas? Thanks again.

                      public bool OkToTradeDay()
                      {
                      if (ToDay(Time[0]) == 20100701
                      || 20100106
                      || 20100113
                      || 20100121
                      || 20100127
                      || 20100203
                      || 20100210
                      || 20100218
                      || 20100225
                      || 20100303
                      || 20100310
                      || 20100317
                      || 20100324
                      || 20100331
                      || 20100407
                      || 20100414
                      || 20100421
                      || 20100428
                      || 20100505
                      || 20100512
                      || 20100519
                      || 20100526
                      || 20100603
                      || 20100609
                      || 20100616
                      || 20100623
                      || 20100630)
                      return false;
                      else
                      return true;
                      }

                      Comment


                        #12
                        This will not work unfortunately, please try a structure for example as below -

                        Code:
                         
                        publicbool OkToTradeDay()
                        { 
                        if (ToDay(Time[0]) == 20100702 || 
                           ToDay(Time[0]) == 20100703) 
                        return false;
                        else
                        return true;
                        }

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        656 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        371 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        574 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        579 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X