Post the code you now have and explain exactly what it is given and what it is supposed to do. Remember that I know virtually nothing about the what this signal you are counting represents in the real word. See this post for details of how to post code or flows - How to share code or flow json