Login Page - Create Account

Support Board


Date/Time: Tue, 23 Apr 2024 20:27:17 +0000



[User Discussion] - How to find all values of an sc.Subgraph[] array that are above a given value?

View Count: 710

[2021-04-09 17:02:45]
opmetal - Posts: 65
I have an array that I use to store support pivots. I can't figure out how to determine if a chart bar closed below more than one of these pivots. I use sc.GetIndexOfHighestValue(SupportPivot, sc.ArraySize) to get the highest value of the pivot array and test if price closes below this. But often there is a close below multiple support pivots in the same bar. Later in my code I will need to test if price is near one of these pivots and the logic won't work if price is already below them. I'm using AutoLoop and I'm not sure if I would need to loop manually to accomplish what I want. Basically I need to find all the values of SupportPivot that are above the closing price and remove them from my array.

Any help is appreciated!!


SCSubgraphRef SupportPivot = sc.Subgraph[0];

if (some conditions bla bla)
{
SupportPivot[sc.Index - 1] = InData[SC_OPEN][sc.Index - 1]; //store a value in the array
}

float HighestSupportPivot = sc.GetHighest(SupportPivot, sc.ArraySize); // get the highest pivot from the array
int HighestSupportPivotIndex = sc.GetIndexOfHighestValue(SupportPivot, sc.ArraySize); // get the highest pivot's sc.Index

if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED // check if a bar has closed
&& InData[SC_LAST][sc.Index] < HighestSupportPivot // then check if price closed below the highest pivot
)
{
SupportPivot[HighestSupportPivotIndex] = NULL; // clear the highest pivot from the array as I only need support pivots below the current price.
}
[2021-04-10 00:06:32]
Flipper_2 - Posts: 57
You can still use for loops in a study that is set to Autoloop.

If I understand correctly what you want to do is loop through all the bars and see if any close prices are below the highest pivot point in SupportPivot. If so remove that pivot?



if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED) {

for (int Index = 0; Index < sc.ArraySize; Index++)
{
if (sc.Close[Index] < HighestSupportPivot)
{
SupportPivot[HighestSupportPivotIndex] = 0.0;
}
}

}

Date Time Of Last Edit: 2021-04-10 00:25:52
[2021-04-11 03:12:33]
opmetal - Posts: 65
Yes, thank you. With a little tweaking this is what I wanted to achieve.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account