In Canada, calculating the capital gain from selling a partial position is done based on average cost, as opposed to using First-In-First-Out (FIFO) or other rules distinguishing units based on date acquired. (e.g. Canada doesn't contrast "short-term" vs. "long-term" gains like the U.S. does.)
New units and old units in your non-registered accounts are all considered part of the same position when it comes to figuring the capital gains. The cost per unit you need to calculate to determine your capital gain is known officially as the Adjusted Cost Base, or ACB.
From a simplistic perspective – i.e. where no distributions were received – the ACB per unit is the average price paid (including commissions paid to acquire the shares or units.) From this perspective, and probably incorrect for a mutual fund, your ACB would be:
((100 * $10) + (200 * $5) + (50 * $20) + (100 * $10)) / 450 = ($4000 / 450) ~= $8.8889 per unit
For typical company shares paying typical dividends, the ACB calculation would likely end there, as dividends are not a factor in the gain calculation – unless you are reinvesting your dividends.
The ACB calculation is more complicated for mutual funds, exchange-traded funds, closed-end-funds, and income trusts, due to the kinds of distributions made by such investment vehicles. Distributions are frequently composed of more than just dividends.
Fund distributions often contain components like return of capital (ROC) and distributed capital gains, i.e. when the fund itself realizes net gains on transactions in the portfolio and passes them through to you. Return-of-capital distributions reduce your ACB. Capital gain distributions increase your ACB. You don't want to be taxed twice on distributed gains, so be sure to figure your ACB correctly.
You can know if your fund issued those specific kinds of distributions by looking at the tax slips received, checking with the fund company (e.g. their web site), or your broker/advisor.
So, imagine if, in your example, you had also received $600 worth of distributions, identified as $80 dividends, $20 "other" income (e.g. interest), $450 return-of-capital, and $50 capital gains. Then, your ACB per unit would then be:
($4000 - $450 + $50) / 450 = $8.00 per unit
And so if you sold 300 units at $10 each, the net gain on the sale would be:
300 * ($10 - $8) = $600
(And your $80 dividends and $20 "other" income would be taxed separately on your return, at their respective tax rates.)
I hope this helps. Here are some additional resources to check out: