1. Create an asset account for the investment. Go to Settings > Chart of accounts > New. Choose Other Asset (or Other Current Asset if you expect to sell within a year) as the account type, and give it a clear name like "Investments - [Company/Fund Name]."
2. Record the purchase. Use + New > Expense or a bank transfer, with the asset account you just created as the category, for the amount you paid (your cost basis). This moves money out of your bank account and into the investment account, it doesn't post anything to your P&L, since buying an investment isn't an expense.
3. Track the cost basis, not the market value. QuickBooks Online doesn't automatically pull live stock prices or mark the account to market. The balance in that asset account should reflect what you paid, not what it's currently worth.
4. When you sell, record the deposit. Enter the sale proceeds as a deposit into your bank account.
5. Split the deposit between the asset account and a gain/loss account. Reduce the investment asset account by the original cost basis, and record the difference (proceeds minus cost) to an income account like Realized Gain on Investments, or an expense account if it's a loss. This is the step people skip, and it's the one that makes your books actually reflect what happened.