Support Board
Date/Time: Fri, 07 Feb 2025 03:08:42 +0000
Calculation Precedence And Auto looping
View Count: 1630
[2020-05-15 08:22:54] |
Flipper - Posts: 65 |
When a study is using auto looping it seems that the Calculation Precedence does not hold. I have a study with manual looping doing a calculation and then a second study referencing the first study which is added last on the chart and set to sc.CalculationPrecedence = LOW_PREC_LEVEL and doing only one calculation per bar. But the second study seems to be calculating first!? Chart: F.US.HSIK20 10 Sec #1 | Study: Example Reference | STUDY-2 Index: 2165, num: 2164 Subgraph value last Bar: 0.00, Subgraph One Bar ago: 11.00 | 2020-05-15 18:15:34.113 Chart: F.US.HSIK20 10 Sec #1 | Study: Manual Loop Example | STUDY-1 Index: 2165, num: 2165 Subgraph value last Bar: 10.00 | 2020-05-15 18:15:35.114 Chart: F.US.HSIK20 10 Sec #1 | Study: Example Reference | STUDY-2 Index: 2166, num: 2165 Subgraph value last Bar: 0.00, Subgraph One Bar ago: 16.00 | 2020-05-15 18:15:41.622 Chart: F.US.HSIK20 10 Sec #1 | Study: Manual Loop Example | STUDY-1 Index: 2166, num: 2166 Subgraph value last Bar: 1.00 | 2020-05-15 18:15:42.612 Chart: F.US.HSIK20 10 Sec #1 | Study: Example Reference | STUDY-2 Index: 2167, num: 2166 Subgraph value last Bar: 0.00, Subgraph One Bar ago: 2.00 | 2020-05-15 18:15:51.114 Chart: F.US.HSIK20 10 Sec #1 | Study: Manual Loop Example | STUDY-1 Index: 2167, num: 2167 Subgraph value last Bar: 1.00 | 2020-05-15 18:15:52.111 So the second study which is using sc.GetStudyArrayUsingID() and/or sc.GetPersistentIntFromChartStudy() never updates. If I change the first study to Auto Looping the Calculation Precedence seem to revert back to the expected behavior. Chart: F.US.HSIK20 10 Sec #1 | Study: Auto Loop Example | STUDY-1 Index: 2183, num: 2183 Subgraph value last Bar: 1.00 | 2020-05-15 18:18:35.583 Chart: F.US.HSIK20 10 Sec #1 | Study: Example Reference | STUDY-2 Index: 2183, num: 2183 Subgraph value last Bar: 1.00, Subgraph One Bar ago: 26.00 | 2020-05-15 18:18:35.583 Chart: F.US.HSIK20 10 Sec #1 | Study: Auto Loop Example | STUDY-1 Index: 2184, num: 2184 Subgraph value last Bar: 2.00 | 2020-05-15 18:18:41.583 Chart: F.US.HSIK20 10 Sec #1 | Study: Example Reference | STUDY-2 Index: 2184, num: 2184 Subgraph value last Bar: 2.00, Subgraph One Bar ago: 3.00 | 2020-05-15 18:18:41.583 Is it expected that auto looping would have this effect? |
[2020-05-15 08:54:09] |
Flipper - Posts: 65 |
Code for the first Manual looping study SCSFExport scsf_ManualLoopExample(SCStudyInterfaceRef sc) { SCSubgraphRef NumberSubgraph = sc.Subgraph[0]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Manual Loop Example"; sc.AutoLoop = 0; // no auto-looping NumberSubgraph.Name = "Number"; return; } int& num = sc.GetPersistentInt(0); int& LastBarIndexProcessed = sc.GetPersistentInt(1); SCString MessageText; // Do data processing for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) { num = Index; NumberSubgraph[Index] = sc.Volume[Index]; // One Time Processing per Bar if (Index == 0) LastBarIndexProcessed = -1; if (Index == LastBarIndexProcessed) return; LastBarIndexProcessed = Index; MessageText.Format("STUDY-1 Index: %d, num: %d Subgraph value last Bar: %.2f ", Index, num, NumberSubgraph[Index]); sc.AddMessageToLog(MessageText, 0); } } And Code for the second Study which references the first manual looping study. SCSFExport scsf_ExampleReference(SCStudyInterfaceRef sc) { SCSubgraphRef ReferenceSubgraph = sc.Subgraph[0]; SCInputRef StudyReference = sc.Input[0]; SCString MessageText; if (sc.SetDefaults) { sc.GraphName = "Example Reference"; sc.AutoLoop = 1; sc.CalculationPrecedence = LOW_PREC_LEVEL; ReferenceSubgraph.Name = "ReferanceSubgraph"; StudyReference.Name = "Auto Loop Study Reference"; StudyReference.SetStudySubgraphValues(0, 0); return; } sc.GetStudyArrayUsingID(StudyReference.GetStudyID(), StudyReference.GetSubgraphIndex(), ReferenceSubgraph); int num_FromLoopStudy = sc.GetPersistentIntFromChartStudy(sc.ChartNumber, StudyReference.GetStudyID(), 0); // One Time Processing per Bar int& LastBarIndexProcessed = sc.GetPersistentInt(1); if (sc.Index == 0) LastBarIndexProcessed = -1; if (sc.Index == LastBarIndexProcessed) return; LastBarIndexProcessed = sc.Index; MessageText.Format("STUDY-2 Index: %d, num: %d Subgraph value last Bar: %.2f, Subgraph One Bar ago: %.2f", sc.Index, num_FromLoopStudy, ReferenceSubgraph[sc.Index], ReferenceSubgraph[sc.Index-1]); sc.AddMessageToLog(MessageText, 0); } Date Time Of Last Edit: 2020-05-15 08:55:06
|
[2020-05-15 11:55:29] |
Sierra Chart Engineering - Posts: 104368 |
When a study is using auto looping it seems that the Calculation Precedence does not hold. No this is not true. These two things are completely separate from each other.Refer to: Chart Studies: Study Calculation Precedence And Related Issues We do not provide programming help. 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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2020-05-15 13:21:52] |
Flipper - Posts: 65 |
! Did you look at the log?? I do not want your programming help. The log is clearly showing the study is calculating outside the order stated in your documents. The bold section is showing that study #2 for the same bar index is calculating first ALTHOUGH it is set to lower precedence AND is after study #1 in the chart "Studies to Graph" list. Have a look at this picture and tell me how anything in the second study occurs in the log BEFORE the first study? I know it shouldn't according to your documents but it is. Why? Please look at the picture and copy of log in post #1 Date Time Of Last Edit: 2020-05-15 13:22:47
|
2020-05-15 23_17_14-Sierra Chart 2086 Test.Cht CQG WebAPI 2.png / V - Attached On 2020-05-15 13:21:16 UTC - Size: 57 KB - 296 views |
[2020-05-15 18:33:13] |
Sierra Chart Engineering - Posts: 104368 |
The screenshot that you posted in post #4 does not show the calculation order. The calculation order is further to the right in the Studies to Graph list. And as we said whether manual looping or automatic looping is used has no effect at all upon calculation order. 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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-05-15 18:33:44
|
[2020-05-15 21:59:15] |
Flipper - Posts: 65 |
Ok I'll try again. As you can see the Calculation order is as expected in the Studies to Graph list. That is, Manual loop study CalOrder: 1 Auto Loop Study CalOrder: 2 BUT its calculating in opposite order. |
2020-05-16 07_49_47-Sierra Chart 2086 Test.Cht CQG WebAPI 2.png / V - Attached On 2020-05-15 21:58:42 UTC - Size: 71.1 KB - 296 views |
[2020-05-15 22:35:06] |
Flipper - Posts: 65 |
Have tested it on two different machines with two different Versions of SC. (2086 & 2102) Still same result. Here is the minimal example code to reproduce the unexpected behavior. |
CalcOrderTEST.cpp - Attached On 2020-05-15 22:34:09 UTC - Size: 1.63 KB - 402 views |
[2020-05-16 02:22:59] |
Sierra Chart Engineering - Posts: 104368 |
"Manual Loop Study ONE" is calculated first and then "Auto Loop Study TWO" That is the order no matter how the studies are listed. It does not matter what the logging shows. That is the calculation order. To analyze the order of what you see in the log is a programming help request because that requires an in-depth analysis of your code and debugging. 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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-05-16 02:52:54
|
[2020-05-16 02:57:47] |
Flipper - Posts: 65 |
Why then when you reference the array in the first "Manual Loop Study ONE" which is initiated with this simple code and this code only, for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) { firstSubgraph[Index] = 999.0; } In the study "Auto Loop Study TWO" with this code, sc.GetStudyArrayUsingID(Input_StudySubgraphReference.GetStudyID(), Input_StudySubgraphReference.GetSubgraphIndex(), ReferenceSubgraph);
does is give a values of 0.0 as per the highlighted and attached picture????????? from this code, MessageText.Format("STUDY-2 Index: %d, ReferenceSubgraph value: %.2f --- %.2f ",sc.Index, ReferenceSubgraph[sc.Index], ReferenceSubgraph[sc.Index-1]);
sc.AddMessageToLog(MessageText, 0); Clearly the array 1 bar back and further is referenced correctly but on initial call for each new bar it has yet to be set. I will do you a deal. I will pay you to test it at your standard rate. If you are correct. If I am correct You will pay me at my standard rate of a whole day that I have wasted just to get you to see that its not populating on first call. as per this picture, this code and all the previous post! |
2020-05-16 12_33_31-Message Log.png / V - Attached On 2020-05-16 02:41:55 UTC - Size: 34.98 KB - 243 views CalcOrderTEST.cpp - Attached On 2020-05-16 02:57:08 UTC - Size: 1.92 KB - 355 views |
[2020-05-16 03:42:41] |
Sierra Chart Engineering - Posts: 104368 |
We will have a look. But we did confirm through logging as well, that the calculation order is according to as it is shown in the Chart Studies window: Replay 60X: YMM20[M] 1 Min #1 | ---- | 2020-05-15 23:41:34.653
Replay 60X: YMM20[M] 1 Min #1 | +Calculating study: Manual Loop Study ONE | 2020-05-15 23:41:34.653 Replay 60X: YMM20[M] 1 Min #1 | +Calculating study: Auto Loop Study TWO | 2020-05-15 23:41:34.654 Replay 60X: YMM20[M] 1 Min #1 | ---- | 2020-05-15 23:41:34.965 Replay 60X: YMM20[M] 1 Min #1 | +Calculating study: Manual Loop Study ONE | 2020-05-15 23:41:34.965 Replay 60X: YMM20[M] 1 Min #1 | +Calculating study: Auto Loop Study TWO | 2020-05-15 23:41:34.966 This series of hyphens, denotes, the entry into the calculation loop for the studies. 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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-05-16 03:43:06
|
[2020-05-16 05:00:11] |
Flipper - Posts: 65 |
If there is something wrong with the code I'm happy to pay. Let me know. Though I don't believe there is. That log of yours looks like its from the initial load/population of the chart as the time stamps are all the same or 1ms diff. That's not the problem. Its on adding of new bars with a replay or live feed that caused the result in my screenshot from post #9 |
[2020-05-16 05:30:19] |
Sierra Chart Engineering - Posts: 104368 |
The chance of something being wrong on the Sierra Chart side is next to 0%. The log we provided above is during a chart replay. It is the same even when new bars are added to the chart. First thing we recommend you do is to remove this block code,: // One Time Processing per Bar
int& LastBarIndexProcessed = sc.GetPersistentInt(0); if (Index == 0) LastBarIndexProcessed = -1; if (Index == LastBarIndexProcessed) return; LastBarIndexProcessed = Index; And then you can see your study functions being called in the expected order. In this log you can see that one new bar is added at index 6399 that your own logging is not being triggered for Manual Loop Study ONE until after the second calculation.: Replay 10.00X: YMM20[M] 1 Min #1 | ---- | 2020-05-16 01:29:01.383 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Manual Loop Study ONE | 2020-05-16 01:29:01.383 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Bar Numbering | 2020-05-16 01:29:01.384 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Auto Loop Study TWO | 2020-05-16 01:29:01.386 Chart: Replay 10.00X: YMM20[M] 1 Min #1 | Study: Auto Loop Study TWO | STUDY-2 Index: 6399, Subgraph value: 23393.00 | 2020-05-16 01:29:01.387 Replay 10.00X: YMM20[M] 1 Min #1 | ---- | 2020-05-16 01:29:02.325 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Manual Loop Study ONE | 2020-05-16 01:29:02.326 Chart: Replay 10.00X: YMM20[M] 1 Min #1 | Study: Manual Loop Study ONE | STUDY-1 Index: 6399, Subgraph value: 23399.00 | 2020-05-16 01:29:02.326 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Bar Numbering | 2020-05-16 01:29:02.327 Replay 10.00X: YMM20[M] 1 Min #1 | +Calculating study: Auto Loop Study TWO | 2020-05-16 01:29:02.327 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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-05-16 05:30:51
|
[2020-05-16 06:28:07] |
Flipper - Posts: 65 |
OH! of course a return block : / If there is something wrong with the code I'm happy to pay. Let me know.
Looks like I owe you for programming support. How can I pay you? |
[2020-05-16 06:51:21] |
Sierra Chart Engineering - Posts: 104368 |
That's okay. Don't worry about it.
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, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: