[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EL Question - Referencing 52-week High on Intra-Day Chart



PureBytes Links

Trading Reference Links

> One approach that would need to be updated each week would be to
> define a 2 dimensional array.  One dim being the weekly high, the
> other  dim being the weekly closing date. ( Or may this two single
> dimension arrays. 

All you need is two 52-long single-dimension arrays, to hold the 
weekly high and low for each of the last 52 weeks.  Then you can do 
something like this:

vars: Wk(0), ThisWkHigh(0), ThisWkLow(99999999), High52(0), Low52(0);
arrays: WkHigh[53](0), WkLow[53](0);

if DayOfWeek(Date) < DayOfWeek(Date[1]) then begin  { New week }
  WkHigh[53] = ThisWkHigh;
  WkLow[53] = ThisWkLow;
  High52 = 0;
  Low52 = 999999999;
  for Wk = 1 to 52 begin
    WkHigh[Wk] = WkHigh[Wk+1];
    WkLow[Wk] = WkLow[Wk+1];
    High52 = MaxList(High52, WkHigh[Wk]);
    Low52 = MinList(Low52, WkLow[Wk]);
    end;
  ThisWkHigh = 0;
  ThisWkLow = 99999999;
  end;

ThisWkHigh = MaxList(H, ThisWkHigh);
ThisWkLow  = MinList(L, ThisWkLow);

(Not tested, but it should be close)

As soon as you hit a bar in a new week, the code in the if gets 
executed.  It stores the previous week's H/L in the "53rd week" slot 
(so it can cheat and compute the 52-week H/L while it's in the loop), 
and then shifts all the previous weekly highs/lows back one week.  
Then the last two lines record the H/L for the new week.

(It would be fancier to use a "circular buffer" for the H/L's, so you 
wouldn't have to shift the data.  But that's more confusing to code, 
and the shift action only happens once a week, so who cares if it's a 
little less efficient?  Besides, you need to scan through the arrays 
to find the H/L anyway.)

High52 and Low52 are your 52-week H & L.

Gary