Login Page - Create Account

Support Board


Date/Time: Thu, 10 Oct 2024 19:59:32 +0000



[Programming Help] - sc.GetStudyArrayFromChartUsingID() won't work from another chart?

View Count: 258

[2024-02-11 01:06:46]
j4ytr4der_ - Posts: 938
I'm trying to allow for selection of a study from another chart, but I can't get it to work. I can select a study from the chart my study is instantiated on, and it's fine... but if I choose any other chart, I get zero back. Here is a simplified version of my code:

Inputs:

SCInputRef Input_StudyA = sc.Input[0];
SCInputRef Input_StudyB = sc.Input[1];

SCFloatArray StudyAArray;
SCFloatArray StudyBArray;

Input_StudyA.Name = "Study A";
Input_StudyA.SetChartStudySubgraphValues(0, 0, 0);


Input_StudyB.Name = "Study B";
Input_StudyB.SetChartStudySubgraphValues(0, 0, 0);

Processing code:

sc.GetStudyArrayFromChartUsingID(Input_StudyA.GetChartNumber(), Input_StudyA.GetStudyID(), Input_StudyA.GetSubgraphIndex(), StudyAArray);

StudyA = StudyAArray[sc.ArraySize - 1];

sc.GetStudyArrayFromChartUsingID(Input_StudyB.GetChartNumber(), Input_StudyB.GetStudyID(), Input_StudyB.GetSubgraphIndex(), StudyBArray);

StudyB = StudyBArray[sc.ArraySize - 1];

Anyone have any suggestions as to what I'm missing that would keep this from working on charts other than the study's own chart? Oh and I'm using manual looping as I don't need anything but the current bar for this study, in case it matters.
Date Time Of Last Edit: 2024-02-11 01:09:08
[2024-02-11 01:14:11]
j4ytr4der_ - Posts: 938
Oh I should have added, the end result is that when I use StudyA and StudyB elsewhere, they're empty if the input was a chart other than the study's own chart.
[2024-02-11 05:27:40]
j4ytr4der_ - Posts: 938
Solved it thanks to this post:

What does Study/Price Overlay uses to get Study Arrays

I didn't realize the timeframes of the charts have to match. Works fine now.
[2024-02-11 05:52:38]
j4ytr4der_ - Posts: 938
I stand slightly corrected. To my utter shock and dismay, this function can only fetch a value from another chart if both the timeframe AND number of bars, match!

I want to get the win rate of all my trades, across all contracts, and pull it into my main chart. This chart is a 30min chart that loads only 3 days of data to reduce load. I've set up a separate chart (was a daily, but now I see it has to be 30min as well) and set it to 200 days of data, so that I can get ALL the trades (I've enabled showing fills from all contracts).

Now I've discovered that if I set this chart to 3 days, I get the value just fine... but of course it's only 3 days of fills! If I set it to anything more than 3 days, it won't return anything because the main chart is 3 days.

It's looking like If I want this to work, I have no choice but to do it directly on my main chart and just set that to 200 days to get everything. This is extremely disappointing. All I want to do is fetch a value from another chart from my study. I could use study/price overlay to pull the value in to my main chart, then reference that... and this is likely what I'll have to end up doing. But I coded the direct ability to reference another chart value for exactly this use-case, and having to have both periodicity and number of bars match, makes this feature all but useless. =(

Anyway, I guess I'll just use study/price overlay and move on.
[2024-02-11 07:44:52]
User431178 - Posts: 514
You need only make one simple change for this to work correctly, and you definitely don't have to have same number of bars or timeframe.

Use the array size from the source chart, not the calling chart.

Swap sc.ArraySize - 1 for StudyAArray.GetArraySize() - 1, repeat for any/all similar occurrences.
[2024-02-11 15:17:32]
j4ytr4der_ - Posts: 938
Ahhh very clever! Excellent insight, thank you for that. I will incorporate that straight away. =)

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

Login

Login Page - Create Account