Login Page - Create Account

Support Board


Date/Time: Sat, 15 Mar 2025 22:50:50 +0000



[Programming Help] - Pass Array from GetStudyLineUntilFutureIntersectionByIndex to SubGraph

View Count: 516

[2022-08-03 02:31:46]
BombaFett - Posts: 3
Demigods,

I have a feeling this is a painfully simple question, but for the life of me, I can't the code below to pass all the occurrences of Add Until Line Intersection from the referenced study. It just shows the most recent one on the last bar since adding the study. I can kinda see why because because I'm passing LineValue as a single value, but everytime I try to add an Index (which I'm almost certain I'm doing wrong), I get compile errors.

I've read the documentation for arrays (ACSIL Interface Members - sc.Subgraph Array: sc.Subgraph[].Data[] / sc.Subgraph[][]) but I'm not understanding it much better. Am I even on the right track?

Thanks for any insight you can provide

SCSFExport scsf_IntersectionLines(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_IntersectionLines = sc.Subgraph[0];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Reference Study with Add Until Line Intersection Data";
    sc.StudyDescription = "Referencing Add Until Line Intersection data from other studies on the chart.";
    Subgraph_IntersectionLines.Name = "Line Properties";
    Subgraph_IntersectionLines.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_IntersectionLines.LineWidth = 5;
    Subgraph_IntersectionLines.PrimaryColor = COLOR_GREEN;
    Subgraph_IntersectionLines.DrawZeros = false;
    sc.AutoLoop = 0;

    // low precedence level to ensure other studies are calculated first.

    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    sc.Input[1].Name = "Study Reference with Add Until Line Intersection";
    sc.Input[1].SetStudyID(1);
    return;
  }

  int LineIDForBar = 0;
  int StartIndex = 0;
  float LineValue = 0;
  int EndIndex = 0;

  sc.GraphRegion = 0;


  int LineIndex = 0;
  LineIndex = sc.GetNumLinesUntilFutureIntersection(sc.ChartNumber, sc.Input[1].GetStudyID()) - 1;


  for (LineIndex; LineIndex < sc.ArraySize; ++LineIndex)
  {
    sc.GetStudyLineUntilFutureIntersectionByIndex(sc.ChartNumber, sc.Input[1].GetStudyID(), LineIndex, LineIDForBar, StartIndex, LineValue, EndIndex);
    Subgraph_IntersectionLines[sc.Index] = LineValue;
  }
}

[2022-08-03 07:26:35]
User431178 - Posts: 614
Do you see the problem here?


int LineIndex = 0;
LineIndex = sc.GetNumLinesUntilFutureIntersection(sc.ChartNumber, sc.Input[1].GetStudyID()) - 1;

You are setting the LineIndex variable to the index of the last added LineUntilFutureIntersection, and accordingly, as you have found, you will only ever see the most recent line.

Another problem is that you have Autoloop disabled, but are trying to use sc.Index.
Working with ACSIL Arrays and Understanding Looping: Automatic Looping/Iterating


Here is a modified version of your code, I'll leave you to add the relevant details in the loop.


const int LineIndexArraySize = sc.GetNumLinesUntilFutureIntersection(sc.ChartNumber, sc.Input[1].GetStudyID()) - 1;

for (int LineIndex = 0; LineIndex < LineIndexArraySize; ++LineIndex)
{
sc.GetStudyLineUntilFutureIntersectionByIndex(sc.ChartNumber, sc.Input[1].GetStudyID(), LineIndex, LineIDForBar, StartIndex, LineValue, EndIndex);

.... insert your other relevant code

}

[2022-08-03 20:06:10]
BombaFett - Posts: 3
Ahh I see it now...I thought I was just initializing the variable lol.

Thank you for including the documentation on Auto Looping, I actually never realized sc.Index referred to the BarNumber. It made so much more sense after reading.

Thanks again for your help!

Working code for posterity :)
SCSFExport scsf_IntersectionLines(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_IntersectionLines = sc.Subgraph[0];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Reference Study with Add Until Line Intersection Data";
    sc.StudyDescription = "Referencing Add Until Line Intersection data from other studies on the chart.";
    Subgraph_IntersectionLines.Name = "Line Properties";
    Subgraph_IntersectionLines.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_IntersectionLines.LineWidth = 2;
    Subgraph_IntersectionLines.PrimaryColor = COLOR_DARKORANGE;
    Subgraph_IntersectionLines.DrawZeros = false;
    sc.AutoLoop = 1;

    // low precedence level to ensure other studies are calculated first.

    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    sc.Input[1].Name = "Study Reference with Add Until Line Intersection";
    sc.Input[1].SetStudyID(1);
    return;
  }

  int LineIDForBar = 0;
  int StartIndex = 0;
  float LineValue = 0;
  int EndIndex = 0;

  sc.GraphRegion = 0;


const int LineIndexArraySize = sc.GetNumLinesUntilFutureIntersection(sc.ChartNumber, sc.Input[1].GetStudyID());

for (int LineIndex = 0; LineIndex < LineIndexArraySize; ++LineIndex)
{
sc.GetStudyLineUntilFutureIntersectionByIndex(sc.ChartNumber, sc.Input[1].GetStudyID(), LineIndex, LineIDForBar, StartIndex, LineValue, EndIndex);
  Subgraph_IntersectionLines[sc.Index] = LineValue;
  }
}

Date Time Of Last Edit: 2022-08-03 22:08:00

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account