The first step is to define a set of conditions that you are looking for, which then need to be put in to a scripting formula. You’ve said you’re looking for a counter-trend, but how do you define a trend, eg moving average slope, higher swing highs?