Actually I built this to model renko bars. I have updated the code above with my interpretation of renko bars. enjoy.