[LegacyColorValue = true]; 

{ TSMHerrickPayoff: Herrick Payoff Index
  Copyright 1999, P.J.Kaufman. All rights reserved.
}
  inputs: length(numericsimple);
  vars: hp(0), hpexp(0), hl(0), hl1(0), hl2(0);

  hl = high - low;
  hl1 = high[1] - low[1];
  hl2 = (hl / 2) - (hl1 / 2);
  if openint = 0 or openint[1] = 0 or hl2 = 0 then
			hp = 0
	else
			 hp = BigPointValue * volume * hl2 *
		          (1 + ( hl2 / absvalue( hl2) ) * ( 2 * absvalue(openint - openint[1]) / lowest(openint,2) ) );

  if currentbar = 1 then 
		hpexp = hp
	else
		hpexp = hpexp[1] + (2 / (length + 1))*(hp - hpexp[1]);
		
  TSMHerrickPayoff = hp;