I think the more you know about writing in general–the more you’ve read, the more you’ve thought about writing and why you like the stories you like, the better your ear is for other people’s writing, the more likely you are to gauge your own writing more or less accurately.
But only more or less. Because you’re so close to it, it’s hard to see without the emotional connection you’ve got to it. And as DeadlyAccurate says, even when you know (or think) it’s good, you’re also convinced it’s the worst piece of garbage anyone has ever committed to paper–simultaneously. And it’s hard to get away from that weird emotional state when you’re judging your own writing. But still, the better your judgement is with other people’s work, the better you’ll be at getting at least some idea of how yours is. You’ll never know for sure, but you’ll be pointed in the right direction. IMHO, of course.
I think the phenomenon of the newbie writer whose certain s/he can or has written a bestseller but who’s really turned out a heap of hard-won mulch is directly related to that–if you’re not doubting your abilities, you don’t have a realistic idea of just how hard the job is that you’re doing, and you probably don’t have the competence to know that. So as others have already said, just asking the question shows you’re likely on the right track.
There was a study done recently along those lines, hold on while I google…ah, here.
Summary, as I understand it–the study found that the least competent people (in the tested area) had the most inflated estimate of their ability. Increase their competence, and their assesment became more realistic.
On the other hand, the most competent tended to underestimate their abilities, until they were given a good idea of what average abilities were.