Coding support and resistance is effectively coding a trend channel.
Here's one simple way:
Connect two bars by creating a trend line between them - this trend line starts at the first bar typical price and ends at the last bar typical price. Loop through each bar (from start bar to end bar) and find the highest high and lowest low - relative to the middle trend line, not absolute. Then, your resistance should have the same slope as the middle trend line, only it should be above it by the highest high you found. Same for support, only using lowest low. So find the middle line (connect star bar typical and end bar typical), find how far above/below it prices go and copy this middle trend line up and down based on those values. This means all bars should be within the trend channel. The highest high is found by looping through each bar from start to finish, finding what the price of the middle trend line is at that bar, and then comparing the high value of that bar to the price of the middle trend line.
Then you can look at how narrow it is, and the narrower it is, the more sense (strength or significane) it has and the more you should to consider it. Also, the more highs that a trend channel has that are nearly touching the resistance, the more significant it is.
This isn't a very precise method but it will work in most cases. It won't allow you to create triangular trend channels since here both high/low (resistance/support) are always parallel. Then you can look at intra-channel price distribution, extend the channels into the future/past, etc etc, lots of useful things you can do.