While travelling by train (travelling West to East), it seems the moon is moving in opposite direction when seen from the window, but then it reverses its direction, after a certain amount of time and moves along the train, but then flips back again. And it kept oscillating, as the train kept moving. Can anyone point out the reason?
The Moon was moving in relation to what?
I had to think about this when you described your experience. Because of the distance of the moon compared to objects on the horizon, it should appear to stand still in comparison to everything else closer whizzing past you.
But then I thought of your description of "oscillations" and thought "AHA! The window."
If you were travelling exactly west to east, and you were observing the moon through a window exactly facing south (or north, depending which side of the train you are on and the time of year and where on Earth you are,) it would appear to be standing still in your window. (Neglecting for the moment the comparatively slow apparent progression of the moon through the sky.)
But I reckon your train track was not exactly straight for the duration of your trip and the moon was never exactly perpendicular to your train's direction. But it was probably quite close to perpendicular. So any slight deviation would cause you to observe the moon travelling towards one edge of the window, and then a slight deviation in the other direction would cause the moon to apparently move towards the other edge of the window.
It's simply the winding s-shaped route your train took, heading generally east but never exactly, that caused these oscillations.
I see a few factors that would cause the moon to "move" around. The most significant is variations in the direction of the train.The train may not be going in a straight line and these small variations in direction (slightly north or south), even if undetectable, may cause the moon to "move" from your perspective. If the train turns 1 degree north, then the moon should move 1 degree right, which may seem like it is moving a lot since humans have almost a full 180 degree field of view.
Also the moon is orbiting the earth, so the moon will drift through the sky slowly, however this effect would happen much more slowly and cannot account for the oscillations. I hope this helps, and get some sleep, don't spend all your night thinking about physics ;).