Announcement

Collapse
No announcement yet.

getBarIndexAt

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getBarIndexAt

    Just been looking at the getFirstBarIndexOfDay() function and some other "index" functions such as getCurrentBarIndex() etc.

    I'm trying to get the bar's index value from a Date() object that I've created. Say I've created a date object with the value of "7/7/2010 02:00:00 PM" and now is "7/8/2010 10:00:00 AM". I want to find the bar index that corresponds with my date object "7/7/2010 02:00:00 PM".

    How would I do that?
    Standing on the shoulders of giants.

  • #2
    Just thinking out aloud I should be able to find that myself by iterating backwards through the bars and doing a comparison on that bar's Date object with the one I've created right?

    If that would work, then how would I get the Date object for bar index (say) -20?
    Standing on the shoulders of giants.

    Comment


    • #3
      wildfiction

      I should be able to find that myself by iterating backwards through the bars and doing a comparison on that bar's Date object with the one I've created right?
      That is correct. You can use a while statement to loop back through the bars

      If that would work, then how would I get the Date object for bar index (say) -20?
      Retrieve the rawtime from your Date object using the .getTime() method and then evaluate that against each bar's rawtime() as you loop back. Note that the .getTime() method returns milliseconds whereas rawtime() returns seconds so you will need to adjust for that
      Alex


      Originally posted by wildfiction
      Just thinking out aloud I should be able to find that myself by iterating backwards through the bars and doing a comparison on that bar's Date object with the one I've created right?

      If that would work, then how would I get the Date object for bar index (say) -20?

      Comment

      Working...
      X