Login Page - Create Account

Support Board


Date/Time: Mon, 16 Jun 2025 01:22:44 +0000



sc.AddStudyToChart issue??

View Count: 236

[2025-05-12 21:05:47]
Richard Chinn - Posts: 35
Hi guys,

I recently reported that sc.GetStudyIDByIndex and sc.GetStudyIDByName were returning zero.
In my program they are BUT it looks like the issue is not either of those functions,
It looks like the issue I'm having originates at the sc.AddStudyToChart function.

Simply put if I manually add studies to my chart everything looks good.
I added these studies manually via the studies window:

MovingAverage - Exponential S_ID 27
MovingAverage - Simple S_ID 2

I get the correct values from sc.GetStudyIDByName and sc.GetStudyIDByIndex.
I get 1 and 2 respectively.

However; if I add the studies by using sc.AddStudyToChart, the return values from both functions are always zero.
This is all I am doing:


n_ACSIL::s_AddStudy addStudy;
addStudy.StudyID = 27;
addStudy.ShortName = "MovingAverageExponential";
addStudy.ChartNumber = 1;

sc.AddStudyToChart(addStudy);

int studyInstanceByIndex = sc.GetStudyIDByIndex(addStudy.ChartNumber, addStudy.StudyID); // Returns 0
int studyInstanceByName = sc.GetStudyIDByName(addStudy.ChartNumber, addStudy.ShortName, true); // Returns 0


Thanks for any help you can supply!
Richard
[2025-05-13 17:21:51]
Sierra_Chart Engineering - Posts: 19924
The reason for this is very simple. Calling sc.AddStudyToChart is a delayed action and will not be completed until after your study function returns.

If you are using automatic looping and there are multiple calls into the study function, it is not until the chart is updated next, that the study will have been added.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-05-13 19:00:01]
Richard Chinn - Posts: 35
OK, that explains a lot. Maybe that could be added to the sc,AddStudyToChart documentation.

Thanks,
Richard

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

Login

Login Page - Create Account