Your for loop may have some issues as written. For instance, it will perform 271 sets very quickly. Using our NoSQL database, you can only have one value per point per millisecond. It may work with the H2 or MySQL databases, but I don't think it's what you want.
It sounds like you want some kind of if condition leading to a...
p.set(p.value + 1);
The Scripting data source is run on a cron, so if it's on pattern 0/1 * * * * ? the point would reflect 'total seconds in state' and if you wanted to zero it when the condition is lost you can...