Fancharacters. We're all familiar with them. Most of us greatly dislike the majority of them. This is because a large number of them are written by people creating their first characters, who really have no clue how to create an original character in the first place, and don't realize that inserting a new character into an existing work actually requires more attention to balance to be successful, never mind the fact that the authors often have fictional crushes on at least one character in the work they are writing about. For this reason, some of the most frighteningly bad Mary-Sues are often found in fanfiction.
This can be avoided. Some fancharacters can be made extremely well. It isn't fair to count out all fancharacters, especially if they're written into a series that has a new guest every week, or has even been known to pick up new permanent cast when the writers feel like it. If you hope to write a good fancharacter, there are some simple things to bear in mind.
Your character is a guest in the canon characters' universe, not the other way around.
This should be obvious - and for that reason, is deceptively easy to forget as you write. Guests are remarkably like fish - if they stick around for too long, they start to stink. When writing a fancharacter, this also applies if they stay in the spotlight for too long.
It is easier to write a fancharacter into a fandom that frequently features guests, as this gives you a guideline as to how much of the spotlight guests typically get in that universe. Stay within those guidelines, if they exist. If not, make an educated guess - or, if you do not feel comfortable making a guess, read/watch one or more comparable series and get a feel for how guests may be treated. In any case, one thing is constant - while a guest may hold a fairly large role, and may even be a main plot device, the primary focus will always be on the canon characters.
You and your character will be judged more harshly than a canon writer and guest character.
Live with it.
There are some things that your character just won't be able to get away with unless s/he is actually picked up and added to the book/show/next movie/next game/whatever. How far does that divide go? It depends on the viewer; it's really subjective business. Again, some will get upset because s/he even exists in the first place, even if you're writing a fanfic for a show that has a new guest character every week. Some will get upset if the series man-slut goes after her, a cute girl, for no longer or shorter than he pursues any other cute girl. Some will be upset if he, a teenage boy, develops an unrequited crush on one of the women of the main canon cast, even though this may not be the main focus of his character. Obviously these claims can be shrugged off - such things happening are perfectly normal. However, certain things, such as family, once set by the canon, may be changed by the canon with a fairly good acceptance rate, but you, as a rule, will not have such luck. Similarly, while in the canon, a new character may replace an old one for whatever reason, you shouldn't attempt this, whatever your reason. Even if you did it well, most people will assume it was just because you didn't like the canon character you replaced, and thought you could do better. This always ends badly.
Self insertion is usually bad.
At this, I hear the reactions now - half of you are broken-hearted, half of you are shocked that I only said "usually." If this is your first time writing a fancharacter, don't do it. Seriously. Don't. You are treading on tricky ground if you try.
In all honesty, most real people would probably make good fictional characters - look at yourself, your best friends, near everyone you know. You are rounded, you have real strengths and weaknesses, you are individuals, unlike any others. However, when one inserts him/herself into his/her favorite fandom, s/he often becomes tempted to break many of the rules in this guide for the sake of wish fulfillment.
This is not to say that your character should have nothing in common with you. You should always put a "piece of yourself" into your characters - if you cannot relate to them at all, you're doing it wrong. Giving them a little bit of you to relate to anchors them into reality. However, the danger arrives when you can honestly say that they are you with a different face, perhaps a different name, and probably some exciting new skills and hobbies.
If you are willing to devote a lot of extra time and effort to ensuring that you do not cross the line - if you are willing to reread your work from the standpoint of a stranger, have it critiqued if you can, change whatever you need to in order to ensure that you are not turning the story into a wish fulfillment fantasy - then by all means, try writing yourself in, but I hope that you are interesting enough to justify the extra work. It's usually best to start from scratch.
However, for your own enjoyment, it is perfectly acceptable to write a wish fulfillment fic. We just don't want to see it. Keep it in a private file, or in your drawer, not on the internet or in your shared notebook. It's a bit creepy when you openly subject the world to your fantasies, y'know?
People do not love your character at first sight.
Another that seems like it should go without saying, and for that reason, is deceptively easy to forget. Take note: Out of character, on the sliding scale of likablility, a just-created fancharacter sits right below Scrappy-Doo, Wesley Crusher, and a flesh-eating amoeba. Your character is not a real person, and as such, does not have real family to immediately love him/her the moment s/he is introduced - his/her only family is in the context of your story, and they probably should be just as low on the likability scale. In-character, the canon characters will not immediately love a character they have just met. Depending on the situations surrounding the meeting and how they typically regard newcomers, some will be welcoming, some will be wary, some may be lustful if they're that type (be cautious with this, though!) - but this cannot be mistaken for love. Relationships must never be forced if your character is to get out of that rather uncomfortable spot on the scale of out-of-character likability. Both in-character and out-of-character, your character must earn every bit of appreciation s/he gets.
Your character is not irresistibly beautiful.
A character can be attractive, this is perfectly acceptable. However, under no circumstances is s/he so physically attractive that absolutely everyone who sees him/her will instantly be drawn to him/her - unless every single canon character really is that shallow and has shown it in the canon, in which case I must wonder about your taste in entertainment, but to each their own. If the characters in this universe have any realism to them at all, they all have different taste in what they find attractive - some may be happily married, with eyes for no one but his/her spouse, some may be out to sleep with everything with a pulse and working reproductive organs, most will probably be some shade in between. Do not change this. There are few reasons to change a canon character's behavior, especially in this area.
Your character should look like s/he belongs in the universe.
Look at the canon characters. Take note of not only their clothing, but their hair colors and styles, and their body types. Odds are, there's a reason they're like that - and even if not, it's best if your character fits in. If technicolor hair is not something often seen in this universe, even if hair dye exists, you should refrain from giving your character neon pink highlights. If everyone seems to be physically fit, and shows reason for needing to be, you probably don't want to make your character extremely small and thin and fragile.
As well as dressing appropriately for the universe, your character should dress appropriately for his/her age. An 11-year old girl should not be running around in a fishnet top over a shirt that's barely more than a bra, and a 9-year old boy shouldn't be strutting about shirtless in an open jacket as if he's God's gift to women - unless, say, he's at the pool or beach and imitating his older brother. Similarly, a child should not wear the armor of an adult warrior (aside from being inappropriate, also note that even if he can move in it to some degree, it's probably more hindrance than protection!), and an adult should not wear a middle school uniform. If nothing is shown for the age that you want your character to be, either try a character of a different age or make a rough guess at what would be considered appropriate.
If a family history is known, it is set.
Suppose the main character is known to have a mother who visits occasionally, a father who is dead, and a younger sister who is a regular character. Your character is not his long-lost twin, because he has no long-lost twin - you would think that he, or at least his mother, would be aware of another child, now wouldn't they? Attempting this causes your character to feel shoehorned in, and it won't leave your viewers particularly pleased.
Clones are never a good idea outside of sci-fi, and rarely a good idea even there. Unless your character is to be used as more of a plot device than an actual character, and often even then, it tends to feel like a cop-out - that you were too lazy to come up with your own character, so you tweaked one of the canon characters and called him/her yours.
Giving your character a family relationship to a minor character whose family is unknown can work, but more often than not it tends to look desperate. A simple rule to prevent this is to remember that a guest character should not overshadow his/her canon relatives. If you are introducing a relative, put a slightly greater than equal amount of focus on this minor character as well.
The only potentially acceptable link to an established family is a character who was born after the last "check" of the family tree. It would not even be too much of a stretch to believe that the man-slut of the series might have a child he doesn't know about. If a brother or sister does not or cannot keep in contact, there may be an unknown niece or nephew. However, this, just as the above option, is dangerous ground, and as with self-insertion, takes a lot of extra reviewing to make sure it's going well.
All things considered, unless you're using the family link as a critical plot device, you're best off creating your character's family yourself. If the family link can be replaced with friendship, you're also best off creating your character's family yourself. There are very, very few cases where putting your character in the family is acceptable, and even fewer where it is needed.
No one's past perfectly mirrors a canon character's.
Even if a canon character's past is fairly normal, the odds of someone else's past mirroring it exactly are astronomical. If their past contains more extraordinary events, the odds of similarity - any similarity - decrease drastically. If you want to be realistic, don't Xerox another character's past for yours - you may think you're giving them a point where they can relate, but really, that's just being unoriginal.
Your character does not look exactly like a canon character.
Your character should not be wearing the same clothes as a canon character, unless it is a uniform. Your character should not be an obvious recolor of a canon character - there is nothing original about a brown-haired Sakura Haruno in a blue dress with black trim. While your character should look like s/he belongs in the universe, this refers to style only - not exact design. Your character should not share a non-genetic distinguishing feature with a canon character - nor a genetic feature if they are not related (as they probably are not). Yes, taking your favorite character's gravity-defying hairstyle and just making it longer or adding a ponytail still counts in the "do not" category.
Think of it this way: Imagine a new person comes to your school or workplace, and looks exactly like you, in every way - clothing, accessories, hairstyle, everything - save for one hair pin, or perhaps a different hair color. Would you just hang out with this person as though nothing were abnormal, or would you find it...well, a little creepy?
Realistically speaking, the canon characters would probably be as creeped out as you are.
Canon relationships are not made to be broken.
So your character has spotted one of the canon characters, and has fallen for him...but he's happily married, they both love each other very much, and she's in perfect health. And for some reason or another, you're starting to think "...but my character is better for him! Why can't I put them together!?"
Remember what I said about forcing relationships? Simply changing things because you can is not a good idea.
Occasionally a novice writer will attempt to "remedy" the problem by causing some kind of terrible accident with the person "in the way" of their character's relationship. This is a bad idea. Killing off the canon love interest is an obvious sign of author interference, as well as a blatant failure at understanding human psychology - a person in mourning over such a situation will likely not pursue another relationship with minimal coaxing. It takes far more time than a fanfic is likely to cover.
So, what is the solution? There is none, because it is not a problem. Canon relationships are there, they are to be worked with, not against. Again, remember who the guest is.
Your character is not a canon character's one true love.
If the only reason you're creating a fancharacter is to pair him/her with a canon character, stop. Put the pencil down now and back away. If your plan for your character is for him/her to be permanently paired with a canon character, cut that part out immediately. I certainly hope there is something left to your character's story after this.
Regardless of how well your character is developed, or your true intention behind the act, most viewers will assume that your sole reason for this pairing is wish fulfillment. You do not want this. If your sole reason is wish fulfillment...well, as mentioned before, keep it in your drawer. We don't want to see it. Just because other people do it all the time doesn't mean it's a good idea - just look at some of the more common reviews of the act on fanfiction sites.
Short-term relationships must be evaluated on a case-by-case basis. Obviously no reasonable reader will hold anything against you if your female character ends up in a relationship with Captain Kirk for a day or two. However, if the character you have in mind has never shown any interest in a romantic relationship, even a short-term relationship might not be in your best interest.
The canon characters are still the best at their jobs.
Your character is allowed to have talent. Your character is even allowed to be a rival to maybe one canon character, for a reasonable length of time. However, the canon character must always win. Even if you absolutely despise that character, they're still canon, and your character is not.
Your character cannot "fix" your least favorite character.
Even if the better part of the fandom hates that character, a character's canon behavior absolutely must be respected. We all must learn to live with people we dislike; when we write fanfiction, the same goes for characters. Think of it this way: it may not be enjoyable to write a certain character in-character, but if nothing has gotten him/her to change his/her ways so far, then why is it realistic for your character's presence to magically do it? What makes it believable?
No character is "just that wonderful," sorry. If the better part of the fandom hates the character you wanted to change, anyway, then make his/her role minor, send him/her on "vacation" for the duration of the fanfic, or better yet, play with that character so s/he works out to be better balanced than s/he is in the canon, without making drastic changes to his/her personality. It can be done!
Your character is not a god.
Your character may be strong. Your character may be talented. In a universe where supernatural abilities are common, your character may have some rather powerful ones. However, your character is not infallible, and again, must never overshadow the canon characters. If the canon characters are (or in canon, would be) jealous of your character's abilities, there is a problem.
Finally, and most importantly...
Have fun with your writing!
It may seem like less writing advice, and more of a silly encouragement, but actually it is very important - readers often can tell when an author has stopped enjoying their writing. When writing becomes a drudgery, and you are only continuing to please a fanbase, your writing may become stiff, or dull, or perhaps just absurd - in any case, the result tends to be far from pretty.
Yes, there are many things to keep in mind when writing fanfiction. Yes, there are lots of things to worry about when adding a fancharacter into the mix. Revision does not have to be painful, and with practice, balance will come somewhat naturally. Just write what you enjoy; as long as you enjoy it, the rest of the guidelines should not be too hard to follow.