Login Page - Create Account

Support Board


Date/Time: Sun, 05 May 2024 10:25:20 +0000



Post From: Referencing to Persistent Variable by name NOT working *URGENT*

[2016-02-22 09:26:18]
User972044 - Posts: 154
Hello there,

I am having a lot of trouble working with Persistent variables. I have read all the documentation regarding the method of creating persistent variables and setting and getting values from the persistent variables via sc.SetPersistentInt() and sc.GetPersistentInt() and also int& variablename = -> sc.PersistVars->Integers[0] using intergers for examples if I use a specific variable name via "int& variable_name". The problem is I want to give a default value to a persistent value the FIRST time around ONLY and for the subsequent times, I want the persistent variable to be updated by other values as dictated by my program. So how do I do that or is there anyway to do that? Right now, either I am not being allowed to give a default value to the persistent value to begin with if I use the statement "int& variable_name = sc.PersistVars -> Integers[0];" or "int& variable_name = sc.GetPersistentInt(0);", whenever I reference variable_name, I will get a random number that is set by Sierra Chart which is not useful at all to me. But if I set a default value for the persistent variable via "sc.SetPersistentInt(0,0);" for example to set the default value to 0, every single time when the study runs, it keeps resetting the variable value to 0 and every time when I reference it by the variable_name after int&, the value is not accurate. It doesn't work if I put the sc.SetPersistentInt in the sc.SetDefaults block, it just gets ignored. I use Autoloop = 1 so maybe I need to use some kind of index to determine when my study is fist loaded onto the chart? Which index value should I use and how do I know or get that index value?

To illustrate: Right now, when I write my codes as follows:

int& variable_name = sc.GetPersistentInt(0);

sc.SetPersistentInt(0,0);

both of these above statements outside of the sc.SetDefaults() block and then

if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
{

  variable_name += 1;

}

I only get the result for the variable_name remaining at the value of 1 when it's supposed to incremented with the closing of each bar and the reason why it's not being incremented is because it gets reset back to 0 by the sc.SetPersistentInt(0,0) statement every time when the program runs with the update of each bar. And I don't want that. I only want sc.SetPersistentInt() statement run the FIRST time when the program is loaded onto the chart and that's it. Each bar after, it the variable_name should be updated by the increment statement. How do I do that please?

Thank you for your help in advance.
Date Time Of Last Edit: 2016-02-22 09:41:42