You have to wait a certain amount of time b4 buying back shares if you want to off-set gains.
Otherwise it's called a wash sale,which is illegal.Please check the info As i'm not a hundred percent sure.
http://www.theaustralian.com.au/bus...n-the-wash-sales/story-e6frgacf-1225787681287