Support Board
Date/Time: Wed, 05 Feb 2025 18:01:14 +0000
[Programming Help] - cumulative sum need help
View Count: 166
[2025-01-12 19:20:18] |
User411647 - Posts: 21 |
Hi guys Need help with cumulative sum of two values, when i use sum persist variable that last index value starts 7XXX and each iteration increases or decreases value by hundreds Historical cumulative line looks good, problem is last index value Can anyone help ? sc.AutoLoop = 1 c_SCTimeAndSalesArray TimeSales; sc.GetTimeAndSales(TimeSales); if (TimeSales.Size() == 0) return; int mojIndex = TimeSales.Size(); int OutputArrayIndex = sc.ArraySize; for (int TSIndex = mojIndex - 1; TSIndex >= 0; --TSIndex) { s_TimeAndSales TimeAndSalesRecord = TimeSales[TSIndex]; TimeAndSalesRecord *= sc.RealTimePriceMultiplier; { // Calculate valuesbid and valuesask int& cumulative_sum = sc.GetPersistentInt(1); int cycle_sum = 0; for (int i = 0; i < 30; i++) { cycle_sum += static_cast<int>(valuesBid[i]) - static_cast<int>(valuesAsk[i]); } cumulative_sum += cycle_sum; sc.SetPersistentInt(1, cumulative_sum); Subgraph_BidSize[OutputArrayIndex] = cumulative_sum; } } |
cumulative.jpg / V - Attached On 2025-01-12 19:19:59 UTC - Size: 50.76 KB - 29 views |
[2025-01-13 02:12:09] |
cmet - Posts: 601 |
Check this ES Price Data from sc.GetTimeAndSales() Multiplied by 100 |
[2025-01-13 06:54:22] |
User411647 - Posts: 21 |
thanks for advice cmet but valuesbid and valuesask are specific volume values I tried reset cumulative_sum before iteration if (OutputArrayIndex == 0)
and it looks like this : red bars -> positive askvol and negative bidvol, green line cumulative sum { cumulative_sum = 0; } cumulative calculation looks fine but now last index value is 0 Important for me is last cumulative value but i dont know how to do it I think that persist var is initialized incorrectly what do you think ? |
cumulative sum.jpg / V - Attached On 2025-01-13 06:54:18 UTC - Size: 35.97 KB - 24 views |
[2025-01-13 13:10:10] |
cmet - Posts: 601 |
Here's a test study. Take a look or run on replay/live data. Might be in the ballpark. Image was run on ES 1 min data. |
BA_sum.cpp - Attached On 2025-01-13 13:09:38 UTC - Size: 2.71 KB - 37 views bidask_lastindex.jpg / V - Attached On 2025-01-13 13:09:42 UTC - Size: 125.09 KB - 29 views |
To post a message in this thread, you need to log in with your Sierra Chart account: