Login Page - Create Account

Support Board


Date/Time: Mon, 17 Mar 2025 00:18:01 +0000



Post From: Request for New flex MACD

[2014-04-25 17:10:42]
Sierra Chart Engineering - Posts: 104368
For this, we recommend using the MACD code and customizing it. Refer to this page:
https://www.sierrachart.com/index.php?l=doc/doc_BuildCustomStudiesDLL.html

Here is the code:


SCSFExport scsf_MACD(SCStudyInterfaceRef sc)
{
  SCSubgraphRef MACD    = sc.Subgraph[0];
  SCSubgraphRef MovAvgOfMACD  = sc.Subgraph[1];
  SCSubgraphRef MACDDiff  = sc.Subgraph[2];
  SCSubgraphRef RefLine  = sc.Subgraph[3];

  SCInputRef InputData  = sc.Input[0];
  SCInputRef FastLength    = sc.Input[3];
  SCInputRef SlowLength    = sc.Input[4];
  SCInputRef MACDLength    = sc.Input[5];
  SCInputRef MovingAverageType    = sc.Input[6];


  if(sc.SetDefaults)
  {
    sc.GraphName = "MACD";
    sc.AutoLoop          = 1;

    sc.GraphRegion        = 1;
    sc.ValueFormat        = 3;
    
    MACD.Name = "MACD";
    MACD.DrawStyle = DRAWSTYLE_LINE;
    MACD.DrawZeros = true;
    MACD.PrimaryColor = RGB(0,255,0);

    MovAvgOfMACD.Name  = "MA of MACD";
    MovAvgOfMACD.DrawStyle = DRAWSTYLE_LINE;
    MovAvgOfMACD.DrawZeros = true;
    MovAvgOfMACD.PrimaryColor = RGB(255,0,255);

    MACDDiff.Name = "MACD Diff";
    MACDDiff.DrawStyle = DRAWSTYLE_BAR;
    MACDDiff.DrawZeros = true;
    MACDDiff.PrimaryColor = RGB(255,255,0);

    RefLine.Name = "Line";
    RefLine.DrawStyle = DRAWSTYLE_LINE;
    RefLine.DrawZeros = true;
    RefLine.PrimaryColor = RGB(255,127,0);

    InputData.Name = "Input Data";
    InputData.SetInputDataIndex(SC_LAST);

    FastLength.Name ="Fast Moving Average Length";
    FastLength.SetInt(12);
    FastLength.SetIntLimits(1,MAX_STUDY_LENGTH);

    SlowLength.Name = "Slow Moving Average Length";
    SlowLength.SetInt(26);
    SlowLength.SetIntLimits(1,MAX_STUDY_LENGTH);

    MACDLength.Name = "MACD Moving Average Length";
    MACDLength.SetInt(9);
    MACDLength.SetIntLimits(1,MAX_STUDY_LENGTH);

    MovingAverageType.Name = "Moving Average Type";
    MovingAverageType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);

    return;
  }

  if (MovingAverageType.GetMovAvgType()==MOVAVGTYPE_EXPONENTIAL)
      sc.DataStartIndex = 2;
  else
    sc.DataStartIndex = MACDLength.GetInt() + max(FastLength.GetInt(), SlowLength.GetInt());

  sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACD, sc.Index, FastLength.GetInt(), SlowLength.GetInt(), MACDLength.GetInt(), MovingAverageType.GetInt());

  MovAvgOfMACD[sc.Index]  = MACD.Arrays[2][sc.Index];
  MACDDiff[sc.Index]  = MACD.Arrays[3][sc.Index];
  RefLine[sc.Index]  = 0;  
}


Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing