Login Page - Create Account

Support Board


Date/Time: Sat, 28 Dec 2024 08:35:31 +0000



[Programming Help] - Use of Global variable in other Study

View Count: 1221

[2016-04-18 19:16:42]
User53601 - Posts: 105
Hello,

I declared global variable in StudyA:

SCDLLName("StudyA")
int GlobalLastSeparatorIndex;


Then I want to get the value of this global variable in StudyB:
int Test = GlobalLastSeparatorIndex;


Build Output gives this message:
error: GlobalLastSeparatorIndex was not declared in this scope


How to make StudyB aware of the Global variable?

thank you
[2016-04-19 01:49:19]
Sierra Chart Engineering - Posts: 104368
It really is best to use persistent variables for this:
https://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_Functions.html#scGetPersistentInt

And then use this function to get the persistent variable from another study:
https://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_Functions.html#scGetStudyPersistentIntFromChart
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
[2016-04-20 21:15:49]
User53601 - Posts: 105
I used your recommendation and it helped me to move forward with my task. thank you.


However, I still have a question, I think it somehow relates to the first question.

I need to do some processing during recalculation (and then I want to display the result on bars being recalculated):

StudyB is processing an input ( sc.Index value) from persistent variable in StudyA .

The issue is, that the value transferred to Study B is always the same on the recalculated bars,
but it should be different value for each bar ( the sc.Index ).
Seems that all the recalculated bars get as an input the same value, the sc.Index of the last recalculated bar.

STUDY A
int& TestIndex = sc.GetPersistentInt(5);
sc.SetPersistentInt(5, sc.Index);

STUDY B
if ( sc.IsFullRecalculation )
{ int AAA = sc.GetStudyPersistentIntFromChart(sc.ChartNumber,1,5); }

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

Login

Login Page - Create Account