Support Board
Date/Time: Wed, 12 Feb 2025 12:56:59 +0000
[Programming Help] - plot multiple subgraphs to different regions from single study
View Count: 1363
[2020-10-22 19:25:01] |
jomo88 - Posts: 47 |
I came up with the following solution. I am wondering if it is the most efficient solution memory wise and/or computationally. Running multiple instances of the study that I want to plot subgraphs from is not an option, as it has already maxed out computer resources. #include "sierrachart.h" SCDLLName("PlotStudyData") SCSFExport scsf_PlotStudyData(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_Copy = sc.Subgraph[0]; SCInputRef StudySubgraphReference = sc.Input[0]; if (sc.SetDefaults) { Subgraph_Copy.Name = "Copy For Region Plot"; Subgraph_Copy.DrawStyle = DRAWSTYLE_LINE; Subgraph_Copy.PrimaryColor = RGB(0,255,0); Subgraph_Copy.DrawZeros = false; StudySubgraphReference.Name = "Study And Subgraph To Display"; StudySubgraphReference.SetChartStudySubgraphValues(1,1,3); // Chart, Study, Subgraph return; } SCFloatArray StudyReference; sc.GetStudyArrayFromChartUsingID(StudySubgraphReference.GetChartStudySubgraphValues(), StudyReference); for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) { Subgraph_Copy[Index] = StudyReference[Index]; } } Can you advise me if this is the optimal solution? I am assuming this study will use the memory required to store just Subgraph_Copy. Is memory being used twice with StudyReference? I think its required, correct? Thank you Date Time Of Last Edit: 2020-10-22 19:45:10
|
[2020-10-25 11:17:12] |
ForgivingComputers.com - Posts: 1001 |
I cannot say this is optimal, but I think a simpler workaround would be to add a spreadsheet formula that references a (hidden) subgraph of your study.
|
[2020-10-31 04:06:53] |
jomo88 - Posts: 47 |
For anyone looking, you can find the following code from Studies2.cpp, it works well. Also, good info is at Referencing Other Time Frames and Symbols When Using the ACSIL #include "sierrachart.h" SCDLLName("StudySubgraphReference") SCSFExport scsf_StudySubgraphReference(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_StudySubgraphReference = sc.Subgraph[0]; SCInputRef Input_StudySubgraphReference = sc.Input[0]; SCInputRef Input_DrawZeros = sc.Input[1]; // Set configuration variables if (sc.SetDefaults) { sc.GraphName = "Study Subgraph Reference"; sc.GraphRegion = 2; sc.ScaleRangeType = SCALE_AUTO; Subgraph_StudySubgraphReference.Name = "Study Subgraph"; Subgraph_StudySubgraphReference.DrawStyle = DRAWSTYLE_LINE; Subgraph_StudySubgraphReference.PrimaryColor = RGB(0, 255, 0); Input_StudySubgraphReference.Name = "Study Subgraph to Reference"; Input_StudySubgraphReference.SetStudySubgraphValues(0, 0); Input_DrawZeros.Name = "Draw Zeros"; Input_DrawZeros.SetYesNo(true); sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL; sc.AutoLoop = 0; return; } // Do data processing Subgraph_StudySubgraphReference.DrawZeros = Input_DrawZeros.GetYesNo(); //This will return sc.UpdateStartIndex or an earlier index if this study is calculated after a study which calculated at an earlier index and supports setting that earlier index. int ActualStartIndex = sc.GetCalculationStartIndexForStudy(); // Get the array for the specified Input Data from the specified studies SCFloatArray Study1Array; sc.GetStudyArrayUsingID(Input_StudySubgraphReference.GetStudyID(), Input_StudySubgraphReference.GetSubgraphIndex(), Study1Array); for (int BarIndex = ActualStartIndex; BarIndex < sc.ArraySize; BarIndex++) { Subgraph_StudySubgraphReference[BarIndex] = Study1Array[BarIndex]; } sc.EarliestUpdateSubgraphDataArrayIndex = ActualStartIndex; } |
To post a message in this thread, you need to log in with your Sierra Chart account: