Mathematical/probuilder · probacktest · proorder · proscreener

TAN

TAN in ProBuilder returns the tangent of an angle given in radians. Undefined at 90 degrees and its odd multiples. Syntax, gotchas and worked examples.

Syntax

probuilder
TAN(a)

Parameters

NameTypeDescription
anumberThe angle in radians. Degrees must be converted to radians before the call.

Formula

code
TAN(a) = SIN(a) / COS(a),   with a in radians

TAN(0) returns 0 and TAN(PI/4) returns 1. Near 90 degrees the value grows without bound and is undefined exactly at that angle.

How it works

TAN treats its argument as an angle in radians, so a degree value must be converted with a * PI / 180 first. Unlike sine and cosine, tangent is not bounded: it runs from minus infinity to plus infinity and blows up as the angle nears 90 degrees or 270 degrees, where the cosine denominator reaches zero and the function is undefined.

Guard against those angles in code that sweeps a range. Its inverse, ATAN, is often more useful in trading because it maps an unbounded slope back to a bounded angle.

Examples

Example 1, Tangent of an angle in degrees (Indicator)

probuilder
// Convert 45 degrees to radians, then take the tangent
angleInDegrees = 45
angleInRadians = angleInDegrees * 3.14159265 / 180
result = TAN(angleInRadians)
RETURN result AS "TAN(45 deg)"

The conversion is required. The code returns 1, the tangent of 45 degrees, whereas TAN(45) would treat 45 as radians.

Example 2, Bounded tangent readings only (ProScreener)

probuilder
// Avoid angles near 90 degrees where tangent is unstable
angleDeg = 30
angleRad = angleDeg * 3.14159265 / 180
safe = ABS(COS(angleRad)) > 0.01
t = TAN(angleRad)
SCREENER[safe](t AS "Tangent")

Testing that the cosine is not near zero keeps the tangent away from its undefined blow-up points.

Example 3, Slope-to-tangent consistency check (ProOrder)

probuilder
// Reconstruct a slope from an angle and gate entries on it
ma = Average[30](close)
slopeAngle = ATAN(ma - ma[1])
reconSlope = TAN(slopeAngle)
IF reconSlope > 0 AND NOT LongOnMarket AND close CROSSES OVER ma THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

ATAN turns the slope into a safe angle and TAN reverses it, since the angle stays inside the range where tangent is well defined.

Common errors and gotchas

  • Undefined at 90 degrees and its odd multiples. At 90, 270, 450 degrees and so on the cosine is zero and tangent is undefined, producing very large or invalid values. Guard those angles in code.
  • Angle must be in radians. TAN expects radians. Multiply a degree value by PI / 180 first, otherwise the result is meaningless.
  • Unbounded output. Unlike SIN and COS, tangent has no [-1, 1] limit. A huge magnitude near a discontinuity is expected, not a bug, but it can distort downstream math.
  • SIN, sine of an angle in radians, the numerator of tangent.
  • COS, cosine of an angle in radians, the denominator of tangent.
  • ATAN, arc tangent, the inverse of TAN.
  • ASIN, arc sine.
  • ACOS, arc cosine.
  • ABS, absolute value, useful to guard the cosine denominator.
  • LinearRegressionSlope, slope of a fitted line, related to angle work.