You are correct but with a few caveats. You need one eye on the market, but you also need one eye on your writing style, and another eye on your interests, and perhaps an eye on your agent should you have one.
How do we writers ever get a book written? I don't know. It was messy, fraught with doubt, and took almost two years (first one).
Let's continue our debate. I am all ears as a more or less new writer of historical fiction. I have to be comfortable with my writing amongst all the other concerns.