If you are a beginner trader, i highly recommend you to stick with the trend, because pin bars that occur in trending markets offer good trading opportunities with high risk/reward ratio.
When you master trading it with the rend, you can then move to trade range-bounds markets or even counter-trends.
This strategy is simple, you start by identifying a clear uptrend or downtrend, and you wait for a pin bar to occur after a pullback to support or resistance level.
See the example below:

The figure below shows how this price action signal works if it is traded with the trend, as you can see, the price was rejected from the resistance level which indicates that the bears are still in charge of the downtrend.
The formation of the pin bar indicates the end of the retracement move, and the beginning of the impulsive move at the resistance level in line with the downtrend.
This is a high-quality setup because all the following criteria are respected:
1-The pin bar is well formed, and it is in line with the direction of the market.
2-The rejection occurred in a major key level which represents a hot point in the market (resistance level).
3-The risk to reward ratio is good, and it is worth trading.
Sometimes, even if the market is trending, we can’t draw support and resistance levels, because prices move in a certain way which we can’t spot static key levels.
If you are in this situation, you can use the 21-moving average which will act as a dynamic support in an uptrend market and a dynamic resistance in a downtrend market.
See the illustration below:

As you can see in the chart above, the market was trending down, using the 21 moving averages helps us to identify dynamic resistance levels, and high probability pin bar setups. See another chart below:

The 4-hour chart above illustrates how the 21-moving average could help us find key points in the market.
When prices approach the moving average, the buying pressure takes place in the market, and the price goes up.
The pin bar signal is clear on the chart, because the trend is bullish, the price action setup has a bullish anatomy as well, and the rejection from the 21-moving average is a confirmation signal to buy the market.