Tail movement in squirrels is communication, and it covers several different messages depending on context.
A flicking tail can be part of courtship display, and it also functions as an alarm. Squirrels that have finished feeding have been observed wagging afterwards, which may indicate they are full or advertise a food source to nearby squirrels — a useful bit of information in a shared territory.
Anxious or agitated squirrels wag frequently. There is also a rather remarkable regional adaptation: Californian ground squirrels force blood into the tail when threatened by a rattlesnake, raising its temperature. Rattlesnakes hunt using infrared sensing, so a warmer tail presents a bigger, more confusing target. The response does not occur with snakes that lack that ability.
So the same motion can mean "I am courting you," "there is food here," or "back off" — read the situation around it.