Understanding the execution cycle of the trade script and carrying over state

Hello,

Can some one help me to understand how the script gets executed? I am assuming that it is on the basis of periodicity we select. If that is the case, is it possible to maintain variables (defined using SET) across successive invocations? Any example or pointer on doing this?

Unfortunately, based on reading through the documentation, this doesn’t seem to be possible. Just seeking confirmation.
As an alternative, is it possible to plug in C# code into PI? PI bridge might give this, but I didn’t see any documentation.

Regards!

As of now you can only use tradescript for writing conditions in pi