Login Page - Create Account

Support Board


Date/Time: Wed, 15 Jan 2025 17:39:31 +0000



Post From: Persist Variables

[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.