ParabolicSAR

Calculates the ParabolicSAR indicator.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
applyToSeries <Number>
close
-
periodNumber5-

Returns: Series<Number>

ParabolicSAR is a built-in function - you can use it directly. Below is an example implementation:

1234567891011121314151617181920212223242526272829303132333435
function ParabolicSAR(applyTo = close, period = 5):
initialAF = 0.02
AFStep = 0.02
maxAF = 0.2
highest = Highest(high, period)
lowest = Lowest(low, period)

series isRising: once: Rises(applyTo)

series EP: once: highest if isRising else lowest rest: high if isRising and high > EP else low if not isRising and low < EP else EP

series AF: once: initialAF
if EP != EP: Math.Min(AF + AFStep, maxAF)

series RPSAR: once: lowest rest: RPSAR + (AF * (EP - RPSAR))

series FPSAR: once: highest rest: FPSAR - (AF * (FPSAR - EP))

reversal = RPSAR > low if isRising else FPSAR < high

if reversal update isRising: not isRising
if reversal update EP: highest if isRising else lowest
if reversal update AF: initialAF
if reversal and isRising update RPSAR: lowest
if reversal and not isRising update FPSAR: highest

RPSAR if isRising else FPSAR