Display bar count since recent high or low


I’m looking for help in developing a script that will tell me how many bars ago was the previous high or low. I plan to use this as a custom column.

Thank you