One of the loading screen tips states (paraphrasing) that the Mega Ring charges when you command your Pokemon to use a move and the amount that it charges by is determined by "how close you are to your Pokemon." Through casual testing it seems like it might be referring to the physical distance your trainer is standing from the active Pokemon, but it's hard to tell and doesn't seem entirely consistent, and maybe I'm misinterpreting the definition of "close" that's being used here (maybe it means something like friendship?).
I would prefer an answer that can quantitively describe exactly how the game's code calculates the amount of charge from a technical perspective and what factors are relevant. This would help optimize battle since knowing how the mechanic works would let you charge the ring more efficiently.