MovingAverage

MovingAverage ( seriesIndex ;​ numOfIntervals ;​ calculationMethod ;​ weightList )

Argument Type Range Default Note
seriesIndex int 0..10000 all
numOfIntervals int 1..10000 2
calculationMethod int 0..3 average
weightList num[] -inf..+inf 1
Examples

MovingAverage(all;​50)

MovingAverage(2;​20;​;​1.1 1.05 1.03 1.025 1.02 1.015 1.013 1.01)

Description

As an option, moving averages can be added to scatter, line, area and bar charts. A total of 3 functions are available for this. They make it possible to:

  • define different methods of calculation
  • design the average lines
  • finely tune them using numerous options

The 1st argument seriesIndex in the MovingAverage() function defines which data series the moving average is to be calculated for. If no series index is defined or if seriesIndex = all is set, the respective function refers to all available data series. The 2nd argument numOfIntervals defines the number of data points for calculating the average values. If, for example, a 50-day average is to be calculated, numOfIntervals =​ 50 should be set. If no interval number is defined, the average values from two data points will be calculated as the default (numOfIntervals =​ 2). The calculation method can be defined by using the 3rd argument calculationMethod. Currently, three methods are available to calculate moving averages. Details can be found at the MovingAverageOptions() function.

MOVING_AVERAGE_01
1

OpenDrawing(250;​150)

2

ChartData(7 15 20 24 26 20)

3

ScatterChart(;​on)

4

MovingAverage() /* Moving average of 2 points. */

5

/* Set up styles. */

6

SymbolStyle(1;​bullet;​4;​1;​#4682b4)

7

/* Set up axes. */

8

AxisLine(all;​0)

9

AxisMajorTicks(all;​0)

10

/* Set up grid. */

11

MajorGridLineWidths(x;​y;​0.25)

12

MajorGridLineWidths(y;​x;​0)

13

CloseDrawing()

MOVING_AVERAGE_01
MOVING_AVERAGE_02
1

OpenDrawing(250;​150)

2

ChartData(57 108 70 125 116 13 63 67 45 121 181 189 201 166 115 105 91 75 99 72 33 29 69 85 162 210 211 256 304 258 274)

3

LineChart(symbol)

4

MovingAverage(1;​6) /* Moving average of 6 points. */

5

/* Set up styles. */

6

LineStyle(1;​poly;​1;​#4682b4)

7

SymbolStyle(1;​circle;​3.5;​1;​#4682b4;​;​white)

8

/* Set up axes. */

9

AxisOptions(x;​none) /* Hide x-axis. */

10

AxisLine(y;​0)

11

AxisMajorTicks(y;​0)

12

/* Set up grid. */

13

MajorGridLineWidths(x;​y;​0.25)

14

MajorGridLineWidths(y;​x;​0)

15

CloseDrawing()

MOVING_AVERAGE_02

As an option, a list of weighting factors can be entered as the 4th argument. In doing so, the 1st data point is multiplied by the 1st weighting factor, the 2nd data point by the 2nd weighting factor, etc. A weighting factor less than 1 lessens the influence of a data point to form an average; a weighting factor greater than 1 increases the influence. If the number of weighting factors is less than the number of data points, then the neutral value 1 is used in place of the missing factors. The weighting factors are to be entered separated by spaces, tabs or line feeds.

MOVING_AVERAGE_03
1

OpenDrawing(250;​150)

2

ChartData(57 108 70 125 116 13 63 67 45 121 181 189 201 166 115 105 91 75 99 72 33 29 69 85 162 210 211 256 304 258 274)

3

ScatterChart()

4

MovingAverage(1;​4;​;​0.1 0.1 0.1 0.3 0.3 0.5 0.7 0.8 0.9 1 1.2)

5

/* Set up styles. */

6

LineStyle(1;​poly;​1;​#4682b4)

7

SymbolStyle(1;​bullet;​3;​1;​#4682b4)

8

/* Set up axes. */

9

AxisOptions(x;​none) /* Hide x-axis. */

10

AxisLine(y;​0)

11

AxisMajorTicks(y;​0)

12

/* Set up grid. */

13

MajorGridLineWidths(x;​y;​0.25)

14

MajorGridLineWidths(y;​x;​0)

15

CloseDrawing()

MOVING_AVERAGE_03
Scroll to Top