Support Board
Date/Time: Mon, 25 Nov 2024 09:23:24 +0000
[Programming Help] - Data from study Study/Price overlay are not retrieved correctly on the first load,
View Count: 229
[2024-03-18 23:03:57] |
User851058 - Posts: 9 |
My setup is as follows: I have custom study on chart(chart1) and another custom study on another chart (chart2). When chart1 is loaded, I want to read the data from chart2's study (and chart2 is also doing some calculations in this study the result of which is supposed to be send to chart1 for further analysis), so I added the "Study/Price overlay" study to chart1 and selected the correct study from chart2 to import the data from. On chart1(the one that is supposed to read the data from chart1), I have set calculationPrecedence = VERY_LOW_PREC_LEVEL and on the chart2(the one that is supposed to feed the data to chart1): CalculationPrecedence = STD_PREC_LEVEL;
I have also implemented the wait for downloading historical data, so that the study on chart1 only starts its calculation when the data are there, but my problem still exists giving me occasionally random results int IsDownloading = sc.ChartIsDownloadingHistoricalData(sc.ChartNumber);
if (IsDownloading) return; int Index = sc.Index; int& lastIndexProcessed = sc.GetPersistentInt(0); if (Index == 0) { lastIndexProcessed = 0; return; } if (Index == lastIndexProcessed) return; lastIndexProcessed = Index; Now I've noticed, that the data retrieved from chart2 vary - they are different on first load (incorrect, "random"), and when after I refresh chart1, different result is returned, but this time it returns the data correctly. As in the picture attached, on the first load of the chart1 with ticker VALE, the "isSequenceOk" flag was wrongly set to 1, but after I refreshed the chart1, the value of this flag changed to 0 (and 0 is the expected value of this flag - so correctly set only after reload).... This indicates, that there must some kind of "racing condition" between the two charts and the connected studies. Could You please guide me how to solve this issue? Tried searching the support board but couldn't find anything of help to solve this problem. The only posts I've found were about the calculationPrecedence and that the order of studies in the list matters for calculations, so I also re-ordered them (which also did not solve the problem) Date Time Of Last Edit: 2024-03-18 23:37:20
|
SCCalculation.png / V - Attached On 2024-03-18 22:53:47 UTC - Size: 217.15 KB - 63 views |
[2024-03-19 10:31:04] |
User851058 - Posts: 9 |
Ok, I think I'm gonna answer myself here, for future reference by other devs in here as a lesson-learned (If I'm wrong on my solution, or there is a better way, please correct me Support :) ) So when You're using "Study/Price overlay" added on your chart1, that is referencing some custom-made Study added in other chart (chart2), a good practice is to add a subgraphed flag, say: SCSubgraphRef Subgraph_HasCalculationFinished = sc.Subgraph[0]; that you set to false at the beginning of calculation within this study, and set it to true at the end of this calculation. Then, you reference this flag (by SCSubgraphRef) in your master study in chart1 and can build a logic based on this flag - check if the value is either true of false. The good thing in Sierra Chart ACSIL is that the master study on chart1 will automatically recalculate when the referenced value changes (so the value of Subgraph_HasCalculationFinished flag). Which means, you can pretty much write something like this in pseude-code: if(Subgraph_HasCalculationFinished == false) { return; //do nothing} if(Subgraph_HasCalculationFinished true) { // do your calculation in master study in chart1 |
[2024-03-19 10:52:54] |
User431178 - Posts: 541 |
The code you shared above lacks sufficient context/detail to provide meaningful help. There are functions to help with this also, on inital chart loading (or reload). sc.IsChartDataLoadingCompleteForAllCharts() sc.IsChartDataLoadingInChartbook() |
[2024-03-19 14:46:03] |
User851058 - Posts: 9 |
Ok, gonna give these a try. The context is as follows: 1. On chart1, I have a study that is supposed to do some calculations / drawings / alerts based on another study that it is referencing, added to this chart1 via "Study/Price Overlay", via SCInputRef -> SetStudyID(...); 2. On chart2, I have a study that is doing some pre-calculations (because the chart has different time frame) What I want to achieve is: - Study on chart2 has done some precalculations and is exposing these data via SCSubgraphRef once the calculation is finished, to another studies that want to subscribe to them via this SCSubgraphRef's id. - Study on chart1 is referencing this precalculated data via SCInputRef set on "Study/Price Overlay"- which is referencing this study on chart2 - Study on chart1, when the data it is referencing (from chart2) are calculated, is performing its own calculations (and this calculation includes the data from chart2), and based on the result, set the Alert message (sc.PlaySound(...)) chart1 and chart2 are linked to the same symbol, but they are operating on different time frame. Chart1 is main -> is supposed to perform some actions based on what comes in from calculations done on chart2. Also, both charts work on "Associated Watch List" in Sierra Chart, so when the calculations on chart2 are not yet done, chart1 performs its calculation based on some default values and goes to next symbol in the Associated Watch List when auto-scanning is on on this list -> which ofc is also wrong. I have tried all 3 methods, when the data on chart2 are not yet calculated: (chart2 has sc.CalculationPrecedence = STD_PREC_LEVEL (as it needs to be calculated first), chart1 has sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL; (as it needs to be calculated after chart2) sc.RecalculateChart(sc.ChartNumber);
sc.FlagFullRecalculate = true; sc.RecalculateChartImmediate(sc.ChartNumber); none of them forced the Associated Watch List scanning to recalculate the same symbol -> the scanning proceeds to next symbol in the Associated Watch List "abandoning" the previous symbol and not setting the Alert it would have set if all the calcualations were done. So another question, is there a possibility to programmatically operate on the Associated Watch List / and scanning through the Associated Watch List? Because for some symbols on the Associated Watch List I end up with false Alerts / or no Alert at all when the Alert should be set Date Time Of Last Edit: 2024-03-19 14:59:50
|
SCCalculation2.png / V - Attached On 2024-03-19 14:59:43 UTC - Size: 21.04 KB - 61 views |
To post a message in this thread, you need to log in with your Sierra Chart account: