2 of 3 formatting

A letter of recommendation absolutely does not have to be from someone at your university. It should be from someone you have collaborated with. In general, a letter of recommendation will be most valuable if:

  1. It can speak to your potential as a researcher: letters from supervisors of research projects are much more valuable than letters from people who have only had you in class

  2. It is written by someone well known in the field that you are attempting to enter. When this person says you have potential to be a researcher, it is much more credible if they have experience working with excellent researchers in the field.

  3. It is written by someone who knows you well. They should be able to point to specific things you have done with them, specific conversations you have had, specific ideas you have had.

You should pick your letter writers by seeing how well they optimize these two properties. It won't matter if they are at your home institution or not. The only reason not to get a letter from "someone you have collaborated with online" is if they don't satisfy these criteria. In particular, I might be concerned that they don't know you well enough if you have never met them.

That being said, it might raise a red flag if none of your letter writers are from your home institution. But if you have one of these, that should be enough.