The Parabolic SAR (Stop and Reverse) is a trend-following indicator developed by J. Welles Wilder Jr., the creator of other seminal indicators like the RSI and ADX. Its primary purpose is to identify the direction of a trend and provide exit points. The “SAR” in its name stands for “Stop and Reverse,” which aptly describes its function: when the trend reverses, the indicator stops and repositions itself on the other side of the price.
Visually, it appears as a series of dots on the chart, either below the price in an uptrend or above the price in a downtrend. These dots act as a trailing stop-loss, moving closer to the price as the trend progresses. This lesson breaks down the precise mathematical calculation behind this elegant and effective indicator.
The entire logic of the Parabolic SAR is captured in a single iterative formula. For any given time period t, the SAR for the next period (t+1) is calculated based on the current period’s values.
The core formula is:
This formula looks simple, but its power lies in how the components—the Extreme Point (EP) and the Acceleration Factor (α)—are updated dynamically.
Let’s break down the process of calculating the Parabolic SAR series for a given price history (Open, High, Low, Close).
To start, you need to determine the initial trend. A simple method is to compare the first two periods. If the close of the second candle is higher than the first, an uptrend is assumed.
The Acceleration Factor (α) always starts at its initial value, 0.02.
Using the main formula, calculate the next period’s SAR. However, there are some specific rules to prevent the SAR from moving into the prior period’s price range:
The indicator’s sensitivity is controlled by the AF (), which changes only when the trend makes a new price extreme.
If no new extreme is made, the EP and AF remain unchanged for the next period’s calculation.
A reversal is the signal that the current trend has ended.
When a reversal occurs:
Let’s walk through an example using a hypothetical 15-minute chart for NIFTY futures. We will use the standard parameters: Initial AF = 0.02, Increment = 0.02, Max AF = 0.20. The results are rounded to two decimal places for clarity.
| Candle | Open | High | Low | Close | Trend | SAR | EP | AF | Notes |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 50.0 | 52.0 | 49.0 | 51.0 | UP | 49.00 | 52.0 | 0.02 | Initial UP trend assumed. SAR is set to Low, EP to High. |
| 2 | 51.0 | 54.0 | 50.0 | 53.0 | UP | 49.06 | 54.0 | 0.04 | SAR = 49 + 0.02(52-49). New High made, so EP is updated and AF increases. |
| 3 | 53.0 | 53.5 | 51.0 | 52.0 | UP | 49.26 | 54.0 | 0.04 | SAR = 49.06 + 0.04(54-49.06). No new High, so EP and AF are unchanged. |
| 4 | 52.0 | 52.5 | 49.0 | 49.5 | DOWN | 54.00 | 49.0 | 0.02 | Next SAR (49.45) > Low (49.0). Reversal! SAR flips to previous EP. |
| 5 | 49.5 | 50.0 | 47.0 | 48.0 | DOWN | 53.90 | 47.0 | 0.04 | SAR = 54 + 0.02(49-54). New Low made, so EP is updated and AF increases. |
| 6 | 48.0 | 49.0 | 46.0 | 46.5 | DOWN | 53.62 | 46.0 | 0.06 | SAR = 53.9 + 0.04(47-53.9). New Low made, so EP is updated and AF increases. |
| 7 | 46.5 | 48.0 | 45.0 | 47.5 | DOWN | 53.17 | 45.0 | 0.08 | SAR = 53.62 + 0.06(46-53.62). New Low made, so EP is updated and AF increases. |
| 8 | 47.5 | 48.5 | 46.0 | 47.0 | DOWN | 52.53 | 45.0 | 0.08 | SAR = 53.17 + 0.08(45-53.17). No new Low. EP and AF unchanged. |
| 9 | 47.0 | 49.0 | 46.0 | 48.5 | DOWN | 51.93 | 45.0 | 0.08 | SAR = 52.53 + 0.08(45-52.53). No new Low. EP and AF unchanged. |
| 10 | 48.5 | 50.0 | 47.5 | 49.0 | UP | 45.00 | 50.0 | 0.02 | Next SAR (51.38) > High (50.0). Reversal! SAR flips to previous EP. |
Here is a Python function that implements the Parabolic SAR calculation on a Pandas DataFrame. The DataFrame `df` must contain ‘high’ and ‘low’ columns. The code follows the logic described above.
import pandas as pd
import numpy as np
def calculate_parabolic_sar(df, initial_af=0.02, af_increment=0.02, max_af=0.20):
# Make a copy to avoid SettingWithCopyWarning
df = df.copy()
# Create columns for SAR and its components
df['SAR'] = 0.0
df['EP'] = 0.0
df['AF'] = 0.0
# Determine the starting trend (True for uptrend, False for downtrend)
uptrend = df['close'].iloc[1] > df['close'].iloc[0]
# Initialize first row values
if uptrend:
df.loc[df.index[0], 'SAR'] = df['low'].iloc[0]
df.loc[df.index[0], 'EP'] = df['high'].iloc[0]
else:
df.loc[df.index[0], 'SAR'] = df['high'].iloc[0]
df.loc[df.index[0], 'EP'] = df['low'].iloc[0]
df.loc[df.index[0], 'AF'] = initial_af
# Iterate through the DataFrame starting from the second row
for i in range(1, len(df)):
# Get previous row's values
prev_sar = df['SAR'].iloc[i-1]
prev_ep = df['EP'].iloc[i-1]
prev_af = df['AF'].iloc[i-1]
# Carry over the trend direction initially
current_uptrend = uptrend
# Calculate the potential next SAR
sar_next = prev_sar + prev_af * (prev_ep - prev_sar)
# -- Reversal Check --
if current_uptrend:
# If the next SAR is below the current low, a reversal occurs
if sar_next > df['low'].iloc[i]:
uptrend = False # Flip to downtrend
sar_next = prev_ep # New SAR is the previous Extreme Point
ep_next = df['low'].iloc[i]
af_next = initial_af
else: # No reversal
uptrend = True
af_next = prev_af
ep_next = prev_ep
# Update EP and AF if new high is made
if df['high'].iloc[i] > prev_ep:
ep_next = df['high'].iloc[i]
af_next = min(max_af, prev_af + af_increment)
else: # Current trend is down
# If the next SAR is above the current high, a reversal occurs
if sar_next < df['high'].iloc[i]:
uptrend = True # Flip to uptrend
sar_next = prev_ep # New SAR is the previous Extreme Point
ep_next = df['high'].iloc[i]
af_next = initial_af
else: # No reversal
uptrend = False
af_next = prev_af
ep_next = prev_ep
# Update EP and AF if new low is made
if df['low'].iloc[i] < prev_ep:
ep_next = df['low'].iloc[i]
af_next = min(max_af, prev_af + af_increment)
# Set the values for the current row
df.loc[df.index[i], 'SAR'] = sar_next
df.loc[df.index[i], 'EP'] = ep_next
df.loc[df.index[i], 'AF'] = af_next
return df
# Example usage:
# Assuming df is your DataFrame with OHLC data
# df_with_sar = calculate_parabolic_sar(df)
initial_af): 0.02. This is the starting sensitivity.af_increment): 0.02. This is how much the sensitivity increases on each new price extreme.max_af): 0.20. This caps the sensitivity to prevent the SAR from becoming too tight in a prolonged trend.These standard values, proposed by Wilder, offer a balance between responsiveness and reliability. While they can be adjusted, most charting platforms and traders use them as the default setting. Understanding how these parameters influence the SAR's calculation is key to interpreting its signals correctly.