Login Page - Create Account

Support Board


Date/Time: Sun, 09 Feb 2025 03:50:14 +0000



[Programming Help] - Moving Average Value at Start of Bar

View Count: 475

[2020-08-04 00:55:18]
rahul - Posts: 167
Hello, without replaying a chart I want to find the moving average value at the start of a new bar.
For example a 5 period moving average fluctuates a lot from the time a bar opens till it closes. Looking at a static chart, its easy to determine the value of the moving average (which is always the value at the close of the bar), but how do you know the value when the bar was opened?

I tried the following code, but it doesn't work in this respect.


int& PriorArraySize = sc.GetPersistentInt(1);
float& MovAvgValue = sc.GetPersistentFloat(1);

sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 5);

if (sc.Index == 0)
{
PriorArraySize = sc.ArraySize;
}

// If there are new bars added
if (PriorArraySize < sc.ArraySize)
{
MovAvgValue = sc.Subgraph[0][sc.Index];
}

PriorArraySize = sc.ArraySize;

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

Login

Login Page - Create Account