Announcement

Collapse
No announcement yet.

Backtesting and bartime

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

  • Backtesting and bartime

    Hi

    I have this sample script and would like to test the bartime on it, however it has a error saying bartime could not be found. I have copied script excerpt of another post here.

    Thanks
    Attached Files

  • #2
    biswar
    In line 28 BarTime is written differently than in line 7 (bartime) where you define the variable.
    Also you need to define var getH = 0; and var getMin = 0; else you will get other syntax errors.
    The above changes should fix those errors. Have not checked the functionality of the efs itself
    Alex

    Comment


    • #3
      Hello biswar,

      Looks like you have an end brace (i.e. "}") that is out of order. Move the end brace on the line following BarTime=getH*100+getMin; to the end of main. That should help get you started.
      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


      • #4
        hi

        Im not sure if this is what i want, what im after is to be able to look at the bartime, even if its in the past so it can be used in backtesting. is there way to do this,

        so if the actual bar is between a time say 8am and 9pm then then do a action. not sure if this is possible it would be mean looking at each bar stamp as the global cursor would

        any help appreciated

        Comment


        • #5
          what im after is to be able to look at the bartime, even if its in the past so it can be used in backtesting
          here is how I check time in my backtest code
          PHP Code:
          //global variables
          //ok2Trade = true;
          //var sStartTime = 930;
          //var sEndTime = 1555;
               

              
          sCurrentTime = (getHour()*100)+getMinute();
              if (
          sCurrentTime >= sStartTime && sCurrentTime sEndTime){
                  
          ok2Trade true;
                  
          sPreviousTime sCurrentTime;
              }
              
              
          //-----------------------  exit any open trades at end of trading hours  ----------------
              
          if (sPreviousTime sEndTime && sCurrentTime >= sEndTime){
                  
          ok2Trade false;
                  
          sPreviousTime sCurrentTime;
                  if (
          Strategy.isShort() == true){
                  
              
          etc....
              }
              
              if (
          ok2Trade){
              
              
          //apply your trade logic here
              
              

          I use sPreviousTime to refer to the last value of bartime.

          Now when backtesting, each bar is processed sequentially from the first bar on the chart to the last when the efs is loaded or reloaded. Use of these references to time are appropriate and the oldest historical time that is required is what I refer to as sPreviousTime.

          You can also write your code to start backtesting once the chart fully loads. However, for simple backtesting, this adds another layer of complexity to your code that I would not recommend unless you are fairly advanced. In that case, you would have to reference everyting in relationship to the current bar. e.g. the time 50 bars ago would be Time = (getHour(-50)*100)+getMinute(-50);

          To say it again with a slightly different twist, when backtesting as the efs is loading, the current time as each of the bars load is sCurrentTime = (getHour()*100)+getMinute();
          and it is not necessary to refer to previous bar times as I did where I used the example for 50 bars ago.

          Comment


          • #6
            thanks

            thanks steve

            got it all working now

            thank you again

            Comment

            Working...
            X