Support Board
Date/Time: Fri, 10 Jan 2025 17:22:12 +0000
[Programming Help] - Array Looping
View Count: 1468
[2016-09-27 09:40:01] |
User103305 - Posts: 8 |
Hi, I wanted to ask something about the looping. I have a loop like this: for (int i = 0; i < 50; ++i) { if (sc.Subgraph[3] != 0) etc.... } First index of the Array is 0 isn´t it?? Why then the loop start to iterate from the last value on the chart and not from the first one?? Thx. Best regards, |
[2016-09-27 09:47:38] |
Sierra Chart Engineering - Posts: 104368 |
This is wrong: if (sc.Subgraph[3] != 0) should be: if (sc.Subgraph[3][Index] != 0) 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: 2016-09-27 09:49:51
|
[2016-09-27 09:49:39] |
Sierra Chart Engineering - Posts: 104368 |
The prior post has been corrected.
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 |
[2016-09-27 09:53:16] |
User103305 - Posts: 8 |
Sorry error on copy and paste. Yes I have it so: for (int Index = 0; Index < 100; ++Index) { if (sc.Subgraph[3][Index] != 0) { Thx. Best Date Time Of Last Edit: 2016-09-27 16:58:13
|
[2016-09-27 09:56:57] |
User103305 - Posts: 8 |
Doesn't not display the i after the [3]!!! I dont know why...but I have it there. |
[2016-09-27 16:57:25] |
Sierra Chart Engineering - Posts: 104368 |
Use Index instead of i. That solves the display problem. We have corrected it for you. First index of the Array is 0 isn´t it?? Why then the loop start to iterate from the last value on the chart and not from the first one?? Yes this is correct. The indexing is from the first Subgraph value in the chart. That is definitive. So any conclusion otherwise is incorrect. 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 |
[2016-09-27 18:29:04] |
User103305 - Posts: 8 |
Hi, thx for your answer. Can you give me some example? how to iterate from first value on the chart to last one ? And how to iterate from last value on the chart to first one ? Thx. Best, |
[2016-09-27 23:46:18] |
Sierra Chart Engineering - Posts: 104368 |
Refer to: http://www.sierrachart.com/index.php?page=doc/ACS_ArraysAndLooping.html C++ Control Structures: The for loop 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 |
[2016-09-28 17:45:28] |
User103305 - Posts: 8 |
Hi, thx for your answer. Only to be 100% sure. Can you confirm that the most current not closed bar on the right side of the Sierra Chart have the Index value of 0 ? In this case if the chart settings are set to 1-30.9.2016: 1.9.2016 has the index(first on the right side) value [0] and the 30.9.2016 hast the index(last on the left side) value [29] Correct?? Best, |
[2016-09-28 18:02:56] |
Sierra Chart Engineering - Posts: 104368 |
We will start with this: Can you confirm that the most current not closed bar on the right side of the Sierra Chart have the Index value of 0 ? The last bar in the chart on the right side is at index sc.ArraySize -1. 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 |
[2016-09-28 18:59:38] |
User103305 - Posts: 8 |
Then the second bar on the right side has the index value of 0 ? Best, |
[2016-09-28 19:23:59] |
Sierra Chart Engineering - Posts: 104368 |
No that is not correct either. The index will be sc.ArraySize-2 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 |
[2016-09-28 20:40:44] |
User103305 - Posts: 8 |
Then the example below will populate the arrays from right to left??? Does it mean that the sc.UpdateStartIndex hold the value -1? This function demonstrates manual looping using a for loop. /*----------------------------------------------------------------------------*/ SCSFExport scsf_ManualLoopExample(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Manual Loop Example"; sc.StudyDescription = "This is an example of using manual looping."; sc.AutoLoop = 0; // 0 is the default: there is no auto-looping sc.Subgraph[0].Name = "High Low Difference"; sc.Subgraph[1].Name = "High - Low Average"; sc.Subgraph[2].Name = "Back Reference Example"; sc.Subgraph[3].Name = "Forward Reference Example"; return; } // Do data processing for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) { // Calculate the difference between the high and the low sc.Subgraph[0][Index] = sc.BaseData[SC_HIGH][Index] - sc.BaseData[SC_LOW][Index]; // SimpleMovAvg will fill in the data element in sc.Subgraph[1] at index Index. sc.SimpleMovAvg(sc.Subgraph[0], sc.Subgraph[1], Index, 10); // Copy the previous last price (Index-1) to subgraph array number 3 sc.Subgraph[2][Index] = sc.BaseData[SC_LAST][Index - 1]; // Copy the next last price (Index+1) to subgraph array number 4 sc.Subgraph[3][Index] = sc.BaseData[SC_LAST][Index + 1]; } } Date Time Of Last Edit: 2016-09-28 23:55:01
|
[2016-09-28 23:53:55] |
Sierra Chart Engineering - Posts: 104368 |
The order will be from left to right from the perspective of the chart bars. sc.UpdateStartIndex will never be a negative value. 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: