Black Friday great discounts start today Learn more
+1 888 340 6572

WeeklyBarsAnyDay

Article/Author: Emmanuel Lavelanet Omega Research Inc., 1996

Download: FUNCTION-WEEKLYBARSANYDAY.ELA

File Includes: Function - WeeklyDaysAnyDay

Description: This Function allows you to create Weekly charts from Daily Data, based on any day of the week.
It also allows you to reference Previous Weeks, up to 10 years.

EasyLanguage Code:
{ USER FUNCTION: WEEKLYBARSANYDAY. CREATED BY EMMANUEL LAVELANET. 12/10/96

LAST EDIT: 12/10/96.
PROVIDED BY: OMEGA RESEARCH, INC. (C) COPYRIGHT 1996 }

{ INPUT DESCRIPTION.
WHICDAY - 0 TO 6 SELECTS SUNDAY TO SATURDAY
BARSAGO - SELECTS CURRENT WEEK OR ANY PREVIOUS WEEK
PRICE - 1 TO 4 SELECTS OPEN, HIGH, LOW AND CLOSE}
INPUT:WHICHDAY(NUMERIC),BARSAGO(NUMERIC),PRICE(NUMERIC);

{ THE FOLLOWING VARIABLES ARE USED TO HOLD OPEN, HIGH, LOW AND CLOSE OF THE
WEEK}
VARS:WOPEN(0),WHIGH(0),WLOW(0),WCLOSE(0);

{ ARRAYS ARE USED TO HOLD WEEKLY PRICES TO ALLOW REFERENCE TO WEEKS AGO.
MULTI LEVEL ARRAY CAN BE USED IN VERSION 4 AND UP. }
ARRAY:PREVO[550](0),PREVH[550](0),PREVL[550](0),PREVC[550](0);

{ IF NOT CHOSEN DAY THEN FUNCTION = -1}
WEEKLYBARSANYDAY = -1;

IF DAYOFWEEK(DATE) = WHICHDAY AND VALUE1 > 0 THEN BEGIN
WCLOSE = CLOSE;
WHIGH = CLOSE;
WLOW = CLOSE;

{ FIND OPEN, HIGH AND LOW OF THE WEEK}
FOR VALUE2 = 0 TO VALUE1 BEGIN
IF HIGH[VALUE2] > WHIGH THEN
WHIGH = HIGH[VALUE2];
IF LOW[VALUE2] < WLOW THEN
WLOW = LOW[VALUE2];
IF VALUE2 = VALUE1 THEN
WOPEN = OPEN[VALUE2];
END;

{ STORE OPEN, HIGH, LOW AND CLOSE OF WEEK IN ARRAYS}
VALUE3 = VALUE3 + 1;
PREVO[VALUE3] = WOPEN;
PREVH[VALUE3] = WHIGH;
PREVL[VALUE3] = WLOW;
PREVC[VALUE3] = WCLOSE;

{ FUNCTION RETURNS THE PRICE REQUESTED BY INPUT PRICE}

IF VALUE3 - BARSAGO > 0 THEN BEGIN
IF PRICE = 1 THEN
WEEKLYBARSANYDAY = PREVO[VALUE3 - BARSAGO];

IF PRICE = 2 THEN
WEEKLYBARSANYDAY = PREVH[VALUE3 - BARSAGO];

IF PRICE = 3 THEN
WEEKLYBARSANYDAY = PREVL[VALUE3 - BARSAGO];

IF PRICE = 4 THEN
WEEKLYBARSANYDAY = PREVC[VALUE3 - BARSAGO];
END;

{ RESET NUMBER OF BARS IN WEEK}
VALUE1 = -1;

END;

{ ACCUMULATE NUMBER OF BARS IN WEEK}
VALUE1 = VALUE1 + 1;