Maybe you can try using two PE:
1) With the first PE you can retrieve the events when the tag changes to the required value (Event-Based):
if (prevval('TAGNAME','*')<>'TAGNAME' and 'TAGNAME'="ON") then 'TAGNAME' else NoOutput()
2) In the second PE you only need to count:
Thank you very much for your response, I implemented it without problems.
Thank you very much again.