If a child was born in for example India and moved to America around age 5, but still spoke their native language at home what age would they lose their accent? And then maybe when they are 12 they move back to India and are only speaking their native tongue would they gain their accent back at all?
There are many factors, time spent in each language, consistency and exposure to each (at school, at home, at work, with friends/family).
There seems to be only one change that makes it considerably hard to change ones accent and that is puberty. Before puberty it is very easy to get and maintain a native speaker accent in a second language, but afterwards it takes lots of time and training (with study and practice, grammar and vocabulary don't seem to be a problem after puberty). There is no biological mechanism yet discovered that comes close to explaining this.
If you spoke a language fluently as a child, even if you stop using and hearing it before puberty, you shouldn't have much problem with re-establishing fluency later in life and getting rid of any accent from the in-between language. If you entirely quit the language at 5 years old, because that is so young, you may have some difficulty, but it won't be like entirely learning a new language sound-wise.
One anecdote that shows this is Henry Kissinger, a former US Secretary of State. He moved with his family to the US from Germany at age 15. He has a very noticeable German accent. His brother, Walter Kissinger, is two years younger and has virtually no accent in English.
I am not aware of any studies on this topic, probably because it is highly based on the circumstances.
Usually when a child is brought up with multiple languages, then it has no foreign accent in any of them. The older that child gets before it studies a new language, the more likely it is to have an accent. I cannot back this up with my own experience, but I know a lot of people who can (e.g. look @A.Toumentsev's comment).
Another reason why it's hard to give a direct answer is because some languages sound more similar to others and are thus easier to learn without having an accent. My fiancee is Colombian, but the first time she spoke Bavarian sounded almost perfect. This is true for most Spanish and Italian speakers. On the other side, even though Bavarian is a Germanic language, if a German speaks Bavarian it just sounds horrible and you can hear a very thick accent. It takes a long time of practice before it sounds good.
Determination is also a reason. Some people only care about learning a language so they are understood, while others want to sound like a native. That means that some people are never accent free and others sound almost like natives only after a few months. I know plenty of people who learn a language just to be understood, without trying to adopt a native accent (though I don't find that objectionable). I for one tried to get an American accent when I started to learn English and I came pretty close (it probably used to be better than it is now), up to a point where Spaniards told me that I have an English accent in Spanish.
Lastly, it all depends on the amount you speak and listen to natives. If you only ever talk a language with others who are foreign to the language or if you are only ever writing that language, then the time required to loose your accent will increase even more.
Personally I think one should make an effort to learn somebody else's language well, but keep a slight accent, it makes you likable ;)
Accent, by definition, is a set of habits.
In other words, a person can be comfortable with a certain set of language-related habits and, when they need to speak in another language, they naturally bring their existing habits to how they speak the second language. This is what accent actually is.
Say, phonetically, if one continuously exercise both rolling
/r/ and postalveolar approximant
/r/ (like in Hindi and English, correspondingly) or both
/w/ (the latter is rare in Hindi), they have much greater chance of accent-less speech.
Note however, the accent is not only a phonetic phenomenon; it can also be in how the speaker constructs phrase, uses conjugations, etc. Yet another important factor is using language-specific idiomatic expressions as a result of cultural exposure.
The factor of age works just like for any other habit, allowing the person to grasp knowledge/habits faster.