Lines 48-49 and lines 61-62: the bracket for 0.5 is put wrongly, hence result is incorrect. Should multiply by 0.5 for second pair, not subtract from first pair.
Correct code as below:
href[i] = ((data[high].iat[i]) - (data[close].iat[i-1])) - \
(0.5 * ((data[low].iat[i])-(data[high].iat[i-1])))
lref[i] = ((data[close].iat[i-1]) - (data[low].iat[i])) - \
(0.5 * ((data[low].iat[i-1])-(data[high].iat[i])))