Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 23:27:00 +0000



[Programming Help] - Scope of Persistent Variables in sc.SetDefaults Code Block

View Count: 337

[2023-06-12 18:44:56]
SavantTrader - Posts: 110
The ACSIL documentation on persistent variables states:

You can get and set persistent variables in the sc.SetDefaults code block at the top of the study function.

However, when I set (create) PV's in the sc.SetDefaults block:

if (sc.SetDefaults)
{
[... snipped ...]

int& crowned = sc.GetPersistentIntFast(1);
return;
}

The compiler complains they're not visible elsewhere:

scsf_AuctionStudy(SCStudyInterfaceRef)':
SavantStudies.cpp:3330:3: error:
'crowned' was not declared in this scope; did you mean 'round'?
3330 | crowned = 0;

Can someone explain this to me? What is the purpose of setting (thus creating) persistent vars in the SetDefaults code block if they have no visibility outside the block?
[2023-06-12 18:56:07]
Sierra_Chart Engineering - Posts: 17198
This is really is C++ programming question. It is not Sierra Chart specific at all.

You have to make your own decisions on what you want to do.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-06-16 00:38:01]
ForgivingComputers.com - Posts: 960
Can someone explain this to me?

Yes.

You can get and set persistent variables in the sc.SetDefaults code block at the top of the study function.

The documentation is technically correct. It just means if you want to get/set them in the block, you will also need them declared somewhere else to be useful.
[2023-06-17 01:06:47]
SavantTrader - Posts: 110
Thank you, Brad... your response more closely answers the question I was asking.

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

Login

Login Page - Create Account