Support Board
Date/Time: Sat, 01 Mar 2025 06:59:24 +0000
[User Discussion] - Accessing persistent variables from another study on recalc
View Count: 814
[2021-09-18 18:50:39] |
User920967 - Posts: 62 |
I have a study in which I define a persistent variable to be accessed by another study. For the sake of this example that variable is set to equal the current index on the chart, sc.Index. The expected behavior is that this value updates with each new bar. I have subgraphs on both studies outputting the variable's value for comparison. During recalculation, sc.GetPersistentIntFromChartStudy exclusively returns the final value for the persistent variable, in this case the last index on the chart. This is true for all bars on the chart. The 'source study', meanwhile, outputs the index corresponding to each new bar, as expected. I've used sc.Index here for simplicity, but pattern holds true for other variables. Is this the expected behavior for sc.GetPersistentIntFromChartStudy during recalculation? i.e. Will this only return the value corresponding to the final bar on the chart? Thanks in advance, all help is very much appreciated. Source study (ID3) int& idx = sc.GetPersistentInt(120); idx = sc.Index; idx_sg[sc.Index] = idx; //Outputs the current index on both recalc and replay Destination study PV_sg[sc.Index] = sc.GetPersistentIntFromChartStudy(1, 3, 120); //Outputs the final bar's index |
[2021-09-21 02:17:41] |
User920967 - Posts: 62 |
Bumping in case fresh eyes have insight. I’m not looking for programming help, just trying to understand the limits of sc.GetPersistentIntFromChartStudy() Specifically, can a persistent variable defined in one study be read by another on recalc? Or can this only be done in replay / live? |
[2021-09-21 08:04:48] |
User907968 - Posts: 833 |
Working with ACSIL Arrays and Understanding Looping: Study Function Calling and Threads Study calculations, the calling of a study function, the updating of a chart, and the drawing of the chart, all occurs on a single thread and this is the main thread of Sierra Chart.
Only one study function can run and be called at the same time. Each study is calculated one at a time and according to a calculation order determined by Sierra Chart. "Specifically, can a persistent variable defined in one study be read by another on recalc?" Above suggests not. |
[2021-09-21 12:39:32] |
ForgivingComputers.com - Posts: 1015 |
Is this the expected behavior for sc.GetPersistentIntFromChartStudy during recalculation? i.e. Will this only return the value corresponding to the final bar on the chart?
It makes sense to me that the persistent variable on the source chart is whatever it was when last calculated, meaning the last bar. There is no history of the persistent variable unless it is also a subgraph, so the only way you are going to get something other than the last bar is to reference a subgraph with an index (or SCDateTime variable in the case of studies on other charts) to get the value associated with the bar. |
[2021-09-24 15:40:30] |
Sierra_Chart Engineering - Posts: 18607 |
Is this the expected behavior for sc.GetPersistentIntFromChartStudy during recalculation? i.e. Will this only return the value corresponding to the final bar on the chart? Yes this will be the case during a full recalculation.
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 |
To post a message in this thread, you need to log in with your Sierra Chart account: