Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 06:43:08 +0000



[Programming Help] - Custom SwingHighandLow

View Count: 238

[2024-03-20 21:38:42]
User273277 - Posts: 58
Trying to use the scsf_SwingHighAndLow code and just generate an arrow on every swing low to start out.

Not sure how to make use of this study beyond including it in my file, and the couple lines of code at the bottom.

But it's giving this error when doing a remote build, and I was not able to piece together how to fix this from the forums and google yet:
test1.cpp:144:1: error: 'scsf_SwingHighAndLow' does not name a type
144 | scsf_SwingHighAndLow swingStudy(100);
| ^~~~~~~~~~~~~~~~~~~~
test1.cpp:146:20: error: 'StudyData' was not declared in this scope
146 | int CalculateStudy(StudyData std::data) {
| ^~~~~~~~~


Any help would be appreciated.


########

#include "sierrachart.h"
#include "SCStudyFunctions.h"

SCDLLName("Bar Signal")

/*==========================================================================*/
SCSFExport scsf_SwingHighAndLow(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_SwingHigh = sc.Subgraph[0];
  SCSubgraphRef Subgraph_SwingLow = sc.Subgraph[1];
  SCSubgraphRef Subgraph_LineProperties = sc.Subgraph[2];

  SCInputRef Input_ArrowOffsetValue = sc.Input[0];
  SCInputRef Input_Length = sc.Input[1];
  SCInputRef Input_AllowEqualBars = sc.Input[2];
  SCInputRef Input_ExtendSwings = sc.Input[3];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Swing High And Low";

    sc.AutoLoop = true;
    sc.GraphRegion = 0;
    sc.ValueFormat= VALUEFORMAT_INHERITED;

    Subgraph_SwingHigh.Name = "Swing High";
    Subgraph_SwingHigh.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    Subgraph_SwingHigh.PrimaryColor = RGB(0,255,0);
    Subgraph_SwingHigh.DrawZeros = false;
    Subgraph_SwingHigh.PrimaryColor = RGB(255,0,0);
    Subgraph_SwingHigh.LineWidth = 3;

    Subgraph_SwingLow.Name = "Swing Low";
    Subgraph_SwingLow.DrawStyle = DRAWSTYLE_ARROW_UP;
    Subgraph_SwingLow.PrimaryColor = RGB(255,0,255);
    Subgraph_SwingLow.DrawZeros = false;
    Subgraph_SwingLow.LineWidth = 3;
    Subgraph_SwingLow.PrimaryColor = RGB(0,255,0);

    Subgraph_LineProperties.Name = "Line Properties";
    Subgraph_LineProperties.DrawStyle = DRAWSTYLE_SUBGRAPH_NAME_AND_VALUE_LABELS_ONLY;
    Subgraph_LineProperties.LineWidth = 1;
    Subgraph_LineProperties.PrimaryColor = RGB(255, 0, 0);
    Subgraph_LineProperties.SecondaryColor = RGB(0, 255, 0);
    Subgraph_LineProperties.SecondaryColorUsed = true;
    Subgraph_LineProperties.DrawZeros = false;

    Input_ArrowOffsetValue.Name = "Arrow Offset as Percentage";
    Input_ArrowOffsetValue.SetFloat(3);
    
    Input_Length.Name = "Length";
    Input_Length.SetInt(1);
    Input_Length.SetIntLimits(1,MAX_STUDY_LENGTH);
    
    Input_AllowEqualBars.Name = "Allow Equal High/Low Bars";
    Input_AllowEqualBars.SetYesNo(false);

    Input_ExtendSwings.Name = "Extend Swings Until Future Intersection";
    Input_ExtendSwings.SetYesNo(false);

    return;
  }

  int IndexToEvaluate = sc.Index - Input_Length.GetInt();

  if(IndexToEvaluate - Input_Length.GetInt() < 0)
  {
    return;
  }

  sc.EarliestUpdateSubgraphDataArrayIndex = IndexToEvaluate;

  float ArrowOffset=(sc.High[IndexToEvaluate] - sc.Low[IndexToEvaluate] )*(Input_ArrowOffsetValue.GetFloat() * 0.01f);

  Subgraph_SwingHigh[IndexToEvaluate] = 0;
  Subgraph_SwingLow[IndexToEvaluate] = 0;

  // check for Swing High
  if (!Input_AllowEqualBars.GetYesNo())
  {
    if (sc.IsSwingHigh(sc.High, IndexToEvaluate, Input_Length.GetInt()))
      Subgraph_SwingHigh[IndexToEvaluate] = sc.High[IndexToEvaluate] + ArrowOffset;
  }
  else if (IsSwingHighAllowEqual_S( sc, true , IndexToEvaluate, Input_Length.GetInt()))
    Subgraph_SwingHigh[IndexToEvaluate] = sc.High[IndexToEvaluate] + ArrowOffset;

  
  // check for Swing Low
  if (!Input_AllowEqualBars.GetYesNo())
  {
    if (sc.IsSwingLow(sc.Low, IndexToEvaluate, Input_Length.GetInt()))
      Subgraph_SwingLow[IndexToEvaluate] = sc.Low[IndexToEvaluate] - ArrowOffset;
  }
  else if (IsSwingLowAllowEqual_S(sc, true , IndexToEvaluate, Input_Length.GetInt()))
    Subgraph_SwingLow[IndexToEvaluate] = sc.Low[IndexToEvaluate] - ArrowOffset;

  if (Input_ExtendSwings.GetYesNo())
  {
    if (Subgraph_SwingHigh[IndexToEvaluate] != 0)
    {
      sc.AddLineUntilFutureIntersection
      (IndexToEvaluate
        , 1 // LineIDForBar
        , Subgraph_SwingHigh[IndexToEvaluate]
        , Subgraph_LineProperties.PrimaryColor
        , Subgraph_LineProperties.LineWidth
        , Subgraph_LineProperties.LineStyle
        , false
        , false
        , ""
      );
    }
    else
    {
      sc.DeleteLineUntilFutureIntersection(IndexToEvaluate, 1);
    }
  }

  if (Input_ExtendSwings.GetYesNo())
  {
    if (Subgraph_SwingLow[IndexToEvaluate] != 0)
    {
      sc.AddLineUntilFutureIntersection
      (IndexToEvaluate
        , 2 // LineIDForBar
        , Subgraph_SwingLow[IndexToEvaluate]
        , Subgraph_LineProperties.SecondaryColor
        , Subgraph_LineProperties.LineWidth
        , Subgraph_LineProperties.LineStyle
        , false
        , false
        , ""
      );
    }
    else
    {
      sc.DeleteLineUntilFutureIntersection(IndexToEvaluate, 2);
    }
  }
}

/******************************************************************************************/

scsf_SwingHighAndLow swingStudy(100);

int CalculateStudy(StudyData std::data) {
// Loop through the bars
for (int bar = data.StartBar; bar < data.EndBar; bar++) {
// Calculate the "scsf_SwingHighAndLow" study
swingStudy.CalculateSwingHighAndLow(data, bar);

// Generate buy signal if there is a swing low
if (swingStudy.Subgraph_SwingLow[bar] != 0) {
// Set the buy signal for the current bar
data.PlotArrow[bar] = 1; // Or any other signal you want to use
}
}

return 0;
}

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

Login

Login Page - Create Account