SierraChart has that as a built-in study called "N bar highest high n bar lowest low." You just specify the value for N.