Announcement

Collapse
No announcement yet.

Backtesting Gap Strategy Not Working - based on Esignal Sample

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

  • Backtesting Gap Strategy Not Working - based on Esignal Sample

    I have written a strategy for backtesting an intraday entry at market open - using the previous days close at 4:15

    1. askForInput() is shown in the examples as to be placed under the premain function - if placed there it does nothing - it has to be placed before the premain function to be activated on attaching the strategy to the chart.

    2, setPriceStudy(true) - should plot in the main price window but mine plots in a seperate window underneath - well it doesn't plot it just says Loading Data...

    3. the premain statements such as setPriceStudy etc. colour bright blue when typed correctly - I have setColorPriceBars and setDefaultPriceBarColor but these dont color blue making me think they are incorrect but I can't see why.

    4. The function parameter setLowerLimit and setUpperLimit don't work - when you enter numbers that exceed the limits they are accepted. The setName is supposed to give a meaningful title in the settings dialogue box isn't it - my dialogue boxes show the variable name in the FunctionParameter line and ignore the set name command.

    5. What is the effect of putting the FunctionParameter names in the main() function arguments? I thought the variables did not need to be restated if called from FunctionParameter and included in the function Main argumetns but kept receiving error messages saying one of teh functions not defined. I checked the spelling then reversed the order of the argumetns and the error went away - when resetting them back to the old order the error did not come back - it was not a spelling error.

    6. the debugPrintln lines at line 55 and 56 don't return any information - not sure if they are supposed to.

    Anyway I can't get any output from the script so if anyone can help it would be great.

    Thanks
    Attached Files
    Honesty and Valour - where did they go?

  • #2
    SlipperX
    The first thing you will want to resolve in the efs you posted is a reference error in line 155 and a syntax error in line 17. Following are some answers to your questions
    1. Not sure which examples show that askForInput() should be below preMain(). The Help file (which can be accessed from within the Editor) and the EFS KnowledgeBase indicate that it can be called from preMain() or main(). If you look at any of the formulas in the EFS2 Custom folder you will see that it is always included in preMain().
    2. This is happening because you have written premain() instead of preMain() in line 14.
    3. Some statements and commands do not color in blue only because an internal file that colors those keywords has not been updated yet. This does not mean that they are incorrect.
    4. Both these issues are due to the same reason explained in point 2.
    5. I am not positive but I think this was done for backwards compatibility when the function parameters were subsequently added to EFS. Someone from eSignal will be better able to provide the exact reason.
    6. There are no debugPrintln statements in lines 55 and 56. There is one in line 59 and as far as I can see it is returning information to the Output window. You may want to add a string to each debugPrintln statement indicating which line of the script it is returning.
    I would also suggest that you spend some time reviewing the EFS KnowledgeBase and in particular the Help Guides section.
    Alex

    Comment


    • #3
      Hi Alex

      Thanks for your quick reply - how dumb was that - I looked at that codde for hours and just didn't see it. I have spent a lot of time looking at the EFS help files and know I need to spend more time but the problems aren't always ovbious nor are the places to look for the solutions.

      I guess I would have expected the syntax error with preMain() to have been picked up by the debugger but anyway.

      Having resolved that problem the EFS plots in the right window but the trades never trigger. I wonder if this is to do with this section of code in lines 49 to 68 which I copied from one of the help files and is supposed to check if the current bar is the first bar of the day. The system never takes any trades so I think maybe this code isn't working properly.

      If I ever get this working I want to also condition entries on pre-market cumulative volume on several stocks at a set time before the open - can I do this using the inv() function?

      Very grateful for your help and sorry I had such a dumb error last time

      slipperx
      Attached Files
      Honesty and Valour - where did they go?

      Comment


      • #4
        Slipperx

        I guess I would have expected the syntax error with preMain() to have been picked up by the debugger

        FWIW it is not a syntax error because a) you may not want a preMain() function in the efs and b) you could instead have a user function called premain() (see example below which is perfectly valid)

        PHP Code:
        function main(){
            var 
        test premain();    
            return 
        test;
        }

        function 
        premain(){
            return (
        high()+low())/2;

        Probably a simpler way to achieve what you want is to use a Time Template set to 9:30-16:15 ET (or equivalent if in a different time zone) and just use

        PHP Code:
        if(getDay(0)!=getDay(-1)&&getBarState()==BARSTATE_NEWBAR){
            
        PriorClose close(-1);
            
        CurrentOpen open(0);

        to define the prior day's Close and the current day's Open. You can then use these values in your calculations
        Alex

        Comment


        • #5
          Hi Alex

          Thanks for that but... If I use a time template for the backtest and the efs study will I not have a problem when I try to get the cumulative volume for the pre-market sample stocks - what I mean is for instance look at the cumulative volume in say AMAT at 9:25am to decide if the trade that might trigger on the gap in the futures will be taken or not - to do that I would need to reference the efs to look at outside the current time template. Is that possible?
          slipperx
          Honesty and Valour - where did they go?

          Comment


          • #6
            Hi again

            I set up teh time template as suggested. Why does the template show different data depending on the time interval. For instance looking at ES #F=2 or ES U5 (both the same) on a 1 minute to 30 minute chart gives you a closing price today of 1225 but the closing charts of 60 minute and daily give a price of 1226.50 1.5 points different - thats a huge difference and why is there any difference. How would you know what time period the Back Tester is using if you implement the formula you have below?

            Thanks
            slipperx
            Honesty and Valour - where did they go?

            Comment


            • #7
              Slipperx
              Regardless of the Time Template I don't think you would be able to track the cumulative volume of an external symbol before 9:30 if you are charting ES #F=2 since the latter begins plotting only at 9:30. You would need to chart ES #F with the Time Template set to 8:00-16:15. Then instead of using getDay(0)!=getDay(-1) you could use the EFS2 equivalents as shown in the sample code below (make sure the Time Template loads at least 2 days of data)

              PHP Code:
              if(day(0,sym("es #f=2"))!=day(-1,sym("es #f=2"))){
                      
              vClose close(-1,sym("es #f=2"));
                      
              vOpen open(0,sym("es #f=2"));
                      
              debugPrintln("Prior Close ES #f=2 "+vClose+" Current Open ES #F=2 "+vOpen);
                  } 
              In the following chart you can see I am running ES #F with a Time Template set to 8:00-16:15 but the values returned to the output window by the sample code are those of the prior day's Close and current day's Open of ES #F=2



              With regards to the question in your other message see this post for an explanation
              Alex

              Comment

              Working...
              X