Announcement

Collapse
No announcement yet.

Historical Begin and End Time Stamps

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

  • Historical Begin and End Time Stamps

    Is there a way (or the best way) to record each historical bar's full time stamp (beginning and ending date/hour/minute) as an EFS is being loaded? to be saved for later use, such as to a file? Thanks.

  • #2
    z11,

    here is a method I used after all bars were loaded to accomplish something very similar to what you want.
    PHP Code:
    function time_and_price_data(){
     
    nbars Math.abs(getOldestBarIndex());
     
    dbar Initialize_2X_Array(10,nbars);
     var 
    n;
     for (
    n=0;n<nbars;n++){
      
    dbar[0][n] = (getHour(n-nbars)*60) + getMinute(n-nbars); // # of minutes
      
    dbar[1][n] = open(n-nbars);
      
    dbar[2][n] = close(n-nbars);
      
    dbar[3][n] = high(n-nbars);
      
    dbar[4][n] = low(n-nbars);
     }
    function 
    Initialize_2X_Array(n1,n2){//initialize 2 dim array
     
    var i; var j;var newArray = new Array;
     if (
    n1 == null){n1 =2;}if (n2 == null){n2 2;}
     for (
    i=0;i<n1i++){newArray[i] =  new Array();
      for (
    j=0;j<n2j++){newArray[i][j]=0;
     }}
     return 
    newArray;

    that is one way that I have used in the past which is straight out of operating code. Alternatively, you could do something similar that would record the data as it loaded (FWIW, this would be my preferred method) similar to this:
    PHP Code:
    //define as a global
    dbar = new array();

    //in Main every new bar
    //you define the starttime and date variables

    dbar[barcount] = new time_price_data(starttimedate);

    // as a separate function
    function time_price_data(s,d){
     
    this.start_time s;
     
    this.date d;
    }

    // then store the data
    function store_data(){
     var 
    i;
     
    file1 = new File("x");
     
    file1.open("wt+");
     for (
    i=0;i<dbar.length;i++){// writes to file
         
    var dbar[i].start_time+","+dbar[i].date;
       
    file1.writeln(a);
         
    file1.flush();
      }
      
    file1.close();

    I haven't used the last code snippets, as I just wrote this for you, but they should work.

    I hope this helps.

    Comment


    • #3
      Steve, thanks...another great reply from you.
      Can you do .length operation on 2 dimensional arrays?

      Comment


      • #4
        Hi Z11,

        Thanks for the kind words.

        Yes, you can. I am assuming you would want this for some sort of iterative loop.

        Alternatively, you can also use a for/in statement loop with objects as well. See this link http://www.quirksmode.org/js/associative.html.

        Regarding a 2 dimensional array, dbar[x][y], where x and y are the lengths of their respective dimensions

        dbar.length would equal x

        dbar[0].length would be equal to y (assuming element zero was defined).

        the same goes for dbar[1].length, dbar[2].length, etc. Depending how these elements were defined, their length may each be different. In the first example in my post below, they would all be the same length.

        Comment


        • #5
          Thanks Steve. I have not tried it but I presume the operations of Pop and Unshift will also work on the 2 dimensional arrays as well...

          On a unrelated note, how would you prevent a system from re-enter a position it just exited on the same bar (but different ticks)... say it was short, and its logic exited the short ...but on the next tick it goes back in short.... I tried to set a flag on the bar it exited but it stopped all trades since the bar index is zero for the current bar but on each iteration of ticks you can't increment that flag since it is still the same bar...don't know if I am explaining myself correctly...

          Comment


          • #6
            Z11,

            An easy way would be to create a bool that is set to true when you exit and set to false initially and on each NEWBAR. All you would have to do is check the value of the bool before entering a new trade.

            Alternatively - only enter or exit trades at the close of the bar.

            Garth
            Garth

            Comment


            • #7
              Thanks Garth, I just implemented that flag and am waiting to see if it works during the course of the day..

              Comment

              Working...
              X