Login Page - Create Account

Support Board


Date/Time: Sat, 28 Jun 2025 05:16:49 +0000



[Programming Help] - ACSIL - I do not understand how to plot a moving average

View Count: 1572

[2021-09-16 18:15:55]
liquidsquid - Posts: 3
Hello, this might be a dumb question, however, I found it difficult to plot a moving average on a chart. I have a very simple study that calculates the diff between the last traded volume at the ask and at the bid. I am trying to make an SMA out of it, I can plot the diff (I have a DOM opened with the last volume studies), but I can't plot the SMA.


#include "sierrachart.h"

SCDLLName("SmaTest")

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

SCInputRef Input_SMAPeriod = sc.Input[0];

SCFloatArray IndicatorArray;

if (sc.SetDefaults)
{

sc.GraphName = "Sma plot test";

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

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

}

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

IndicatorArray[IndicatorArray.GetArraySize()] = Indicator;

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

What am I doing wrong here? I tried to add things like
sc.Subgraph[0][sc.Index] = SubgraphSMA;
but this is not working. As far as I understand, the SMA is computed, but I can't see how I should plot it.

Any help would be really appreciated!

Thank you
[2021-09-17 04:39:00]
User504778 - Posts: 22
Add

sc.Subgraph[0][sc.Index] = SubgraphSMA[sc.Index];
[2021-09-17 05:41:08]
liquidsquid - Posts: 3
I tried this too but it is not working which is weird...
Here is my code, I added the indicator without the SMA


#include "sierrachart.h"

SCDLLName("SmaTest")

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

SCInputRef Input_SMAPeriod = sc.Input[0];

SCFloatArray IndicatorArray;

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);

IndicatorArray[IndicatorArray.GetArraySize()] = Indicator;

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

sc.Subgraph[0][sc.Index] = SubgraphSMA[sc.Index];
sc.Subgraph[1][sc.Index] = Indicator;

}

Here is a screenshot of my indicator and as you can see, the SMA keeps returning a 0 value...
http://www.sierrachart.com/image.php?Image=163185721132.png
Date Time Of Last Edit: 2021-09-17 05:41:36
[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()
//);
}

[2021-09-17 06:52:14]
liquidsquid - Posts: 3
Thank you, it works! It definitely makes more sense to pass the SubgraphVolum directly. Thanks!

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

Login

Login Page - Create Account