MovingAverageOptions

MovingAverageOptions ( seriesIndex ;​ numOfIntervals ;​ calculationMethod ;​ alignment ;​ doExtrapolate ;​ hShift ;​ vShift ;​ isRelativeHShift ;​ isRelativeVShift )

Argument Type Range Default Note
seriesIndex int 0..10000 all
numOfIntervals int 1..10000 2
calculationMethod int 0..3 average
alignment int 1..4 backward
doExtrapolate int 0..1 off
hShift num -inf..+inf 0
vShift num -inf..+inf 0
isRelativeHShift int 0..1 off
isRelativeVShift int 0..1 off
Examples

MovingAverageOptions(all;​50;​;​;​on) /* Extrapolate. */

MovingAverageOptions(1;​100;​;​;​on;​;​5;​;​on) /* 5% vShift */

Description

By using the MovingAverageOptions() function, calculating and representing moving averages can be varied in many ways. For example, using the 3rd argument calculationMethod, three different methods for calculating the average values can be chosen. As the default, the average line is calculated using the arithmetic mean values (calculationMethod = average). Instead of the mean value, it is also possible to use the median (calculationMethod = median).

MOVING_AVERAGE_OPTIONS_01
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 270 263 233 229 269 285 362 410 411 456 504 458 474 470 463 257 308 270 325 316 213 263 267 245 321 381 389 401 366 315 305 291 275 299 272)

3

LineChart()

4

MovingAverage(1;​10;​median)

5

MovingAverage(1;​25;​average)

6

MovingAverageLineStyle(1;​10;​median;​poly;​1;​#063e9e)

7

MovingAverageLineStyle(1;​25;​average;​poly;​1;​#00a79d)

8

MovingAverageOptions(1;​10;​median)

9

MovingAverageOptions(1;​25;​average)

10

/* Set up styles. */

11

LineStyle(1;​poly;​1.0;​#f81a53)

12

/* Set up axes. */

13

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

14

AxisLine(all;​0)

15

AxisMajorTicks(all;​0)

16

/* Set up grid. */

17

MajorGridLineWidths(x;​y;​0.25)

18

MajorGridLineWidths(y;​x;​0)

19

CloseDrawing()

MOVING_AVERAGE_OPTIONS_01

The 3rd possibility has to do with calculating an exponentially weighted average (calculationMethod = exponential) using the formula:

  • w[i+1] = w[i] + a*(y[i+1]-w[i])
  • a.....Smoothing constant between 0 and 1
  • y[]...original value
  • w[]...exponentially weighted value

The smoothing constant is entered as the 4th argument in the MovingAverage() function instead of the weighting factors. In addition, a start value can also be added to the smoothing constant as an option. In the event of exponential smoothing, the arguments alignment and doExtrapolate are ignored.

MOVING_AVERAGE_OPTIONS_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;​;​exponential;​0.25) /* 0.25 = smoothing constant. */

5

MovingAverageLineStyle(1;​2;​exponential;​smooth;​1;​#c002a0)

6

MovingAverageOptions(1;​;​exponential)

7

/* Set up styles. */

8

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

9

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

10

/* Set up axes. */

11

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

12

AxisLine(all;​0)

13

AxisMajorTicks(all;​0)

14

/* Set up grid. */

15

MajorGridLineWidths(x;​y;​0.25)

16

MajorGridLineWidths(y;​x;​0)

17

CloseDrawing()

MOVING_AVERAGE_OPTIONS_02
MOVING_AVERAGE_OPTIONS_03
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 15 26 20 23)

3

LineChart()

4

MovingAverage(1;​;​exponential;​0.5 15) /* 0.5...smoothing constant, 15...start value. */

5

MovingAverageLineStyle(1;​;​exponential;​smooth;​1;​#c002a0)

6

MovingAverageOptions(1;​;​exponential)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_03

By using the 4th argument alignment, the position of the average line can be controlled. Average lines — except for exponential smoothing — are always "somewhat shorter" than the original curve since the number of points for drawing the average lines is always numOfIntervals-1 less than the number of points of the original curve. In other words, for example, a 50-day average line has 49 fewer points than the original curve. Four constants are available for aligning the average lines. As the default, the average line is aligned with the last data point (alignment = backward).

MOVING_AVERAGE_OPTIONS_04
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​4;​average)

5

MovingAverageLineStyle(1;​4;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​4;​average;​backward)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_04

The average line is aligned with with the first data point if alignment = forward is set.

MOVING_AVERAGE_OPTIONS_05
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​4;​average)

5

MovingAverageLineStyle(1;​4;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​4;​average;​forward)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_05

If alignment = centeredBackward or alignment = centeredForward is set, the average line is centered. That means, for example, for an interval number of 50 and when alignment = centeredBackward, the average line is indented 25 points and 24 points when alignment = centeredForward. If the number of missing points is even, both constants centeredForward and centeredBackward produce the same result.

MOVING_AVERAGE_OPTIONS_06
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​4;​average)

5

MovingAverageLineStyle(1;​4;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​4;​average;​centeredBackward)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_06
MOVING_AVERAGE_OPTIONS_07
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​4;​average)

5

MovingAverageLineStyle(1;​4;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​4;​average;​centeredForward)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_07

By activating the argument doExtrapolate = on, it is possible to extend the average line over the entire data area.

MOVING_AVERAGE_OPTIONS_08
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​6;​average)

5

MovingAverageLineStyle(1;​6;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​6;​average;​centeredForward;​on)

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_08

Using doExtrapolate = on proves to be advantageous when representing the total average, i.e. the average of the complete data series. Generally, the total average is calculated for a data series consisting of n values by setting the number of intervals equals n.

MOVING_AVERAGE_OPTIONS_09
1

OpenDrawing(250;​150)

2

ChartData(9 15 20 23 18 22 26 24 23 23 26)

3

ScatterChart(;​on)

4

MovingAverage(1;​11;​average)

5

MovingAverageLineStyle(1;​11;​average;​poly;​1;​#c002a0)

6

MovingAverageOptions(1;​11;​average;​;​on)

7

/* Set up styles. */

8

SymbolStyle(1;​spokes5;​6;​1;​#4682b4)

9

/* Set up axes. */

10

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

11

AxisLine(all;​0)

12

AxisMajorTicks(all;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_09

As an option, moving averages can be shifted by entering a horizontal offset value (hOffset) and/or a vertical offset value (vOffset). Offset values can either be entered as absolute values (isRelativeHShift = off and isRelativeVShift = off) (default) or in percent of the average values (isRelativeHShift = on and isRelativeVShift = on).

MOVING_AVERAGE_OPTIONS_10
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 270 263 233 229 269 285 362 410 411 456 504 458 474 470 463 257 308 270 325 316 213 263 267 245 321 381 389 401 366 315 305 291 275 299 272)

3

LineChart()

4

MovingAverage(1;​10;​average)

5

MovingAverageLineStyle(1;​10;​average;​poly;​2 2 2;​#c002a0)

6

MovingAverageOptions(1;​10;​average;​;​;​5;​;​on) /* Shift 5% to the right. */

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(y;​0)

12

AxisMajorTicks(y;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_10
MOVING_AVERAGE_OPTIONS_11
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)

3

ScatterChart()

4

MovingAverage(1;​30;​average)

5

MovingAverageLineStyle(1;​30;​average;​poly;​1.0;​#c002a0)

6

MovingAverageOptions(1;​30;​average;​;​on;​;​20) /* Shift 20 units to the top. */

7

/* Set up styles. */

8

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

9

/* Set up axes. */

10

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

11

AxisLine(y;​0)

12

AxisMajorTicks(y;​0)

13

/* Set up grid. */

14

MajorGridLineWidths(x;​y;​0.25)

15

MajorGridLineWidths(y;​x;​0)

16

CloseDrawing()

MOVING_AVERAGE_OPTIONS_11
Scroll to Top
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×