Login Page - Create Account

Support Board


Date/Time: Sat, 08 Feb 2025 02:05:34 +0000



Post From: Calculate a moving average based on a custom variable

[2020-06-17 19:58:47]
Ackin - Posts: 1865
"Use SG", I wrote it to you at the end of the message as another variant (see note), you sent only a part of your code, I can't know if you have a loop for filling the array and processing it.

Below you have a code that is definitely functional




SCSFExport scsf_CustomMovingAverage(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Avg = sc.Subgraph[0];
  SCSubgraphRef realBody = sc.Subgraph[1];

  SCInputRef Length = sc.Input[1];

  if (sc.SetDefaults)
  {
    sc.GraphName = "Moving Average";

    sc.GraphRegion = 1;
    sc.ValueFormat = 2;
    sc.AutoLoop = 1;

    Avg.Name = "Avg";
    Avg.DrawStyle = DRAWSTYLE_LINE;
    Avg.PrimaryColor = RGB(0, 255, 0);
    Avg.LineWidth = 1;
    Avg.DrawZeros = true;

    Length.Name = "Length";
    Length.SetInt(10);
    Length.SetIntLimits(1, MAX_STUDY_LENGTH);

    return;
  }
  sc.DataStartIndex = Length.GetInt();

  realBody[sc.Index] = sc.BaseData[SC_OPEN][sc.Index] - sc.BaseData[SC_LAST][sc.Index];
  sc.MovingAverage(realBody, Avg, MOVAVGTYPE_SIMPLE, Length.GetInt());
}