Login Page - Create Account

Support Board


Date/Time: Tue, 14 May 2024 08:41:24 +0000



Post From: Calculation based on subgraph values

[2017-06-28 01:39:02]
Neo - Posts: 198
mkata,

Do you mean something like this-

#include "sierrachart.h"

SCDLLName("MivingAvgBigSmall")

SCSFExport scsf_MovingAverageBigSmall(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Avg = sc.Subgraph[0];

  SCInputRef InputStudy1 = sc.Input[0];
  SCInputRef Study1Subgraph = sc.Input[1];
  SCInputRef StudySubgraph1 = sc.Input[2];  
  SCInputRef Length = sc.Input[3];
  if (sc.SetDefaults)
  {
    sc.GraphName = "Moving Average - Big and Small";

    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;

    InputStudy1.SetStudyID(0);
    Study1Subgraph.SetSubgraphIndex(0);
    StudySubgraph1.Name = "Study Subgraph Reference(Big)";
    StudySubgraph1.SetStudySubgraphValues(0,0);

    Length.Name = "Length";
    Length.SetInt(4);
    Length.SetIntLimits(1, MAX_STUDY_LENGTH);
    
    sc.FreeDLL = 1;
    return;
  }
  
  SCFloatArray Study1Array;
  sc.GetStudyArrayUsingID(StudySubgraph1.GetStudyID(), StudySubgraph1.GetSubgraphIndex(), Study1Array);
  
  sc.MovingAverage(Study1Array,Avg,MOVAVGTYPE_SIMPLE_SKIP_ZEROS,Length.GetInt());
}

From my understanding SC don't have a built in function for what I require, so it requires a custom implementation

MOVAVGTYPE_SIMPLE_SKIP_ZEROS looks to skip zero values and replace them with the last value

eg MOVAVGTYPE_SIMPLE_SKIP_ZEROS, based on length 2, subgraph values: 10[],0[-1],5[-2] = 10
eg My Moving Average, based on length 2, subgrpah values: 10[],0[-1],5[-2]= 7.5


I could be wrong here in my undersatnding, So I stand to be corrected.