Nightmares are more of reflection of things you've been thinking about during the day. Hence, its advisable to have positive thoughts because that's what will be translated in your dreams. It's right that nightmares can be avoided but not at all but for a good number of months if possible. All you need to do is avoid stress. Whenever you're stressed up, you'll tend to think about lots of things to get out of that situation. This finally, makes your memory filled up and when you go to bed, you'll find that you end up having nightmares. Also, you should check on your sleeping time.I have done research on myself and realised that whenever i sleep very late like past 12 am, I must have nightmares. This happens to many and you need to check on it. Finally, before going to sleep, its good to say a short prayer because some nightmares are very frightening and at times they come to pass. I believe in the power of prayers.