Announcement

Collapse
No announcement yet.

Different Code for Discrete Time Periods

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

  • Different Code for Discrete Time Periods

    Hi,

    I am aware that it is not possible to backtest over a discrete period in history (e.g. 2000-2001) with the performance analyzer.

    I thus wish to amend my script so that if the date is before a certain date, one set of coding is used, but if it is after a certain date, another piece of code is used. In this way, I am hoping to apply different coding to different phases of the market's life, and use the backtest analyser over the whole period.

    Is it possible to do this?

    Thanks in advance.

    Deax.

  • #2
    Deax
    See the efs in this post as an example of limiting trades to a user defined period
    Alex

    Comment


    • #3
      Alex,

      What can I say - Fantastic! Thank you very much!

      Deax.

      Comment


      • #4
        Alex,

        I have now tried what you posted, but it isn't quite what I want.

        Is it possible to use a date type function to restrict one set of code to operate within a certain period of time, and another set of code to operate at another time. I was thinking of something like:

        Whilst time is > x && < y { insert code }

        Whilst time is >y and < z {insert code }

        Is that possible ?

        Many thanks

        Deax.

        Comment


        • #5
          Deax
          It should be possible by modifying slightly the efs I suggested (see example below). Replace the colors commands with some flags and then reference those flags in your conditions.
          Alex

          PHP Code:
          function preMain(){
              
          setStudyTitle("test conditions");
              
          setPriceStudy(true);
              
          setShowCursorLabel(false);
          }

          function 
          main(){

          var 
          vTrade 1;
          var 
          vYear,vMonth,vDay;

              
          vYear=getYear(0,-1)+"";
              
          vMonth=getMonth()+"";
                  if(
          vMonth<10)
                      
          vMonth 0+vMonth;
              
          vDay getDay()+"";
                  if(
          vDay<10)
                      
          vDay 0+vDay;

              if(
          vYear+vMonth+vDay>20041001&&vYear+vMonth+vDay<=20041231){
                  
          setBarBgColor(Color.lime);
              }
              if(
          vYear+vMonth+vDay>20041231){
                  
          setBarBgColor(Color.yellow);
              }
              if(
          vYear+vMonth+vDay<=20041001){
                  
          setBarBgColor(Color.cyan);
              }

              return;

          Comment


          • #6
            Alex,

            That's absolutely perfect. Many thanks.

            Deax.

            Comment

            Working...
            X