Hmm… Buying after a rally is being with the trend, and don’t think it is a novice mistake. Novice mistake is to trying to sell/short when in a rally or leaving the stocks which are going up and trying to buy stocks which are going down thinking it will also start rallying.
Mechanical way, I guess is probably using technical analysis indicators, say for example buying when RSI is way above the overbought levels…
If you are a trader, you have to buy on rally. As your objective is to capture momentum and not to block your capital for longer periods.
But if you are a investor, you wait for corrections, and slowly invest in a belief that in long term it will again move up. The up move may come after a month/year but you have to stick to it with a stoploss.
Good traders who make money are always with the trend, in fact they scale up as the rally progress!!
My advice is see what happened before a rally, is it a sudden move, are they traders trapped on wrong side, is it on some news, is it some important technical level(support, resistance), is it weekly/monthly new high etc and take a decision.
in other words, is there a mechanical way u can think of to avoid buying after a rally?