Stronger earnings and foreign buying extended the market’s rally, but rising inflation and continued domestic institutional selling could limit further gains.