I'm a complete beginner to C++ and this code is surely done terribly but for now I am trying to just code a simple chart indicator for SierraChart. When coding a chart indicator for sierra chart all the code for a chart indicator goes into one function and I'm stuck on this part.
I only need to run just the last direction that was crossed. What ends up happening with the code currently is that both end up running at the same time because both conditions end up being true.
I've tried an else if for the second direction and some boolean conditions inside the if blocks to try and only run the last direction and that doesn't seem to solve the issue.
How can I solve this?
int &barCount = sc.GetPersistentInt(0);
float &longCount = sc.GetPersistentFloat(0);
float &shortCount = sc.GetPersistentFloat(0);
float Highest = sc.GetHighest(sc.BaseDataIn[SC_HIGH], barCount);
float Lowest = sc.GetLowest(sc.BaseDataIn[SC_LOW], barCount);
sc.MovingAverage(sc.BaseData[Input_MA1Price.GetInputDataIndex()], sc.Subgraph[2], Input_MA1Type.GetMovAvgType(), Input_MA1Length.GetInt());
sc.MovingAverage(sc.BaseData[Input_MA2Price.GetInputDataIndex()], sc.Subgraph[3], Input_MA2Type.GetMovAvgType(), Input_MA2Length.GetInt());
int direction = sc.CrossOver(sc.Subgraph[2], sc.Subgraph[3]);
if (direction == CROSS_FROM_BOTTOM)
{
barCount = 0;
longCount = 0;
}
if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED)
{
barCount++;
barCounter[sc.Index] = barCount;
if (sc.BaseData[SC_HIGH][sc.Index] == Highest)
{
longCount = 0;
}
if (sc.BaseData[SC_HIGH][sc.Index] > sc.BaseData[SC_HIGH][sc.Index - 1] && sc.BaseData[SC_HIGH][sc.Index] < Highest)
{
longCount++;
highPrice[sc.Index] = longCount;
if (sc.BaseData[SC_HIGH][sc.Index - 2] < sc.BaseData[SC_HIGH][sc.Index - 1] && sc.BaseData[SC_HIGH][sc.Index] < Highest)
{
longCount--;
highPrice[sc.Index] = 0;
}
}
}
if (direction == CROSS_FROM_TOP)
{
barCount = 0;
shortCount = 0;
}
if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED)
{
barCount++;
barCounter[sc.Index] = barCount;
if (sc.BaseData[SC_LOW][sc.Index] == Lowest)
{
shortCount = 0;
}
if (sc.BaseData[SC_LOW][sc.Index] < sc.BaseData[SC_LOW][sc.Index - 1] && sc.BaseData[SC_LOW][sc.Index] > Lowest)
{
shortCount++;
lowPrice[sc.Index] = shortCount;
if (sc.BaseData[SC_LOW][sc.Index - 2] > sc.BaseData[SC_LOW][sc.Index - 1] && sc.BaseData[SC_LOW][sc.Index] > Lowest)
{
shortCount--;
lowPrice[sc.Index] = 0;
}
}
}