Login Page - Create Account

Support Board


Date/Time: Fri, 29 Nov 2024 00:41:51 +0000



[Programming Help] - do standard variables reset to zero every time a study functions loops?

View Count: 391

[2023-03-15 14:55:16]
Berliner JFK - Posts: 45
I have a study function which autoloops and uses both persistent and standard variables.

The persistent variables retain their value after every loop, which is expected behavior. I've observed, though, that standard variables (e.g. int test = 1;) can also retain their value after every loop.

Is it expected behavior that standard variables do not erase/reset every time the study returns (loops)?

Thank you very much!
Date Time Of Last Edit: 2023-03-15 16:36:46
[2023-03-15 18:38:34]
Tony - Posts: 522
that happens either of these cases

1, variables are set as public (above all study functions)

2, static variables

otherwise, variables are reset every loop, for me anyway.
[2023-03-16 12:08:35]
Berliner JFK - Posts: 45
Hello Tony and thank you.

I did not find the terms public and static variables in the ACSIL documentation, but after doing some research on C++, it seems like public is the same as a global variable in ACSIL, while static is the same as a persistent variable.

But your statement about standard variables is clear, i.e. that they are reset to zero every time the function returns. Thanks again.

I believe the problem is solved now. I had a standard, non-persistent variable which was retaining it's value after my study function returned. The reason was because it was in scope, as explained by @ondafringe in a different post, and I solved the issue by explicitly resetting it to zero.

Thanks again to everyone for the help!
Date Time Of Last Edit: 2023-03-16 15:24:19

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account