Is there a way to detect a player with relative coordinates to the command block?

You almost had it, /execute is the solution, but with positioned:

/execute positioned ~1 ~2 ~3 if entity @p[distance=..4.5] run …