custom field to count open tasks

custom field to count open tasks

Hi there.
is there a way to have a customized field to count how many open tasks this lead/opportunity has?
detail:
this field start with 0, when you creat a new open task, and save, then this field become 1, if you complete the task, it become 0 again.