Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 06:46:10 +0000



Using ACSIL To Access the subgraph value of a Study

View Count: 1512

[2023-02-17 22:59:39]
Ticks - Posts: 183
I'm trying to access the value of subgraph 9 of a study on the chart.

The below code works if the study only has one subgraph.
However, I cant figure out how to access the value in subgraph 9 of the study
SCFloatArray StudyLine3;
  sc.GetStudyArrayUsingID(Input_Line3Ref.GetStudyID(), Input_Line3Ref.GetSubgraphIndex(), StudyLine3);

Can anyone tell me what code I'm missing to get the value in subgraph 9?
[2023-02-18 05:04:18]
ondafringe - Posts: 286
I don't access my subgraph data that way, but I *think* all the subgraph values are contained in your StudyLine3 array.

Keep in mind, subgraphs are zero-based, so to reference subgraph 9, you would use an 8.

See if this works (use an appropriate variable for the sub9 value):

"some variable" = StudyLine3[8];
[2023-02-18 11:04:30]
User431178 - Posts: 543
How is 'Input_Line3Ref' configured in your inputs?

The appropriate input should be configured using 'SetStudySubgraphValues', then you would choose the required subgraph in the study settings.
ACSIL Interface Members - sc.Input Array: sc.Input[].SetStudySubgraphValues()
[2023-02-18 13:50:05]
Ticks - Posts: 183
I used the example code from one of the SC examples of Moving Average cross-over studies.
The code works and I can get the line values.
I just can't access the line value of an indicator that has more than one subgraph.

How is 'Input_Line3Ref' configured in your inputs?
int num = 0;
SCInputRef Input_Line3Ref = sc.Input[num++];



sc.GetStudyArrayUsingID(Input_Line3Ref.GetStudyID(),StudyLine3);
float TrendDirection = StudyLine3[8];
There are 9 subgraphs in the indicator im trying to access.
Subgraph 9 will either have a value of 1 or -1.
using StudyLine3[8] returns a 1 that never changes.
using StudyLine3[9] returns a 1 that never changes.
[2023-02-18 14:01:46]
User431178 - Posts: 543
SCInputRef Input_Line3Ref = sc.Input[num++];

Yes, but what comes after that, how to do you actually configure the input?

For example:

Input_Line3Ref.Name = "Example Ref";
Input_Line3Ref.SetStudySubgraphValues(0,0);

Then in study settings you would select the Study and Subgraph accordingly.
If you are not setting both the Study ID and Subgraph Index in the study settings, then 'Input_Line3Ref.GetSubgraphIndex()' will return 0.


using StudyLine3[8] returns a 1 that never changes.
using StudyLine3[9] returns a 1 that never changes.

All this is doing is accessing the 8th or 9th index of whichever array you have linked to.
[2023-02-18 14:52:04]
Ticks - Posts: 183
Yes, I have that set as
Input_Line3Ref.Name = "Trend Direction";
  Input_Line3Ref.SetStudySubgraphValues(0, 0);
The input allows me to select the study and subgraph9.

I changed the code to this.
sc.GetStudyArrayFromChartUsingID(Input_Line3Ref.GetChartNumber(), Input_Line3Ref.GetStudyID(), Input_Line3Ref.GetSubgraphIndex(), StudyLine3);
StudyLine3[8] now returns a 0 that never changes.
StudyLine3[9] also returns a 0 that never changes.
[2023-02-18 16:24:31]
ondafringe - Posts: 286
You have an indicator study on your chart.
You know the ID number for that study.

Assume the study ID is 3... and you want to get the Sub9 value...

This uses the actual number for Sub9:


SCGraphData name;
SCFloatArrayRef name2 = name[0];

sc.GetStudyArray(3, 9, name2);
float trend = name2[sc.Index];

Date Time Of Last Edit: 2023-02-18 16:26:12
[2023-02-19 00:21:19]
Ticks - Posts: 183
Still a no-go.
using

SCGraphData name;
SCFloatArrayRef name2 = name[3];
sc.GetStudyArray(3, TrendDirection0, name2); //TrendDirection0 added as an input to keep from going into the code to set a number
float trend = name2[sc.Index];
Subgraph_DataTester[sc.Index] = trend;//visual output to chart

I cycled thru numbers 0 to 10 and it only returns the value of the first subgraph when the input is a 1.
All other numbers return a 0 as output.
[2023-02-19 00:41:06]
ondafringe - Posts: 286
Is your study ID number really a 3? If not, you need to use your study ID number.

I tested the exact sample code provided on my end and it works as expected.
Date Time Of Last Edit: 2023-02-19 02:50:33
[2023-02-19 02:49:37]
Ticks - Posts: 183
After some sleep to rest my brain.
It is working now with the below code.
I have added additional details to help anyone who struggled like I did and may need a code example.

int num = 0;
SCInputRef Input_Line3Ref = sc.Input[num++];//define input
Input_Line3Ref.Name = "Trend Direction";//Apply a name to the input reference
Input_Line3Ref.SetStudySubgraphValues(0, 0);//Set Subgraph Values

// using Input_Line3Ref input variables, retrieve the subgraph array
SCFloatArray StudyLine3;
sc.GetStudyArrayUsingID(Input_Line3Ref.GetStudyID(), Input_Line3Ref.GetSubgraphIndex(), StudyLine3);

float TrendDirection = StudyLine3[sc.Index];//place data in a variable to be used anywhere in the study

Thanks for all your assistance and patience.
Date Time Of Last Edit: 2023-02-19 02:52:25
[2023-09-14 03:46:43]
Bricolico - Posts: 3
So many thanks for this lines of code that works fine. Would like to add one little precision that I struggled with a little bit (I'm new to Sierra Chart but not to coding).

At the 4th line of code (see code above):

Input_Line3Ref.SetStudySubgraphValues(0, 0); //***Define your Study#/Subgraph# Values of your Studies list***

This line is very important.
- The first number represent your Study number. In your list, it is identified as ID:____
- The second number represent the index # of the Subgraph section (in the settings of the study). You will need to substract 1 to the line where your data is. So, if your data you want to import is on the first line of the subgraph, the number to put will be 0, not 1. And if the data imported is on the fourth line of a subgraph, the index # will be 3.

Example:
Your study is RSI-W and is located in your ID:7 list.
You want to import the RSI-W Avg (SG4)

The code line will look like this
Input_Line3Ref.SetStudySubgraphValues(7, 3);

Just putting this here so it can help few of you, as well.

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

Login

Login Page - Create Account