Support Board
Date/Time: Sat, 14 Jun 2025 07:22:05 +0000
[Programming Help] - Reading Persistent variable in other study
View Count: 1367
[2020-06-13 20:35:04] |
User53601 - Posts: 106 |
I try to use Persistent variable instead of Global variable, as it was recomended on other place. To share variable accross multiple studies I am trying to use Persistent variable in conjuction with SetPersistentIntForChartStudy GetPersistentIntFromChartStudy Persitent variable is declared in Study01, then nonzero value is set in Study02 ( by SetPersistentIntForChartStudy). I would expect to read the nonzero value in Study03 (by GetPersistentIntFromChartStudy). However, the value is not returned, resp. the returned value is zero. Could you please help to figure out what I am doing wrong? Here is my code: STUDY 01 int& g_LongMarkersCount = sc.GetPersistentInt(1); STUDY 02 sc.SetPersistentIntForChartStudy(sc.ChartNumber,1,1,33); STUDY 03 int g_Counter_Markers_Long = sc.GetPersistentIntFromChartStudy(sc.ChartNumber,1,1) ; Here is the problem, I expect the returned value should be 33, but instead the returned value is zero. |
[2020-06-16 13:34:38] |
ForgivingComputers.com - Posts: 1066 |
Your code for Study 02 is not correct. Just create another persistent var for this study and then study 03 should work, assuming Study 02 is ID1. int& NewPersistentVar = sc.GetPersistentInt(1) = 33;
If Study 02 is ID2, then you would need to change that in Study 03: int g_Counter_Markers_Long = sc.GetPersistentIntFromChartStudy(sc.ChartNumber,2,1) ;
Study 01 has no knowledge of the new value unless you do the same thing and set the value the way study 03 does. |
[2020-06-16 15:01:12] |
User53601 - Posts: 106 |
thank you for your effort however I am not sure this is what I need. My intention is to have a dedicated persistent variable which can be shared accros all the studies on the chart. By other words, persistent variable which substitutes the global variable. The idea behind is, that I have multiple studies, each displays some Subgraphs ( for example DRAWSTYLE_POINT, DRAWSTYLE_POINT). These Subgraphs overlap and that is what I try to avoid. That is why I want to control the position of Subgraphs in particulat studies by help of that persistent (or global) variable. My understanding is, that by means of these two functions: SetPersistentIntForChartStudy GetPersistentIntFromChartStudy it is possible to set and get the value of some dedicated Persistent variable, here and there in all the studies on the chart. |
[2020-06-16 16:11:07] |
User907968 - Posts: 840 |
Here is the problem, I expect the returned value should be 33, but instead the returned value is zero.
1) Check that the StudyGraphInstanceID is correct i.e. '1' in your case does it refer to the correct study 2) Check the calculation order of the studies It is possible to get and set the variables using the code in post #1 Date Time Of Last Edit: 2020-06-16 16:11:21
|
To post a message in this thread, you need to log in with your Sierra Chart account: