There are two places where a writer needs to be able to know when to stop: editing and ending.
Firstly - this is one of my personal bugbears, something I really struggle to do - if you want to write, you have to get on with it. You won't get every sentence perfect first time. There will be parts you can see are not right, words that don't fit, awkward phrases, names that you haven't decided on yet.
If you like, highlight them for review. Or keep two working documents, one where you scribble it down while the muse has you, one where you copy-paste and edit when you're lacking in inspiration for the next part. Leave brief descriptions in brackets where you don't know a name. But don't sit agonising over a sentence when you know what to write for the next bit.
Secondly, when you get to a good ending, stop. This can be hard to find; endings are one of the hardest things to get right. There may be the temptation to have a 'happy ever after' because you want your characters, who you have nurtured and guided and watched struggle and put a great deal of yourself into, to be happy in the end. It may be that that fits your story, it may not. Don't force your story to that.
Don't force it to a tragic ending either, or anything else that you like the idea of, or that is trendy, or whatever. The ending must feel right for the story, even if you don't like it. I can't really tell you how to tell when it is right; you'll have to decide for yourself, but whatever you decide on, don't do it for vanity. And if the ending you thought you would have turns out not to be right, don't hesitate to change it.
Then, even when you know you where you are going, you have to realise when you've got there. You have to stop at some point. It may be that the story ends with a central character's death, or some other obvious end point. Often, though, it won't. It may well be that as far as you know what happens goes on somewhat further than as far as there is any story left.
In my vampire story (working title), I have a trilogy mapped out, with an ending that I am pretty sure is a good one that will fit the story. I also have a fair picture of Alexis' life after that, with things that I would love to write about. But I shan't, at least, not as part of the novels, because it isn't necessary. It would spoil the effect of the ending.
Know when to stop.