Returns the cosine of an angle given in radians.
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
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 floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| angle | const/ | required | The 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.toradiansfirst.
Example
//@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