Write for yourself? Write for your reader?
Both are correct, and neither.
If you're writing something you don't enjoy writing just because you think it will sell, you're doing something wrong. Generally if you don't enjoy writing it, your readers won't enjoy reading it.
On the other hand, too often "I write for myself" is just an excuse to not put effort into it because you're trying to console yourself ahead of time that if it's not well received, it's just because the readers don't "get it."
I've fallen into both traps at times, but fortunately it's not to difficult to keep the correct frame of mind. My rule of thumb is this:
Write a book that you'll want to read.
That will help you focus the style of the book into something that your readers can enjoy, while at the same time giving you the pleasure of writing and the motivation to make it the best you can.