Login Page - Create Account

Support Board


Date/Time: Thu, 19 Sep 2024 21:45:35 +0000



Storing values in containers when using manual looping?

View Count: 2766

[2013-07-19 00:21:52]
User45685 - Posts: 36
Dear Support,

A couple of days ago I asked about data retention while using sc.autoloop=1 and you refered me to persistent variables. This is fine and I have a working solution in place.

From a theoretical standpoint i have a different question; Assuming I'm using a manual for loop instead of autolooping and i place the std::list storage container outside of the for loop, will the data be retained?

SCSFExport scsf_Example(SCStudyInterfaceRef sc)
{

if (sc.SetDefaults)
{
// Set the configuration and defaults
Settings here

}

//Storage of information needed between calls
std::list<int> Container1;
std::list<float> Container2;

//Dataprocessing here
for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
{
//Calculation/Drawing code in here
Container1.push_back(calculatedvaluehere);
}


//END

}


As per this (crude) example, would Container1 and Container2 retain the data that are inserted into it within the for loop retain their data or does the way manual looping work also include the flushing of everything outside of the for loop as it does with autoloop=1 ?
[2013-07-19 11:30:50]
Sierra Chart Engineering - Posts: 104368
The 2 containers are defined on what is called the stack, so they will be persistent until you return from the function or if they were contained in an inner {} block, until that block is exited.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2013-07-19 15:48:09]
User45685 - Posts: 36
I see, small followup question on ACSIL and sc.Updatestartindex.

The for { int i = sc.UpdateStartIndex; i < sc.ArraySize; i++) replaces the autoloop = true setting but what happens when it reaches the end of the loop? Or basically when i is not smaller than sc.ArraySize ? Will it stop and then restart the entire study and start calling the if (sc.defaults) part?

Or does the way the for loop works or more specifically the sc.updatestartindex work basically mean the loop is going to continue forever/as long as the chart is open? Because I read the documentation and I am still not quite clear on how this works exactly when the loop has performed for the last bar in the chart.
[2013-07-19 19:16:01]
Sierra Chart Engineering - Posts: 104368
This question is a C++ question and a programming question in general. When the loop is finished, the code below that will run and then the function will be exited.

For information about when the study function is called, refer to:
https://www.sierrachart.com/index.php?l=doc/doc_ACS_ArraysAndLooping.html#WhenFunctionCalled

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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2013-07-19 19:31:34
[2013-07-20 11:00:29]
User45685 - Posts: 36
Dear Sierra,

Yeah i thought that i could avoid using the persistvariables using manual looping but since once the for loop has run through all its instances i would have to use some kind of goto statement to return it to the beginning of the loop again and i have no idea what that would cause to memory usage i might aswell stick with autolooping and persistvariables =/

Request is resolved.
Thanks for all the support and patience :)

Kind regards
[2013-07-20 11:08:36]
Sierra Chart Engineering - Posts: 104368
i would have to use some kind of goto statement to return it to the beginning of the loop again and i have no idea what that would cause to memory usage
You would freeze Sierra Chart. Memory use would stay same.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

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

Login

Login Page - Create Account