Login Page - Create Account

Support Board


Date/Time: Sat, 28 Jun 2025 05:26:22 +0000



Post From: ACSIL - I do not understand how to plot a moving average

[2021-09-17 06:41:46]
User907968 - Posts: 840
sc.Subgraph[0][sc.Index] = SubgraphSMA[sc.Index];
This is not the solution, 'sc.Subgrah[0]' and 'SubgraphSMA', refer to the same data -> SCSubgraphRef SubgraphSMA = sc.Subgraph[0];

'SubgraphSMA' is automatically filled with data when 'sc.SimpleMovAvg' is called, so there is nothing to do there.


#include "sierrachart.h"

SCDLLName("SmaTest")

SCSFExport scsf_SmaTest(SCStudyInterfaceRef sc)
{
SCSubgraphRef SubgraphSMA = sc.Subgraph[0];


// a - use subgraph for 'indicator' values
SCSubgraphRef SubgraphVolume = sc.Subgraph[1];

// or
// b - use extra array from SubgraphSMA for 'indicator' values
// SCFloatArrayRef IndicatorArray = SubgraphSMA.Arrays[0];

SCInputRef Input_SMAPeriod = sc.Input[0];

if (sc.SetDefaults)
{
sc.GraphName = "Sma plot test";

SubgraphSMA.Name = "SMA";
SubgraphSMA.DrawStyle = DRAWSTYLE_LINE;
SubgraphSMA.DrawZeros = true;

SubgraphVolume.Name = "Volume";
SubgraphVolume.DrawStyle = DRAWSTYLE_LINE;
SubgraphVolume.DrawZeros = true;

Input_SMAPeriod.Name = "SMA Period";
Input_SMAPeriod.SetInt(3);

sc.AutoLoop = 1;
}

int Indicator = sc.GetRecentAskVolumeAtPrice(sc.Ask) - sc.GetRecentBidVolumeAtPrice(sc.Bid);

// a
SubgraphVolume[sc.Index] = Indicator;

sc.SimpleMovAvg(
SubgraphVolume,
SubgraphSMA,
Input_SMAPeriod.GetInt()
);

// b
//IndicatorArray[sc.Index] = Indicator;

//sc.SimpleMovAvg(
// IndicatorArray,
// SubgraphSMA,
// Input_SMAPeriod.GetInt()
//);
}