[LegacyColorValue = true]; 

{ TSMMoneyFlow: Money Flow Index
  Copyright 1999, P.J.Kaufman. All rights reserved.
}
  inputs: phigh(numericseries), plow(numericseries), pclose(numericseries),
          length(numericsimple);
  vars:  avg(0),  flow(0), ratio(0), sumup(0), sumdn(0), ix(0), diff(0);

  avg = (phigh + plow + pclose) / 3;
  flow = volume * avg;
  sumup = 0;
  sumdn = 0;
  for ix = 0 to length-1 begin
    diff = avg[ix] - avg[ix+1];
    if diff > 0 then 
          sumup = sumup + flow
       else 
          sumdn = sumdn + flow;
    end;
  ratio = 1.0;
  if sumdn <> 0 then ratio = sumup / sumdn;
  TSMMoneyFlow = 100 - (100 / (1 + ratio));