I am applying to graduate school in US for MS and Phd program. I wonder is it a good idea to ask for a letter of recommendation from someone that I took his course and I did amazing in his class and he knows me very well but he is now professor at another prestigious institute ?
It's not just a good idea, it's an excellent idea. Your professor is still in just as good a position to speak to his experience with you and his assessment your abilities as he was before. You say he has moved to another good institution, so there is no reason for his opinion to be discounted just because he moved---changing institutions is not unusual. In fact, if he is happy to write you a good letter, it will look even better than if he was at the same institution, because even after changing institutions he still remembers you and cares enough to write.
It doesn't matter where the professor works now, but you should state clearly that the professor once taught you at your university.