That's actually a very common question
. The answer is that you get average prices of all your purchases of this particular stock, and subtract it from the sell price, no matter how many shared you sell. In your example your average price comes to $3.50 per share, which means that when you sold 1,000 shares at $5.20 you made profit of $1.70 per share for a total profit of $1,700.
I hope this helps.