Login Page - Create Account

Support Board


Date/Time: Sat, 24 May 2025 12:33:12 +0000



Post From: Experiencing slow calculations speed when getting data from another chart study

[2023-08-03 13:49:40]
LoupyTrader - Posts: 8
Hello,
I am building an algo that needs to be split on two charts (between a main on a chart and a child study on the other) that needs to communicate multiple variables (int, floats and pointer to doubles array mainly). The child study also needs to know all the main study inputs.
I am experiencing lag when using sc.GetPersistentXXXFromChartStudy() and sc.GetChartStudyInputXXX().
I made an independent code to test the functions calculations speed, you can find it attached.
It takes the child study 3 ms (as displayed by Sierra in the chart studies menu) to get 5 inputs from main study and about 25 ms for 5 persistent variables. And I can't afford that especially when doing a replay.

Is there a better (and faster way) to communicate data from one the study to another on two different charts ?

If you require any further information, please do not hesitate.


#include "sierrachart.h"

SCDLLName("Testing Peristent Variables and Inputs From Chart Study Speed");

SCSFExport scsf_MainStudy(SCStudyInterfaceRef sc)
{
int InputIndex = 0;
SCInputRef Input_TestIntInput1 = sc.Input[InputIndex ++];
SCInputRef Input_TestIntInput2 = sc.Input[InputIndex ++];
SCInputRef Input_TestIntInput3 = sc.Input[InputIndex ++];
SCInputRef Input_TestIntInput4 = sc.Input[InputIndex ++];
SCInputRef Input_TestIntInput5 = sc.Input[InputIndex ++];

SCInputRef Input_TestDoubleInput1 = sc.Input[InputIndex ++];
SCInputRef Input_TestDoubleInput2 = sc.Input[InputIndex ++];
SCInputRef Input_TestDoubleInput3 = sc.Input[InputIndex ++];
SCInputRef Input_TestDoubleInput4 = sc.Input[InputIndex ++];
SCInputRef Input_TestDoubleInput5 = sc.Input[InputIndex ++];

if (sc.SetDefaults)
{
sc.GraphName = "Main Study";
sc.GraphRegion = 0;
sc.AutoLoop = 1;

Input_TestIntInput1.Name = "Test Int Input 1";
Input_TestIntInput1.SetInt(1);

Input_TestIntInput2.Name = "Test Int Input 2";
Input_TestIntInput2.SetInt(2);

Input_TestIntInput3.Name = "Test Int Input 3";
Input_TestIntInput3.SetInt(3);

Input_TestIntInput4.Name = "Test Int Input 4";
Input_TestIntInput4.SetInt(4);

Input_TestIntInput5.Name = "Test Int Input 5";
Input_TestIntInput5.SetInt(5);

Input_TestDoubleInput1.Name = "Test Double Input 1";
Input_TestDoubleInput1.SetDouble(1.0);

Input_TestDoubleInput2.Name = "Test Double Input 2";
Input_TestDoubleInput2.SetDouble(2.0);

Input_TestDoubleInput3.Name = "Test Double Input 3";
Input_TestDoubleInput3.SetDouble(3.0);

Input_TestDoubleInput4.Name = "Test Double Input 4";
Input_TestDoubleInput4.SetDouble(4.0);

Input_TestDoubleInput5.Name = "Test Double Input 5";
Input_TestDoubleInput5.SetDouble(5.0);

return;
}

int& r_TestPersistentInt1 = sc.GetPersistentInt(1);
int& r_TestPersistentInt2 = sc.GetPersistentInt(2);
int& r_TestPersistentInt3 = sc.GetPersistentInt(3);
int& r_TestPersistentInt4 = sc.GetPersistentInt(4);
int& r_TestPersistentInt5 = sc.GetPersistentInt(5);

double& r_TestPersistentDouble1 = sc.GetPersistentDouble(1);
double& r_TestPersistentDouble2 = sc.GetPersistentDouble(2);
double& r_TestPersistentDouble3 = sc.GetPersistentDouble(3);
double& r_TestPersistentDouble4 = sc.GetPersistentDouble(4);
double& r_TestPersistentDouble5 = sc.GetPersistentDouble(5);

r_TestPersistentInt1 = 1;
r_TestPersistentInt2 = 2;
r_TestPersistentInt3 = 3;
r_TestPersistentInt4 = 4;
r_TestPersistentInt5 = 5;

r_TestPersistentDouble1 = 1.0f;
r_TestPersistentDouble2 = 2.0f;
r_TestPersistentDouble3 = 3.0f;
r_TestPersistentDouble4 = 4.0f;
r_TestPersistentDouble5 = 5.0f;
}

SCSFExport scsf_ChildStudy(SCStudyInterfaceRef sc)
{
int InputIndex = 0;

SCInputRef Input_MainChartStudyValues = sc.Input[InputIndex ++];
SCInputRef Input_TestGettingIntInputs = sc.Input[InputIndex ++];
SCInputRef Input_TestGettingDoubleInputs = sc.Input[InputIndex ++];
SCInputRef Input_TestGettingPersistentInts = sc.Input[InputIndex ++];
SCInputRef Input_TestGettingPersistentDoubles = sc.Input[InputIndex ++];

if (sc.SetDefaults)
{
sc.GraphName = "Child Study";
sc.GraphRegion = 0;
sc.AutoLoop = 1;

Input_MainChartStudyValues.Name = "Main Study Values";
Input_MainChartStudyValues.SetChartStudyValues(1,1);

Input_TestGettingIntInputs.Name = "Test Getting Int Inputs";
Input_TestGettingIntInputs.SetYesNo(0);

Input_TestGettingDoubleInputs.Name = "Test Getting Double Inputs";
Input_TestGettingDoubleInputs.SetYesNo(0);

Input_TestGettingPersistentInts.Name = "Test Getting Persistent Ints";
Input_TestGettingPersistentInts.SetYesNo(0);

Input_TestGettingPersistentDoubles.Name = "Test Getting Persistent Doubles";
Input_TestGettingPersistentDoubles.SetYesNo(0);

return;
}

int ChartNumberOfMainStudy = Input_MainChartStudyValues.GetChartNumber();
int MainStudyID = Input_MainChartStudyValues.GetStudyID();

if (Input_TestGettingIntInputs.GetYesNo())
{
int IntInput1;
int IntInput1Result = sc.GetChartStudyInputInt(ChartNumberOfMainStudy, MainStudyID, 0, IntInput1);
int IntInput2;
int IntInput2Result = sc.GetChartStudyInputInt(ChartNumberOfMainStudy, MainStudyID, 1, IntInput2);
int IntInput3;
int IntInput3Result = sc.GetChartStudyInputInt(ChartNumberOfMainStudy, MainStudyID, 2, IntInput3);
int IntInput4;
int IntInput4Result = sc.GetChartStudyInputInt(ChartNumberOfMainStudy, MainStudyID, 3, IntInput4);
int IntInput5;
int IntInput5Result = sc.GetChartStudyInputInt(ChartNumberOfMainStudy, MainStudyID, 4, IntInput5);
}

if (Input_TestGettingDoubleInputs.GetYesNo())
{
double DoubleInput1;
int DoubleInput1Result = sc.GetChartStudyInputFloat(ChartNumberOfMainStudy, MainStudyID, 0, DoubleInput1);
double DoubleInput2;
int DoubleInput2Result = sc.GetChartStudyInputFloat(ChartNumberOfMainStudy, MainStudyID, 1, DoubleInput2);
double DoubleInput3;
int DoubleInput3Result = sc.GetChartStudyInputFloat(ChartNumberOfMainStudy, MainStudyID, 2, DoubleInput3);
double DoubleInput4;
int DoubleInput4Result = sc.GetChartStudyInputFloat(ChartNumberOfMainStudy, MainStudyID, 3, DoubleInput4);
double DoubleInput5;
int DoubleInput5Result = sc.GetChartStudyInputFloat(ChartNumberOfMainStudy, MainStudyID, 4, DoubleInput5);
}

if (Input_TestGettingPersistentInts.GetYesNo())
{
int& PersistentInt1 = sc.GetPersistentIntFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 1);
int& PersistentInt2 = sc.GetPersistentIntFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 2);
int& PersistentInt3 = sc.GetPersistentIntFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 3);
int& PersistentInt4 = sc.GetPersistentIntFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 4);
int& PersistentInt5 = sc.GetPersistentIntFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 5);
}

if (Input_TestGettingPersistentDoubles.GetYesNo())
{
double& PersistentDouble1 = sc.GetPersistentDoubleFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 1);
double& PersistentDouble2 = sc.GetPersistentDoubleFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 2);
double& PersistentDouble3 = sc.GetPersistentDoubleFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 3);
double& PersistentDouble4 = sc.GetPersistentDoubleFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 4);
double& PersistentDouble5 = sc.GetPersistentDoubleFromChartStudy(ChartNumberOfMainStudy, MainStudyID, 5);
}
}