Think of moonwalk as doing sort of a half-circle towards the direction you want to moonwalk. All the characters can moonwalk, and the most common method is initiating the moonwalk from the walking animation. So if you want to moonwalk towards the right, you could start by walking towards the right, then while walking, quickly move the stick from left to right without letting the stick go through the center (neutral). This is why you need a sort of half-circle motion. It is possible to do the half-circle going above neutral to accomplish a successful moonwalk, but going under is definitely recommended.
Doing it out of the walk is how I grab ledge with propably every character besides Falcon. I run towards the edge, then wavedash forward so I'm very close to the edge, walk for a few frames then moonwalk -> ledgegrab. If my timing is slightly late, it becomes a pc drop fastfall ledgegrab instead, 'cause it's basically the same motion of the thumb. Very good, effective and stylish way of grabbing edge, if you're comfortabe with it.
I think Falcon is the only character where starting the moonwalk from a dash instead of a walk is viable, because it yields almost the same length, and can easily be implemented into his dash dance this way. Using this method, if you want to moonwalk towards the right, you start by dashing right, then doing the same half-circle motion from left to right as in the previous method. This is the most common method for Falcon mains, but I recommend mastering both. You can also moonwalk out of "the charlie" which can be initiated from a sticky walk and a teeter cancel AFAIK.
If you feel like you're not getting anywhere with your moonwalk, your most likely not doing the half-circle input fast enough. It actually has to be ridiculousely fast, and it will seem impossible at first, but it can definitely be done. Practice just rolling to the ledge, then doing a half-circle towards the ledge until you can fall off of it.
The best thing with moonwalking is that it allows you to go far off stage with your back turned outwards. Other than that it's mostly a show off, and can sometimes mess with your opponent's head.