Login Page - Create Account

Support Board


Date/Time: Sun, 12 May 2024 18:20:47 +0000



Persist Variables

View Count: 2867

[2017-06-27 05:39:37]
User972044 - Posts: 154
Also I am using persistent variables via the following manner:

int& variable_name = sc.PersistVars->Integers[0]; and then variable_name = 2;

It worked all fine last year. According to your documentation, https://www.sierrachart.com/index.php?page=doc/ACSIL_Members_Variables_And_Arrays.html#scPersistVars:

Available Persistent Variables

sc.PersistVars->i1 through sc.PersistVars->i16. Integer data type.
sc.PersistVars->f1 through sc.PersistVars->f16. Single precision floating-point data type.
sc.PersistVars->d1 through sc.PersistVars->d24. Double precision floating-point data type.
sc.PersistVars->scdt1 through sc.PersistVars->scdt8. SCDateTime variable type.
sc.PersistVars->Integers[64]. Integer data type.
sc.PersistVars->Doubles[64]. Double precision floating-point data type.
Example

// You can use references to give the persistent variables
// more descriptive names that you can use.

// MyCounter is a reference to sc.PersistVars->Integers[0]
int& MyCounter = sc.PersistVars->Integers[0];

// MyAverage is a reference to sc.PersistVars->Doubles[2]
double& MyAverage = sc.PersistVars->Doubles[2];

// We are using the reference we made above.
// This is the same as: sc.PersistVars->Integers[0] += 1;
MyCounter += 1;

// We are using the reference we made above.
// This is the same as: sc.PersistVars->Doubles[2] = (10.0f+24.0f)/2.0f;
MyAverage = (10.0f+24.0f)/2.0f;

// We are using the reference we made above.
MyAverage = (sc.Subgraph[2][sc.Index]+24.0f)/2.0f;
Resetting Persistent Variables Example

if (sc.Index == 0)
{

// When there is a full recalculation of the study,
// reset the persistent variables we are using
sc.PersistVars->Integers[0] = 0;
sc.PersistVars->Integers[1] = 0;

sc.PersistVars->Integers[2] = 0;
sc.PersistVars->Integers[3] = 0;
}

this format is available for backward compatibility so everything compiled but when I try to change values to the persistent variables, the new values did not get set and the default value for persistent variables are supposed to be 0.00 but it's a ridiculously huge number such as these:

Chart: Replay 1.0X: XXXX 60 Min #2 | Study: Custom DLL Study | Buy PositionData Quantity: 0 TradeS_OrderQuantity: 0 Trade_PosL: 1086121984 | 2017-06-27 05:18:06
Chart: Replay 1.0X: XXXX 60 Min #2 | Study: Custom DLL Study | Sell PositionData Quantity: 0 TradeS_OrderQuantity: 0 Trade_PosS: 1086121984 | 2017-06-27 05:18:06
Chart: Replay 1.0X: XXXX 60 Min #2 | Study: Custom DLL Study | | 2017-06-27 05:18:06

My two persistent variables are Trade_PosL and Trade_PosS and they are NEVER set to 0 to begin with. They always stay as 1086121984 throughout the running of the whole program and because of this problem, my program is not sending any trades.

Please investigate and advise.
[2017-06-28 17:25:00]
User972044 - Posts: 154
Can I have an update on this? Are you still investigating? It's been two days since I reported this issue. Just to let you know this issue is still there after I upgraded Sierra Charts to the newest version. I was able to run my codes and the persist variables still did NOT get initialized to 0 as per your documentation and always stated as 1086121984.
[2017-06-29 17:59:12]
Sierra Chart Engineering - Posts: 104368
You must be doing something wrong from your side.

If you reset your persistent variables you are using back to 0 using code like this, then they will be set to zero for sure.
if (sc.Index == 0)
{

// When there is a full recalculation of the study,
// reset the persistent variables we are using
sc.PersistVars->Integers[0] = 0;
sc.PersistVars->Integers[1] = 0;

sc.PersistVars->Integers[2] = 0;
sc.PersistVars->Integers[3] = 0;
}


My two persistent variables are Trade_PosL and Trade_PosS and they are NEVER set to 0 to begin with. They always stay as 1086121984 throughout the running of the whole program and because of this problem, my program is not sending any trades.
As long as you are displaying the values properly using the proper formatting function and formatting specification, persistent variables even without expressly resetting them in a study function, are at 0 when a study is applied to a chart or the Chartbook containing the chart which contains the study, is opened.
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: 2017-06-29 18:01:38
[2017-06-29 20:21:06]
User972044 - Posts: 154
As long as you are displaying the values properly using the proper formatting function and formatting specification, persistent variables even without expressly resetting them in a study function, are at 0 when a study is applied to a chart or the Chartbook containing the chart which contains the study, is opened.

I thought the proper formatting might be the cause too so I checked countless times already on what I did. These are the codes that I am using to display values of my persist variables Trade_PosL and Trade_PosS:

SCString Message7;
    
Message7.Format("Buy PositionData Quantity: %d TradeS_OrderQuantity: %d Trade_PosL: %d", PositionData.PositionQuantity, fabs(TradeS.OrderQuantity), Trade_PosL);  
  
sc.AddMessageToLog(Message7, 0);

SCString Message8;
    
Message8.Format("Sell PositionData Quantity: %d TradeS_OrderQuantity: %d Trade_PosS: %d", PositionData.PositionQuantity, fabs(TradeS.OrderQuantity), Trade_PosS);  
  
sc.AddMessageToLog(Message8, 0);   

I know you don't provide Programming help and I am not expecting you to. I am just posting these codes here to show you what I did. I have used the same formatting to display other data and they are all displayed fine except these two persist variables. That's why it's so baffling and I am spending the time to create a support ticket for it. If you see something that's amiss, I would appreciate it if you can point it out. If not, you can just leave them to be.

if (sc.Index == 0)

{

// When there is a full recalculation of the study,

// reset the persistent variables we are using

sc.PersistVars->Integers[0] = 0;

sc.PersistVars->Integers[1] = 0;

sc.PersistVars->Integers[2] = 0;

sc.PersistVars->Integers[3] = 0;

}

This is what I use in my codes to reset the persist variable:

if (sc.Index == 0)
{

Trade_PosL = 0;

Trade_PosS = 0;

}

Very simple codes and they worked fine all last year but for some reason not anymore for this year. I will try your suggestions to see if they work. Hopefully they do and I won't have to post here again.
Date Time Of Last Edit: 2017-06-29 20:23:06
[2017-07-05 16:40:11]
Sierra Chart Engineering - Posts: 104368
We see what one of the problems is. You are using fabs instead of labs. You need to use the function that returns an integral type, when using %d.
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: 2017-07-05 16:40:35
[2017-07-06 02:59:05]
User972044 - Posts: 154
That certainly fixed the display problem for the TradeS.OrderQuantity but TradeS.OrderQuantity is NOT the persistent variables that I was having issues with and created this ticket for; the TradeS.OrderQuantity was just a member of the s_SCNewOrder class. Anyway, persistent variables are now working miraculously even though I did NOT change anything in my codes. I'll consider this issue resolved.
Date Time Of Last Edit: 2017-07-06 02:59:19

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

Login

Login Page - Create Account