Date & time
4 functions
DATETODAY(DATE)Days from 1990-12-19 to the given YYMMDD date.
- DATE(integer)
- A date in YYMMDD form — 251231 is 2025-12-31.
// calendar days between two dates — subtract the day numbers,
// which is what makes this function useful
DAYS: DATETODAY(251231) - DATETODAY(250101);
// days elapsed since a fixed start date
ELAPSED: DATETODAY(DATE) - DATETODAY(250101);DAYTODATE(N)The date N days after 1990-12-19, as YYMMDD.
- N(integer)
- Day number counted from 1990-12-19 — the inverse of DATETODAY.
// what date is 30 calendar days out from this bar?
FUTURE: DAYTODATE(DATETODAY(DATE) + 30);
DRAWTEXT(ISLASTBAR, LOW, VARCAT('+30d = ', VAR2STR(FUTURE, 0)));TIMETOSEC(TIME)Convert HHMMSS to seconds since midnight.
- TIME(integer)
- A clock time in HHMMSS form — 93000 is 09:30:00.
// HHMMSS is not linear — 100000 minus 95900 is not one minute.
// convert to seconds before doing any arithmetic on times
SINCEOPEN: TIMETOSEC(TIME) - TIMETOSEC(93000);
// only mark signals in the first half hour
EARLY := SINCEOPEN >= 0 AND SINCEOPEN <= 1800;
DRAWICON(EARLY AND CROSS(MA5, MA20), LOW, 85);SECTOTIME(SEC)Convert seconds since midnight back to HHMMSS.
- SEC(integer)
- Seconds since midnight — the inverse of TIMETOSEC.
// do the maths in seconds, then convert back for display
CLOSETIME := SECTOTIME(TIMETOSEC(TIME) + 3600);
DRAWTEXT(ISLASTBAR, LOW,
VARCAT('+1h = ', VAR2STR(CLOSETIME, 0))), COLORWHITE;