Support Board
Date/Time: Wed, 12 Feb 2025 10:13:35 +0000
[Programming Help] - ACSIL function for sorting values?
View Count: 1227
[2020-09-28 08:56:53] |
User267701 - Posts: 66 |
Greetings, does ACSIL already offer a sc.function for arranging values in an array or do i have to implement a c++ sorting algo like these?: https://www.softwaretestinghelp.com/sorting-techniques-in-cpp/ Problem for me is, that dont understand a single one of these algos...no chance. Its completely above my skills. Regards Date Time Of Last Edit: 2020-09-28 12:36:38
|
[2020-09-28 12:07:57] |
Kiwi - Posts: 375 |
You shouldn't need to understand sorting algorithms. Just use the standard library functions: https://en.cppreference.com/w/cpp/algorithm/sort and read this Sorting arrays in ACSIL Date Time Of Last Edit: 2020-09-28 12:09:10
|
[2020-10-09 01:18:07] |
bekitz - Posts: 26 |
I am also interested in this functionality. I read both links in post #2. Using both examples in the links & for simplicity sake, if I wanted to sort all of the closing prices with the following code attempt: SCSubgraphRef Closes = sc.Subgraph[0]; SCSubgraphRef Sort_Closes = sc.Subgraph[1]; //ignore default section; Closes[sc.Index] = sc.Close[sc.Index]; Sort_Closes[sc.Index] = std::sort(Closes.begin(), Closes.end()); I get errors saying that 'begin' & 'end' are not part of the subgraph struct, etc. Any assistance is appreciated. |
[2020-10-09 05:52:06] |
Ackin - Posts: 1865 |
Sierrachart example SCSFExport scsf_StochasticPercentile(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_Stochastic = sc.Subgraph[0]; SCSubgraphRef Subgraph_StochasticAverage = sc.Subgraph[1]; SCSubgraphRef Subgraph_Line1 = sc.Subgraph[2]; SCSubgraphRef Subgraph_Line2 = sc.Subgraph[3]; SCInputRef Input_Data = sc.Input[0]; SCInputRef Input_StochasticLength = sc.Input[1]; SCInputRef Input_MovingAverageLength = sc.Input[2]; SCInputRef Input_Line1Value = sc.Input[3]; SCInputRef Input_Line2Value = sc.Input[4]; if (sc.SetDefaults) { sc.GraphName = "Stochastic - Percentile"; sc.ValueFormat = 2; Subgraph_Stochastic.Name = "Stochastic%"; Subgraph_Stochastic.DrawStyle = DRAWSTYLE_LINE; Subgraph_Stochastic.PrimaryColor = RGB(0,255,0); Subgraph_Stochastic.DrawZeros = true; Subgraph_StochasticAverage.Name = "Average"; Subgraph_StochasticAverage.DrawStyle = DRAWSTYLE_LINE; Subgraph_StochasticAverage.PrimaryColor = RGB(255, 127, 0); Subgraph_StochasticAverage.DrawZeros = true; Subgraph_Line1.Name = "Line1"; Subgraph_Line1.DrawStyle = DRAWSTYLE_LINE; Subgraph_Line1.PrimaryColor = RGB(255, 255, 0); Subgraph_Line1.DrawZeros = true; Subgraph_Line2.Name = "Line2"; Subgraph_Line2.DrawStyle = DRAWSTYLE_LINE; Subgraph_Line2.PrimaryColor = RGB(0, 0, 255); Subgraph_Line2.DrawZeros = true; Input_Data.Name = "Input Data"; Input_Data.SetInputDataIndex(SC_LAST); Input_StochasticLength.Name = "Length"; Input_StochasticLength.SetInt(10); Input_StochasticLength.SetIntLimits(1,MAX_STUDY_LENGTH); Input_MovingAverageLength.Name = "Moving Average Length"; Input_MovingAverageLength.SetInt(10); Input_MovingAverageLength.SetIntLimits(1, MAX_STUDY_LENGTH); Input_Line1Value.Name = "Line 1 Value"; Input_Line1Value.SetFloat(20); Input_Line2Value.Name = "Line 2 Value"; Input_Line2Value.SetFloat(80); sc.AutoLoop = false; return; } std::vector<float> AscendingValues; SCFloatArrayRef DataArray = sc.BaseData[Input_Data.GetInputDataIndex()]; sc.DataStartIndex = Input_StochasticLength.GetInt() - 1; for (int CurrentIndex = sc.UpdateStartIndex; CurrentIndex < sc.ArraySize; CurrentIndex++) { AscendingValues.clear(); int FirstIndex = CurrentIndex - Input_StochasticLength.GetInt() + 1; for (int BarIndex = FirstIndex; BarIndex <= CurrentIndex; BarIndex++) { AscendingValues.push_back(DataArray[BarIndex]); } std::sort(AscendingValues.begin(), AscendingValues.end()); float CurrentPrice = DataArray[CurrentIndex]; int AscendingValuesSize = static_cast<int>(AscendingValues.size()); int AscendingValuesIndex = 0; for(; AscendingValuesIndex < AscendingValuesSize; AscendingValuesIndex++) { if (CurrentPrice == AscendingValues[AscendingValuesIndex]) break; if (AscendingValuesIndex == AscendingValuesSize - 1) break; } Subgraph_Stochastic[CurrentIndex] = 100.0f*AscendingValuesIndex/(Input_StochasticLength.GetInt() - 1); sc.SimpleMovAvg(Subgraph_Stochastic, Subgraph_StochasticAverage, CurrentIndex, Input_MovingAverageLength.GetInt()); Subgraph_Line1[CurrentIndex] = Input_Line1Value.GetFloat(); Subgraph_Line2[CurrentIndex] = Input_Line2Value.GetFloat(); } return; } |
To post a message in this thread, you need to log in with your Sierra Chart account: