MultiCharts 12 is here with the Super Hot Summer Offer! Take advantage of it!
+1 888 340 6572

Week

Article/Author: Origin: http://www.traders2traders.com. Coded by: John Corrion

Download: WeekNumber.ela

File Includes: Function - Week

Category: Function > Week

Description:

A week number function to ISO rules for an indicator. It’s universal in need but missing from the standard library of Easy Language functions. It functions similarly to the “month” and “year” built in functions. Use at your own risk.

Inputs:

Date

EasyLanguage Code:
{WEEK NUMBER TO ISO RULES}

INPUT: DATE(NUMERICSERIES);
VARS: YR(0), MO(0), DDY(0), DY(0), LEAP(0), DNUM(0), FRSTMON(0);

YR = YEAR(DATE);
MO = MONTH(DATE);
DDY = DAYOFMONTH(DATE);

IF YR >= 99 THEN YR = YR + 2000 ELSE YR = YR + 1900;
IF MOD(YR, 4) = 0 THEN LEAP = 1 ELSE LEAP = 0; {IS YEAR A LEAP YEAR?}

DY = MOD((YR + INTPORTION(YR / 4) - LEAP + 1), 4); {FIND WEEKDAY FOR JAN 1 (1 = SAT, 2 = SUN)}
FRSTMON = 4 - DY; {FIND DATE OF MONDAY IN FIRST WEEK}
DNUM = DDY + INTPORTION(30.56 * MO) - 32 + LEAP; {CALCULATE DAY NUMBER}

IF MO < 3 THEN DDY = DDY + 2; {ADJUST FOR JAN AND FEB}
WEEK = INTPORTION((DNUM - FRSTMON) / 7) + 1; {FIND NUMBER OF WHOLE WEEKS}