Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 13:04:57 +0000



Post From: How to reference Persistent Variables from a different chart.

[2015-04-21 03:49:23]
Sierra Chart Engineering - Posts: 104368
Here is an example which should make this more clear:
SCSFExport scsf_GetStudyPersistentVariableFromChartExample(SCStudyInterfaceRef sc)
{
  SCInputRef ChartStudyReference = sc.Input[0];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "Get Study Persistent Variable from Chart Example";
    sc.AutoLoop = 1;
    sc.FreeDLL = 0;

    ChartStudyReference.Name = "Chart Study Reference";
    ChartStudyReference.SetChartStudyValues(1, 0);

    return;
  }

  //Set persistent float variable with a value of 100 using integer key 1.
  float & PersistentFloat = sc.GetPersistentFloat(1);
  PersistentFloat = 100;

  
  // Get a reference to a persistent variable with key value 100 in the chart
  // and study specified by the "Chart Study Reference" input. Assuming the
  // "Chart Study Reference" input is referencing this particular chart and
  // study instance, then FloatFromChartStudy will equal 100.

  float & FloatFromChartStudy = sc.GetStudyPersistentFloatFromChart(ChartStudyReference.GetChartNumber(), ChartStudyReference.GetStudyID(), 1);


}

The persistent variable is being set and get within the same function but this works across charts and studies as well. Just make sure you use the same Key value.
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: 2015-04-21 03:52:42