Announcement

Collapse
No announcement yet.

Trying to get seconds from a bar

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

  • Trying to get seconds from a bar

    I have Hours and Minutes working but the Seconds no.

    barHr = getHour()+"";
    if (barHr != null && barHr < 10) barHr = "0"+barHr;
    barMin = getMinute()+"";
    if (barMin != null && barMin < 10) barMin = "0"+barMin;
    barSec = getSecond()+"";
    if (barSec != null && barSec < 10) barSec = "0"+barSec;
    barTime = barHr + ":" + barMin + ":" + barSec;

    borrowed code but help shows second() getSecond not Seconds
    trying both still no go
    sam

  • #2
    sam
    The snippet of code you posted is working fine. Keep in mind that unless you are running the script on a tick based chart (ie intervals T, V, S, P and R) it will always return 00 seconds.
    getSeconds() is a method of the Date Object and not a function like second() or getSecond() [the latter is actually a wrapper for the getValue() function requesting the seconds value]
    Alex


    Originally posted by sam.burn
    I have Hours and Minutes working but the Seconds no.

    barHr = getHour()+"";
    if (barHr != null && barHr < 10) barHr = "0"+barHr;
    barMin = getMinute()+"";
    if (barMin != null && barMin < 10) barMin = "0"+barMin;
    barSec = getSecond()+"";
    if (barSec != null && barSec < 10) barSec = "0"+barSec;
    barTime = barHr + ":" + barMin + ":" + barSec;

    borrowed code but help shows second() getSecond not Seconds
    trying both still no go

    Comment


    • #3
      thanks again Alex

      I am running script that is tick based but not a chart (5min)

      Sam
      sam

      Comment


      • #4
        Sam
        Even though you are running a script that executes on every tick you are requesting the seconds of the bar time which is always 0 except on tick based intervals (eg 10T, 500V, 0.5R, etc).
        Alex


        Originally posted by sam.burn
        thanks again Alex

        I am running script that is tick based but not a chart (5min)

        Sam

        Comment


        • #5
          Thanks
          Alex
          sam

          Comment


          • #6
            Sam
            You are most welcome
            Alex

            Comment

            Working...
            X