Support Board
Date/Time: Sat, 24 May 2025 11:51:44 +0000
[Programming Help] - Experiencing slow calculations speed when getting data from another chart study
View Count: 396
[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); } } |
[2023-08-03 14:02:18] |
User431178 - Posts: 687 |
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.
But is that not displaying the result of calling the study function at every bar in the chart (as you are using auto-looping)?Have you actually timed a single chart update sequence? What is the result if you switch to manual looping? Working with ACSIL Arrays and Understanding Looping: Manual Looping/Iterating |
[2023-08-03 14:35:25] |
LoupyTrader - Posts: 8 |
Have you actually timed a single chart update sequence?
How would you do so ? I tried myself but can't get something to work properly. What is the result if you switch to manual looping?
Will try that but it doesn't suit the algo I am trying to make. |
[2023-08-03 16:21:21] |
User431178 - Posts: 687 |
How would you do so ? I tried myself but can't get something to work properly.
Using chrono from the standard library - https://en.cppreference.com/w/cpp/chrono There are many examples on the internet, here is one - https://www.learncpp.com/cpp-tutorial/timing-your-code/ Will try that but it doesn't suit the algo I am trying to make.
Maybe I am a simpleton, but how does it not suit it?
|
[2023-08-03 16:29:14] |
LoupyTrader - Posts: 8 |
Problem solved using manual looping. I will split the algo in two parts : calculations that needs to be done for every bar and looking for trades separately only when the latest bar is updated. To be honest I wasn't 100% aware of manual looping would work with that. You may want to have the value in a variable remain persistent between calls to your study function. For example, when using Automatic-Looping (the default and recommended method of looping) your study function is called for every bar in the chart. If you want to have a variable retain its value between calls into your study function, then you need to use persistent variables.
ACSIL Interface Members - Functions: Persistent Variable Functions The documentation kind of misled me into thinking that would be the only way to achieve what I want to do. Date Time Of Last Edit: 2023-08-03 16:29:52
|
To post a message in this thread, you need to log in with your Sierra Chart account: