I believe Zettt has nailed an answer (nice one Zettt). I want to extend this to a bigger picture.
There may be an algorithm but I don't know of it specifically as an equation. This is all about mixing sound tracks like you are a great chef cooking up an unbelievable dish. Start with the finest ingredients, in this case sounds you have already recorded that are clear, and do not clip at all. Your goal is to mix all the ingredients so you can taste each one without it overwhelming the others or losing its identity. This is why your ears like your taste buds will be the most important guide. Consider how a music arranger puts together a score for an orchestra. Take into account how the timbre of each instrument will have both an individual composite of harmonics and how these change over the entire instrument's range.
For instance if I was mixing violins and a triangle, I already know that a triangle has a very odd set of harmonics, and I won't have to give that track much gain at all for me to hear it clearly. You rarely see a percussionist hitting a triangle very hard because its tone is so differently constructed that a slight hit will cut through the rest of the orchestra very easily.
Mixing is not about adding one thing on top of each other, it's about balancing a blend that you can hear everything in the mix. Yes, you have to keep the gain under 0 dB, you can not have any clipping, not any or else you just burnt your dish.
You can think of the spectra envelope of each instrument as a guide but allow for your ear to tell you when it's right.
What controls do you have when you are mixing tracks?
For one you have the gain of each track, then you have where it lives in the stereo field, is it best in the center? 15% to the right, 20% to the left?
How you control the way an overall sound envelope is another factor, does it have a fast attack, does it fade away, do you want to have it ride in the distance, or bring it up front?
Another thing to think about is the depth, how much reverb if any, this will also color the sound. Notice as you add reverb you loose some highs and it sounds like it's further away, is that what you want?
Mixing sound is like making a great meal, you start with the best ingredients and allow each to stand out without overwhelming the others or getting lost. Be aware of your instruments spectra, envelopes, and how all this changes over the entire range. Be aware of what controls you do have and how these can be best set for your desired results.
Finally, don't be afraid to try new things, take risks, you can always change it back before you make your master.