Average (Function)

image\trumpet2.gif Disclaimer

The Average function calculates the standard arithmetic mean of prices or values over a range of bars. It may also be called a moving average, since the values are recalculated for every bar.

Syntax

Average(Price,Length)

Returns (Double)

A numeric value for the current bar.

Parameters

Name

Type

Description

Price

Numeric

Specifies which bar value (price, function, or formula) to use.

Length

Numeric

Sets the number of bars to consider.

Remarks

The Average function is often used to smooth the values of functions or indicators.

Average (arithmetic mean) is the sum of n numbers divided by n.

  Average = (1+3+5) / 3 = 3

The input parameter Price can be a bar value such as Close, High, Low, Open, or Volume. It can also be any mathematical calculation such as (High + Low) / 2, or a numeric function such as RSI, Stochastic, or ADX.

The value for the Length input parameter should always be a positive whole number.

Examples

Assigns the 9 bar moving average of the Close to Value1, then plots Value1:

Value1 = Average(Close,9);

Plot1(Value1, "AvgClose");

Assigns the 15 bar moving average of the range;(High + Low) /2 to Value1, then plots Value1:

Value1 = Average((High + Low)/2,15);

Plot1(Value1, "AvgRng");

Assigns the 10 bar moving average of the RSI function to Value1, then plots Value1:

Value1 = Average(RSI(Close,14),10);

Plot1(Value1, "AvgRSI");

Assigns the 20 bar moving average of the custom variable myRange to Value1, then plots Value1:

Vars: myRange(0);

MyRange = ((High[1]-Low[1]) + (HighLow))/2;

Value1 = Average(myRange, 20);

Plot1(Value1, "AvgRng");