Actually there IS a secret!
Get some double-sided scotch tape and put it directly in between the cord and the mag. Wrap with colored duct tape or 100 MPH tape and you're good to go!
The double-sided tape provides another surface of adhesion so the cord doesn't pull out of the tape. Some guys tie knots to prevent it, but that looks ridiculous, untidy, and makes it difficult for multi-mag pouches.
I also put a 1x1 inch square of 3M grip tape on the lower front edge of the mag to provide better grip. I actually use it more than the cord but I don't want to take my mags apart again to get the cord out of all 11 of my mags.