Sidechair

math.avg()

Browse the reference

Returns the arithmetic mean of the numbers you pass.

Try it in the editor

math.avg adds its arguments and divides by how many were given. Pass as many numbers as you need.

hl2 is math.avg(high, low) in short form, and ohlc4 is the average of all four prices. If any argument is na, the result is na.

Syntax

Pine Script
math.avg(number0, number1, ...: simple int/float) -> simple float
math.avg(number0, number1, ...: series int/float) -> series float

Arguments

NameTypeDefaultDescription
number0, number1, ...simple/series int/floatrequiredTwo or more numbers to average.

Returns

simple/series float: the mean of the arguments.

Remarks

  • To average a series over time, use ta.sma; math.avg averages values across arguments on one bar.

Example

Pine ScriptMidpoint of two averagesOpen in editor
//@version=6
indicator("Mid average", overlay = true)
mid = math.avg(ta.ema(close, 10), ta.ema(close, 30), ta.sma(close, 50))
plot(mid, "Mean of three", color = color.fuchsia, linewidth = 2)

See also

Runs on Sidechair