It's called a weighted average.
1000 X 10 = 10000
+4000 X 5 = 20000
So you have 30000 from 5000 shares. Average? $6
1000 x 10 = 10,000
4000 x 5 = 20,000
30,000 / 5000 = $6 average
30000/5000
Say I buy 1000 shares of stock at $10. Then I buy another 4000 shares of the same stock at $5. How would I get the average?