All trades are executed on a FIFO basis(First In First Out basis), which means the shares that are bought first are sold out first. Here, when you sell out 5 shares at 358, the first 5 shares bought at 360 are sold out. You take an intraday loss of Rs.10.
Shares left are:
4 stock at the price of 355.50 = 4355.50 = 1422
1 stock at the price of 355 = 1355 = 355
plus you buy again,
4 stock at the price of 354.50 = 4354.50 =1418
2 stock at the price of 354 = 2354= 708
You new average price is 354.82 for the 11 shares that are still present in your account and you’ve taken an intraday loss of Rs.10 for the 5 shares bought and sold.
Are you sure it is always FIFO? I recently noticed that in one stock my first lot was sold where as in the other one my last lot was sold. I guess it selects based on selling price higher/lower compared to first/last lot.
Was it a bug or is this the logic by which average is calculated?