Sidechair

math.tan()

Browse the reference

Returns the tangent of an angle given in radians.

Try it in the editor

math.tan is math.sin divided by math.cos. It grows without bound as the angle approaches a quarter turn.

The tangent of a slope angle gives the rise per run, so it converts an angle to a gradient.

Syntax

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

Arguments

NameTypeDefaultDescription
angleconst/input/simple/series int/floatrequiredThe angle in radians, not degrees. The result is very large near a quarter turn.

Returns

const/input/simple/series float: the tangent.

Remarks

  • Clip the output when plotting, since values near odd multiples of math.pi / 2 are huge.

Example

Pine ScriptTangent of a slow angleOpen in editor
//@version=6
indicator("Tangent")
angle = math.toradians(bar_index % 80)
plot(math.tan(angle), "tan", color = color.red)

See also

Runs on Sidechair