With the historical data and the support and resistance known, can i can calculate the distance price retraces back to support or resistance before going up or down? This way I can say "after +500 trades, prices retraces back to support or resistance by X ticks the most"? This way I have idea the optimal place to use limit orders for entry.
Yes, for backtesting purposes. You would just be doing addition/subtraction between the "current" price and the support/resistance price...this would be your "distance."