Announcement

Collapse
No announcement yet.

getFirstBarIndexOfDay

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

  • getFirstBarIndexOfDay

    I am trying to use getFirstBarIndexOfDay() to get the first bar index of the second last trading day. I run the following code snippet on 1min chart.


    if ( getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0 ) {
    var fbi = getFirstBarIndexOfDay(getValueAbsolute( "rawtime", 0 ));
    var fbi2 = getFirstBarIndexOfDay(getValueAbsolute( "rawtime", fbi-1 ));
    debugPrintln(fbi + " " + fbi2);
    }


    Can someone tell me why the above code snippet prints out the same value for fbi and fbi2.

  • #2
    Re: getFirstBarIndexOfDay

    clearpicks
    At my end your code is printing different values and these correspond to the appropriate first bar of each day (see enclosed screenshot)
    Alex




    Originally posted by clearpicks
    I am trying to use getFirstBarIndexOfDay() to get the first bar index of the second last trading day. I run the following code snippet on 1min chart.


    if ( getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0 ) {
    var fbi = getFirstBarIndexOfDay(getValueAbsolute( "rawtime", 0 ));
    var fbi2 = getFirstBarIndexOfDay(getValueAbsolute( "rawtime", fbi-1 ));
    debugPrintln(fbi + " " + fbi2);
    }


    Can someone tell me why the above code snippet prints out the same value for fbi and fbi2.

    Comment


    • #3
      clearpicks
      Here is the same after a new bar was formed. The values still appear to be correct and updating properly
      Alex

      Comment


      • #4
        I run it on a time template for 1minute: #days = 2 days, start time 0:00 and end time 24:00. The symbol is CL F8.
        Attached Files

        Comment


        • #5
          the output
          Attached Files

          Comment


          • #6
            The time template
            Attached Files

            Comment


            • #7
              clearpicks
              I believe that the results you are seeing are due to the fact that [as I understand it] "rawtime" returns the bar time as UTC time and not as local time.
              You have two solutions that I can think of. One solution is to convert the time returned by "rawtime" to local time. You would do this by adding/subtracting the timezone offset (depending on where you are located respect to GMT) to the time returned by "rawtime". The other which is considerably simpler to implement is to use "time" instead of "rawtime" in your getValueAbsolute() calls. As far as I know "time" returns the bar time expressed as local time (ie as you see it displayed on the chart).
              Either method described above should resolve your problem.
              Alex


              Originally posted by clearpicks
              I run it on a time template for 1minute: #days = 2 days, start time 0:00 and end time 24:00. The symbol is CL F8.

              Comment

              Working...
              X