Loaded topic.
When I started writing seriously, I was in a danger zone with my marriage. Little kids. Husband who worked in the middle of the night. Time on my hands while everyone else was sleeping, so I spent it at the keyboard. It should be noted that the writing and the danger zone were not intertwined, it was just coincidental. HOWEVER, the emotional roller coaster affected my writing. As the marriage unraveled, I couldn't clear my head enough to focus on writing.
There is a hypothesis that you can't write real emotion until you've been through deep emotion. I'm not sure how much I subscribe to that, but I can tell you that although I completed that first book, my marriage fell apart while I started working on Book 2 (because you can't sell just one book, right?). I had to prove to myself that I could write another one, that one book wasn't a fluke. Neither one got published during that tumultuous time, and I certainly had a ton of emotion to invest into my writing.
That first book wouldn't be released until life leveled off--two years later. It isn't uncommon for first books to take years to work through. Learning the process. Learning what to do with your final product. Perfecting the craft.
Returning to a clearer frame of mind.
I continued on with a third book, because I was still convinced a publisher would want more than one book, and probably a three-book deal. The time it took to write those three books was the longest stretch of time I ever spent between books, and a lot of it had to do with emotional roller coasters coupled with challenges at the day job. I took a promotion that, quite frankly, they expected I might fail at. (Spoiler alert. I met the challenge and did NOT, in fact, fail.)
So much emotion.
Certainly, I'd reached that hypothetical threshold of emotion required to compel readers to take a journey with me. Those were certainly some of the most emotional years I'd lived through. But something else happened. I found writing helped me work through some of the darkness and the challenges by virtue of taking me out of my everyday life and -- this is funny -- out of my head. Wait. Isn't that where the stories come from?
Writing had become a vacation.
I did write from some very dark places. I killed off a nightmare boss in one of my books (yes, that's really a thing). I escaped from overthinking by writing characters who had to overcome personal challenges. By comparison, my life seemed like small potatoes.
Here's another tidbit --writing about personal challenges in fiction is rarely a good idea. Unless you have a resolution to those challenges, you can't stick the landing. You (and your not-so-fictional character) are stuck without the happily ever after ending.
So is it a good idea to write when you're moody? When the world is crashing around you? Yes and no. Yes, because it gives you an escape from the world, but no if that crashing world sneaks into what you're writing.
As I've been writing this next book, I found myself sliding into sad, dark places. It happens. Lack of sunlight. Health issues. If you've lost people close to you, you miss them sometimes. The holidays often highlight that they're missing. The mood came through in my writing. My characters were unlikeable. After a swift kick in the backside, I pulled myself up by my bootstraps to remind myself what I have rather than what I've lost - a conscious mood shift, if you will. The result is more likeable characters. I'm still molding them and still working through the next story, but the mood adjustment was definitely needed in order to proceed with something someone else might actually want to read.
Moods can be tricky things. They aren't always easy to kick out of, especially when life "piles on." Writing can be cathartic, and it can take you away from the troubles--at least for a little while. As an author, the rule is to write, even if you're writing crap. You can always fix it later, which is what I'm doing with the story playing in my head.