As a rough guideline, you get the most trade if half the ports within reach of your fleet are yours and have trade goods, while the other half (with or without trade goods) belong to countries you can trade with (not at war with).

For instance, suppose that there are 8 ports within range of your fleet. If you control 1, it can only sell goods to 7 ports. If you control 7, then each one can sell goods to 1 port, so you get the same amount of profit because 7 X 1 = 1 X 7

However, if you control 4 of the ports, then each of them has 4 trade partners, 4 X 4 = 16 trade relationships, which is more than twice as good as owning just one port or all seven of them.

That isn't taking into account that some provinces have more valuable products to trade. It also is not taking into account that you can't sell a product to another port if it is in a province that produces the same product. So it is only intended as a rough measure.