Sidechair

math.cos()

Browse the reference

Returns the cosine of an angle given in radians.

Try it in the editor

math.cos takes an angle in radians and returns a value between -1 and 1. It is the sine shifted a quarter turn.

math.cos(0) is 1 and math.cos(math.pi) is -1. Use it with math.sin to build phase-shifted waves or rotate coordinates.

Syntax

Pine Script
math.cos(angle: simple int/float) -> simple float
math.cos(angle: input int/float) -> input float
math.cos(angle: const int/float) -> const float
math.cos(angle: series int/float) -> series float

Arguments

NameTypeDefaultDescription
angleconst/input/simple/series int/floatrequiredThe angle in radians, not degrees. Use math.toradians() to convert from degrees.

Returns

const/input/simple/series float: the cosine, from -1 to 1.

Remarks

  • Convert from degrees with math.toradians first.

Example

Pine ScriptAngle in degreesOpen in editor
//@version=6
indicator("Cosine of degrees")
deg = bar_index % 360
plot(math.cos(math.toradians(deg)), "cos", color = color.purple)

See also

Runs on Sidechair