Announcement

Collapse
No announcement yet.

Difference between two Dates as Bars

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

  • Difference between two Dates as Bars

    Hi,

    I am trying to write a script that will tell me the number of bars between my current bar and a bar representing some future date and time. I have the following test code snippet:

    var futureDate = new Date(2008, 11, 31); //Dec 31, 2008 at 00:00:00
    var currentBarDate = rawtime(0)*1000; // in milli seconds
    var difference = futureDate.getTime()-currentBarDate;

    If I had a specific time on the future date, I can add that to the futureDate variable by using getHour(), getMinute(), getSecond(), ...

    Here is my issue:
    I know there is 86400000 milliseconds in a day so if I am running intraday, say 5 min bars, getInterval() will return 5 and I can figure out how to get the number of bars from my current bar to my future date bar. If I am running day bars, getInterval() should return D and I can figure out the number of bars. LIkewise for weekly charts as there are 7 day in a week.

    My question is, how is this handled for Monthly charts (since the number of days in a month varies, is there 4 or 5 weeks in a month), tick charts, second charts and volume bar charts? (Basically all the charts possible in eSignal.)

    Perhaps someone knows a clean solution to this problem. Any insight and help would be greatly appreciated. Thank you very much in advance.

    Also, very happy holidays and all the best into the New Year to all the staff of eSignal and all the members of this and other eSignal forums.

    Regards,
    Jane

  • #2
    Re: Difference between two Dates as Bars

    Jane
    If the chart's interval is monthly you could just calculate the difference between the month of the future date and that of the current bar and adjust the resulting value by 12 for each year's difference if they are not in the same year
    Alex


    Originally posted by jg
    Hi,

    I am trying to write a script that will tell me the number of bars between my current bar and a bar representing some future date and time. I have the following test code snippet:

    var futureDate = new Date(2008, 11, 31); //Dec 31, 2008 at 00:00:00
    var currentBarDate = rawtime(0)*1000; // in milli seconds
    var difference = futureDate.getTime()-currentBarDate;

    If I had a specific time on the future date, I can add that to the futureDate variable by using getHour(), getMinute(), getSecond(), ...

    Here is my issue:
    I know there is 86400000 milliseconds in a day so if I am running intraday, say 5 min bars, getInterval() will return 5 and I can figure out how to get the number of bars from my current bar to my future date bar. If I am running day bars, getInterval() should return D and I can figure out the number of bars. LIkewise for weekly charts as there are 7 day in a week.

    My question is, how is this handled for Monthly charts (since the number of days in a month varies, is there 4 or 5 weeks in a month), tick charts, second charts and volume bar charts? (Basically all the charts possible in eSignal.)

    Perhaps someone knows a clean solution to this problem. Any insight and help would be greatly appreciated. Thank you very much in advance.

    Also, very happy holidays and all the best into the New Year to all the staff of eSignal and all the members of this and other eSignal forums.

    Regards,
    Jane

    Comment


    • #3
      Hi Alex,

      I never thought of this. I thought of using the difference (rawtime(0) - rawtime(-1))*1000 for bars but this offsets by 1 bar. Your solution is much cleaner. Thank you very much.
      Regards,
      Jane

      Comment


      • #4
        Jane
        You are most welcome
        Alex


        Originally posted by jg
        Hi Alex,

        I never thought of this. I thought of using the difference (rawtime(0) - rawtime(-1))*1000 for bars but this offsets by 1 bar. Your solution is much cleaner. Thank you very much.
        Regards,
        Jane

        Comment

        Working...
        X