Investment Studio > Expressions > Functions > Indicator > SAR
float array[*][2] sar(float array[*][3] dhl, float min_af = 0.02, float max_af = 0.2)
Returns a two-column array containing dates (first column) and corresponding parabolic Stop And Reverse (SAR) values (second column). Given n input rows in dhl, n - 1 rows are returned.
dhl is a three-column array containing daily price range quotes. Each row is structured as follows:
| Column # | Content |
| 1 | The quote date. |
| 2 | The day's high (highest traded price). |
| 3 | The day's low (lowest traded price). |
The array is assumed to be time-sorted, with earlier dates preceding later dates.
Automatic type conversion allows the use of date strings as arguments instead of explicit date values.
min_af is the initial acceleration factor and the step by which the acceleration factor is successively incremented (from min_af to 2 *min_af to 3 * min_af and so on). If omitted, min_af defaults to 0.02.
max_af is the terminal (largest allowed) acceleration factor. If omitted, max_af defaults to 0.2.
Interpretation
SAR is a trend-following indicator designed to create a trailing stop.
In an uptrend, the stop is initially set at the lowest low of the last two trading days; in a downtrend, the stop is initially set at the highest high of the last two trading days. Every trading day, the stop then accelerates in the trend's direction, resulting in a characteristic parabolic trajectory. The signal is eventually triggered when the stop penetrates the day's price range or the previous trading day's price range. At this point, positions in the asset (long in an uptrend, short in a downtrend) should be exited.
Welles Wilder (New Concepts in Technical Trading Systems, 1978) originally created SAR as the basis for a system which always kept the trader in the market. When stopped out of a long position, the trader was to immediately establish a short position; when stopped out of a short position, the trader was to immediately establish a long position. In practice, consolidation periods without a clear trend can cause whipsaw galore, so Wilder recommended augmenting the system with a trend strength indicator like ADX and only entering the market in the presence of a clear trend, and then only in the trend's direction.
The arguments min_af and max_af are crucial to the successful use of SAR, and must be determined from historical data for the asset under study.
| In an
uptrend, the daily SAR value is given by the expression SAR = previous SAR + (previous SAR - highest price so far) * acceleration factor The acceleration factor starts out = min_af and is then incremented by min_af (up to the terminal value max_af) every time price hits a new high. |
|
| In a
downtrend, the daily SAR value is given by the expression SAR = previous SAR + (lowest price so far - previous SAR) * acceleration factor The acceleration factor starts out = min_af and then is incremented by min_af (up to the terminal value max_af) every time price hits a new low. |
A higher min_af means faster acceleration toward price and therefore faster triggering of the exit signal. A higher max_af means that the acceleration factor is allowed to grow larger, and will lead to faster acceleration in the later stages of the SAR's trajectory, provided that there are enough new highs (in an uptrend) or lows (in a downtrend) before the exit signal is triggered.
For a real life example, consider Barrick Gold (NYSE:ABX) from January 1 to December 31, 2001:

The chart shows the price in standard candlestick form and the corresponding SAR with default arguments (in blue).
Example
Assuming standard US date format settings,
=sar({{"1/1/1990", 100, 90}, {"1/2/1990", 97, 84}, {"1/3/1990", 95, 89}})
returns the array {{32875, 100}, {32876, 99.68}}. 32875 is the date code for 1/2/1990; 100 is the SAR for that date. The first stop is located above the price (at the highest high of the first two days) because the midpoint of the second day's price range is lower than the midpoint of the first day's price range, indicating a downtrend. 32876 is the date code for 1/3/1990; 99.68 = 100 + (84 - 100) * 0.02 is the SAR for that date, given the default min_af = 0.02.