Announcement

Collapse
No announcement yet.

Question about backtesting results using multiple time intervals

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

  • Question about backtesting results using multiple time intervals

    Hi Guy's hope all is well.

    I'm aware of the well documented techniques to eliminate the forward looking issues when back testing on a chart using a 5 minute time chart for example that also accesses larger time periods for signal generation.

    I was wondering if I test on a 60 minute chart for example and also access 30 or lower time interval indicators are any specific coding techniques required to insure more realistic results?

    I realize that the entry price for market orders will be recorded at the open of the next 60 minute bar, but does the backtester when referencing a shorter time interval actually "open" and generate the price and indicator data values of those shorter time intervals?

    Thanks very much.

    Glen
    Glen Demarco
    [email protected]

  • #2
    Hello Glen,

    Back testing formulas that look at multiple intervals should be run on the lowest interval chart used by the strategy and look up to the higher intervals for signal evaluation.

    Remember that in back testing, each historical bar is only processed once. If you run your formula on a 60 min chart, you will get one formula execution for each bar. You can use series based on intervals lower than 60, but you will only see the last data point for the lower series for each 60 minute window.

    Run the following on a 60 minute chart and compare the returned data points for the two series.

    PHP Code:
    var bInit false;
    var 
    x1 null;

    function 
    main() {
        if (
    bInit == false) {
            
    x1 close(inv("1"));
            
    bInit true;
        }

        
    debugPrintln(getCurrentBarIndex() + "  " x1.getValue(0));
        return new Array(
    close(0), x1.getValue(0));

    This makes the lower interval series basically the same as the 60 min series. I'm not sure how this would be utilized for back testing purposes. However, results can vary depending on what series are used. If you describe more specifically how you are trying to use the lower interval series on the 60 minute chart I may be able to provide some more specific guidance.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Originally posted by JasonK
      Hello Glen,

      Back testing formulas that look at multiple intervals should be run on the lowest interval chart used by the strategy and look up to the higher intervals for signal evaluation.

      Remember that in back testing, each historical bar is only processed once. If you run your formula on a 60 min chart, you will get one formula execution for each bar. You can use series based on intervals lower than 60, but you will only see the last data point for the lower series for each 60 minute window.

      Run the following on a 60 minute chart and compare the returned data points for the two series.

      PHP Code:
      var bInit false;
      var 
      x1 null;

      function 
      main() {
          if (
      bInit == false) {
              
      x1 close(inv("1"));
              
      bInit true;
          }

          
      debugPrintln(getCurrentBarIndex() + "  " x1.getValue(0));
          return new Array(
      close(0), x1.getValue(0));

      This makes the lower interval series basically the same as the 60 min series. I'm not sure how this would be utilized for back testing purposes. However, results can vary depending on what series are used. If you describe more specifically how you are trying to use the lower interval series on the 60 minute chart I may be able to provide some more specific guidance.
      Hi Jason,

      Thanks very much for the reply and the cdoe you provided it was very helpful. I see what you mean about returning the same value for "close" for both the 1 and 60 minute time periods.

      I altered the code as I was interested in what was returned for indicator values on hgher and lower time periods then the chart time period:
      PHP Code:
      var bInit false;
      var 
      x1 null;
      var 
      x2 null;
      var 
      x3 null;
      var 
      x4 null;

      function 
      main() {
          if (
      bInit == false) {
              
      x1 pdi(14,14,inv("30"));
              
      x2 pdi(14,14,inv("60"));
              
      x3 pdi(14,14,inv("120"));
              
      x4 pdi(14,14,inv("D"));
              
              
      bInit true;
          }

          
      debugPrintln(getCurrentBarIndex() + "  " x1.getValue(0)+ "  " x2.getValue(0)+ "  " x3.getValue(0)+ "  " x4.getValue(0));
          return new Array(
      x1.getValue(0), x2.getValue(0), x3.getValue(0), x4.getValue(0));

      What I'm am trying to do is simply when I get a signal on a 60 minute for example, to first check a higher and or lower indicator value essentially looking for confirmation of a "trend".

      The strange thing is that however "logical" that seems all my strategies do worse when I do that. Perhaps it's strategy or instrument dependent, or else my logic is flawed.

      I wanted to determine if there was any value to checking a lower time interval indicator along with or instead of the higher.

      I realize as you mentioned that the trade trigger and value returned for the shorter would only be returned on the close of the 60 minute bar but that may not be an issue.

      I need to spend more time tinkering with the example you generously provided and think this through further.

      As always thank you very much for the assistance.

      Glen
      Glen Demarco
      [email protected]

      Comment


      • #4
        Hello Glen,

        Originally posted by demarcog
        Hi Jason,

        Thanks very much for the reply and the cdoe you provided it was very helpful. I see what you mean about returning the same value for "close" for both the 1 and 60 minute time periods.

        I altered the code as I was interested in what was returned for indicator values on hgher and lower time periods then the chart time period:
        PHP Code:
        var bInit false;
        var 
        x1 null;
        var 
        x2 null;
        var 
        x3 null;
        var 
        x4 null;

        function 
        main() {
            if (
        bInit == false) {
                
        x1 pdi(14,14,inv("30"));
                
        x2 pdi(14,14,inv("60"));
                
        x3 pdi(14,14,inv("120"));
                
        x4 pdi(14,14,inv("D"));
                
                
        bInit true;
            }

            
        debugPrintln(getCurrentBarIndex() + "  " x1.getValue(0)+ "  " x2.getValue(0)+ "  " x3.getValue(0)+ "  " x4.getValue(0));
            return new Array(
        x1.getValue(0), x2.getValue(0), x3.getValue(0), x4.getValue(0));

        What I'm am trying to do is simply when I get a signal on a 60 minute for example, to first check a higher and or lower indicator value essentially looking for confirmation of a "trend".
        I would suggest for simplicity of code logic that you write your formula to the lowest interval you are using in your strategy. In this case, 30 min. To evaluate your signals every 60 minutes, look for the new bar state of the 60 min interval with getBarStateInteval("60"). At that instance, which is the open of the new 30 min and 60 min bar, then evaluate all the interval conditions of their most recently completed bars for confirmation. You'll be running the formula on a 30 minute chart, but the signals will still be evaluated once every 60 minutes. Because the conditions are looking at the recently completed bar data (i.e. bar index of -1) you can record trades at the open of the current bar in the strategy calls with Strategy.MARKET/Strategy.THISBAR constants.

        The strange thing is that however "logical" that seems all my strategies do worse when I do that. Perhaps it's strategy or instrument dependent, or else my logic is flawed.
        Post a complete formula example and I'll take a look.

        I wanted to determine if there was any value to checking a lower time interval indicator along with or instead of the higher.

        I realize as you mentioned that the trade trigger and value returned for the shorter would only be returned on the close of the 60 minute bar but that may not be an issue.

        I need to spend more time tinkering with the example you generously provided and think this through further.

        As always thank you very much for the assistance.

        Glen
        The way I think about this is just simply the fact that multiple intervals are being considered. I think you're complicating this a bit by thinking of the strategy running on a 60 min chart and looking to "lower" and "higher" intervals for confirmation. Evaluating signals every 2 bars on a 30 min chart will generate basically the same results as evaluating every 1 bar on a 60 min chart. Writing the formula logic for the 30 min bars should make this easier for you.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Originally posted by JasonK
          Hello Glen,

          Post a complete formula example and I'll take a look.

          Jason,

          Understood, thanks for the assistance. Here is a simplified version as the actual strategy is using a function library for alot of the common strategy management functions.

          This is a basic MA crossover strategy that goes long when the 5 is above the 20 and visa versa using the built in OSC study.

          Now what's interesting is that intuition is such that for example if you take every signal using only a 60 minute time interval you would expect that the profitability would increase if the 5 is above the 20 on a longer term interval, indicating bigger picture uptrend? This is the generally accepted methodology for discretionary trading, check the daily first, etc.

          My logic may be flawed but so far every strategy I've tried on a per trade basis usually does better using only a single time interval and adding additional "longer term" intervals adds no value which is really puzzling.

          What prompted my original question was I wanted to research whether or not adding a shorter term interval for the same indicator signal would improve the performace?

          My next step would be to see if using different signals on each specific time interval would be useful.

          I realize that this is an oversimplified example. But needed to start somewhere to answer the questions about the effect of adding multiple intervals on profitability.

          If you look at the code there is one problem, for some reasons I couldn't figure out, when I pass 3 different numeric values for the time intervals for function parameters Int1 Int2 and Int3 the strategy generates trades. But when I use the same interval for each I get no trades.

          So If you want to run this first for 1 interval as I did you need to
          edit lines 434 445 to only check the relavent intervals.
          I ran it on GBP A0-FX.

          I really appreciate any comments or suggestion, thanks very much.

          Glen
          Attached Files
          Glen Demarco
          [email protected]

          Comment


          • #6
            Hello Glen,

            Originally posted by demarcog
            ....

            If you look at the code there is one problem, for some reasons I couldn't figure out, when I pass 3 different numeric values for the time intervals for function parameters Int1 Int2 and Int3 the strategy generates trades. But when I use the same interval for each I get no trades.

            So If you want to run this first for 1 interval as I did you need to
            edit lines 434 445 to only check the relavant intervals.
            I ran it on GBP A0-FX.

            I really appreciate any comments or suggestion, thanks very much.

            Glen
            I can't provide advice on how to accomplish profitability. This is beyond the scope of EFS support.

            Regarding the code you've provided, the problem with setting all the intervals to the same one has to do with the getBarStateInterval() function problem we ran into before in this thread. In short, we can't make multiple calls with this function on the same interval. This seems like a bug to me. I'm going to enter a bug report for this one and see if we can't get the functionality behind this function call modified to allow this. It seems logical that we should be able to make that call multiple times regardless of the interval passed.

            Modifying the conditions on lines 434 and 435 to work around the getBarStateInterval() problem does allow many trades to be recorded (over 400 on 20 days of 5 min data) when using the same interval for all three. However, when testing the same time period with the multiple interval signals, only 2 trades were generated. This occurs because the number of times the new bar state occurs for the highest interval in the strategy severely restricts the number of times the trade signals can be evaluated. What you are doing is not necessarily wrong, it's just the reality of the particular strategy of this formula. For this particular formula, I would suggest testing over the maximum amount of data possible to get the best comparison possible. However, with an interval of 720 you will still be limiting the number of possible trades to occur relative to a 5 min interval. You may want to consider lowering that interval to allow more possible trade signals to be evaluated.
            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Jason,

              Thanks for the reply.

              Sorry about that I didn't immediately realize it was the same issue
              I ran across in another EFS. Thanks for pursuing it with development.

              I realize that profitability is beyond the scope of EFS support I tried posting in the past for anyone interested in the topic and interesting enough there was little if any interest.

              The issue for me and I'm sure many others at this point is to apply what you and others have generously taught toward profitable strategy development which is a major "challenge".

              If you can recommend any sources, books, file shares etc., which can be used educationally to assist in this process it would be greatly appreciated?

              Thanks Again,

              Glen
              Glen Demarco
              [email protected]

              Comment

              Working...
              X