Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 14:14:43 +0000



Persistent Variables Set Before SetDefaults() are Getting Reset

View Count: 1543

[2018-08-07 16:40:09]
BlakJak - Posts: 108
Hi,

I am setting a persistent variable (actually a pointer to an object I use in my study) at the start of the main function call. I do this because I need some info from the object to setup my defaults.

The problem I am finding is that when the code re-enters and tries to get the pointer to class Study back after the SetDefaults has been run, it is set to NULL again. Why and is there a way around this?

SCSFExport scsf_BidAskBubbles(SCStudyInterfaceRef sc)
{
  Study* p_Study = (Study*)sc.GetPersistentPointer(PersistentVarKeys::STUDY_PTR);

  if (sc.LastCallToFunction)
  {
    if (p_Study != NULL)
    {
      delete p_Study;
      sc.SetPersistentPointer(PersistentVarKeys::STUDY_PTR, NULL);
    }
    return;
  }

  if (p_Study == NULL)
  {
    p_Study = (Study*)new Study(sc);

    if (p_Study != NULL)
      sc.SetPersistentPointer(PersistentVarKeys::STUDY_PTR, p_Study);
    else
      return;
  }

  if (sc.SetDefaults)
  {
...

[2018-08-08 10:47:30]
Sierra Chart Engineering - Posts: 104368
We still need to test this.
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
[2018-08-08 11:12:55]
BlakJak - Posts: 108
... I should add that I am setting "FreeDLL = false" in my defaults settings.
[2018-08-08 17:57:02]
Sierra Chart Engineering - Posts: 104368
Understood but that does not change the use of persistent variables using these persistent variable functions.
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
[2018-08-09 10:12:55]
Sierra Chart Engineering - Posts: 104368
We have implemented a solution to this which will be out in the next release but we have not really thought through this carefully to see if it might have some unexpected consequences. So we don't want to make any promise as to whether it would remain.
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
[2018-08-09 20:42:10]
Sierra Chart Engineering - Posts: 104368
Update to the latest pre-release of Sierra Chart for testing. This limitation is resolved.
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
[2018-08-12 18:32:59]
BlakJak - Posts: 108
I tested this fix over the weekend and it is not working as far as my use case is requiring it.

SetDefaults() is called when you click "Add Custom Study" to the chart, and before it is even added to your chart. This means that my constructor code to create my Study object is being called and the pointer to the object saved as a Persistent Pointer even before the study is added to the chart. This is fine for me, however on the next pass when GetPersistentPointer() is called on this key, it returns NULL so my program is forced to create a new object and ultimately crashes.

I need the GetPersistentPointer() to record the pointer even if the study is just being listed as an option to add.
[2018-08-12 22:25:14]
Sierra Chart Engineering - Posts: 104368

I need the GetPersistentPointer() to record the pointer even if the study is just being listed as an option to add.

We cannot support what you want. That is just simply out of the question. Other than to provide a flag indicating that the study function is called just for the purpose of listing the available studies.
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
[2018-08-13 02:28:01]
BlakJak - Posts: 108
OK. In that case I can create a workaround using a static member function of class Study to call during the "SetDefaults()" which does not need an object to be called.

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

Login

Login Page - Create Account