Support Board
Date/Time: Tue, 15 Apr 2025 12:47:51 +0000
Post From: sc.GetStudyIDByIndex / sc.GetStudyIDByName always return 0
[2025-04-12 15:11:41] |
User431178 - Posts: 646 |
I had to add two lines at the top which are: #include "sierrachart.h"
SCDLLName("StudyInformation"); Yes, sorry, I pasted it from a larger file that had those values set at the very top and forgot to include them for you here. 3. The second guard is catching an issue. The code can never get past this guard because of: sc.Input[0].SetChartNumber(0); in the SetDefaults block, which is then assigned to chartNumber here: const auto chartNumber = sc.Input[0].GetChartNumber(); So chartNumber is assigned zero. When the guard checks it, it fails because chartNumber is zero: if (chartNumber == 0 || identifier <= 0)
return; 4. All I had to do was change: sc.Input[0].SetChartNumber(0); TO sc.Input[0].SetChartNumber(1); to get the study to work. Fine, but you don't need to change that, the whole point is that you can set the chart number via the study settings interface. The default value of 0 means that it doesn't do anything when you first add it to the chart (unless you change the input to the desired chart). In my personal study I assume the information is available once the studies are added, I don't perform multiple loops to obtain the information because according to the documentation, sc.AddStudyToChart returns the unique sc.StudyGraphInstanceID, which is exactly the value I am trying to get. I do this in my code: const auto result = sc.AddStudyToChart(addStudy), then use the "Result", expecting it to be correct. If I understand what is happening correctly... - The real issue is NOT: sc.GetStudyIDByIndex (which does show the correct values, proved in the while loop) - The real issue is: The return value of sc.AddStudyToChart (I added two studies, ATR and EMA, so the "Result" should be 2 and 3 respectively because "Study Information" is 1, the first study instance on the chart) No The return value of sc.AddStudyToChart is completely irrelevant (other than to indicate that it executed successfuly), I only included the "Result" variable so you could see it in the log. Where exactly in the docs does it state that the sc.AddStudyToChart function returns the unique sc.StudyGraphInstanceID? The problem is simply that the new studies are not available until the chart (or other chart) is calculated again, and this does not occur until after your study function returns. It is wrong to assume that the information is immediately available, as it is not. Date Time Of Last Edit: 2025-04-12 15:15:14
|