Announcement

Collapse
No announcement yet.

controlling trading times in a backtesting strategy

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

  • controlling trading times in a backtesting strategy

    Hi everyone,

    I have finally managed to get my first real trading strategy working as an efs file. I have one issue that I cannot get my head round, and that is how to program what constitutes a trading day.

    I.E. being able to set which hours of the day trades can occur. I want to limit the backtesting to certain hours of the day, and I cannot get it to work.

    Does anyone have any examples of how to force backtesting trades to only occur between certain times (9-30am untill 3-30pm for instance)

    any help would be appreciated.

    thanks

  • #2
    function main(maxgain, maxloss, size, OpenTime, LunchStart, LunchEnd, CloseTime, trigger) {
    getTime(); //check time
    if(cBarTimeInt < LunchStart && cBarTimeInt > OpenTime ){ market = "open"; cancel = "false"; }//morning session
    if(cBarTimeInt < CloseTime && cBarTimeInt > LunchEnd ){ market = "open"; cancel = "false"; }//afternoon session
    if(cBarTimeInt > LunchStart && cBarTimeInt < LunchEnd ){ market = "lunch"; cancel = "false"; }//lunch hour
    if(cBarTimeInt > CloseTime || cBarTimeInt < OpenTime ){ market = "closed"; }//overnight session

    function getTime(){today = new Date; cBarTimeInt = today.getHours()*100 + today.getMinutes()*1; return;}

    function preMain() { debugClear();
    var fp1 = new FunctionParameter("maxgain", FunctionParameter.NUMBER); var fp2 = new FunctionParameter("maxloss", FunctionParameter.NUMBER);
    var fp3 = new FunctionParameter("size", FunctionParameter.NUMBER); var fp4 = new FunctionParameter("OpenTime", FunctionParameter.NUMBER);
    var fp5 = new FunctionParameter("LunchStart", FunctionParameter.NUMBER); var fp6 = new FunctionParameter("LunchEnd", FunctionParameter.NUMBER);
    var fp7 = new FunctionParameter("CloseTime", FunctionParameter.NUMBER); var fp8 = new FunctionParameter("trigger", FunctionParameter.NUMBER);
    fp1.setDefault(9); fp2.setDefault(9); fp3.setDefault(1); fp4.setDefault(800);
    fp5.setDefault(1100); fp6.setDefault(1400); fp7.setDefault(1610); fp8.setDefault(20);

    Comment


    • #3
      Many thanks for this David.

      I have looked at this, and can not get it to work. Do you have a simple EFS file with this in that functions, that I could use as an example?

      something that just prints the time to the debug window would do.

      many thanks in advance

      TJ

      Comment


      • #4
        function main()
        today = new Date;
        cBarTimeInt = today.getHours()*100 + today.getMinutes()*1;
        debugPrintln("Right now it is "+cBarTimeInt);
        return;
        }

        Comment

        Working...
        X