ATR Trailing Stop
get_atr_stop(quotes, lookback_periods=21, multiplier=3, end_type=EndType.CLOSE)
Parameters
| name | type | notes |
|---|---|---|
quotes | Iterable[Quote] | Iterable of the Quote class or its sub-class. • See here for usage with pandas.DataFrame |
lookback_periods | int, default 21 | Number of periods (N) for the ATR evaluation. Must be greater than 1. |
multiplier | float, default 3 | Multiplier sets the ATR band width. Must be greater than 0 and is usually set around 2 to 3. |
end_type | EndType, default EndType.Close | Determines whether Close or High/Low is used as basis for stop offset. See EndType options below. |
Historical quotes requirements
You must have at least N+100 periods of quotes to cover the convergence periods. Since this uses a smoothing technique, we recommend you use at least N+250 periods prior to the intended usage date for optimal precision.
quotes is an Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
EndType options
from stock_indicators.indicators.common.enums import EndType
| type | description |
|---|---|
CLOSE | Stop offset from Close price (default) |
HIGH_LOW | Stop offset from High or Low price |
Returns
AtrStopResults[AtrStopResult]
- This method returns a time series of all available indicator values for the
quotesprovided. AtrStopResultsis just a list ofAtrStopResult.- It always returns the same number of elements as there are in the historical quotes.
- It does not return a single incremental indicator value.
- The first
Nperiods will haveNoneAtrStop values since there’s not enough data to calculate.
⚞ Convergence warning: the line segment before the first reversal and the first
N+100periods are unreliable due to an initial guess of trend direction and precision convergence for the underlying ATR values.
AtrStopResult
| name | type | notes |
|---|---|---|
date | datetime | Date |
atr_stop | Decimal, Optional | ATR Trailing Stop line contains both Upper and Lower segments |
buy_stop | Decimal, Optional | Upper band only (green) |
sell_stop | Decimal, Optional | Lower band only (red) |
buy_stop and sell_stop values are provided to differentiate buy vs sell stop lines and to clearly demark trend reversal. atr_stop is the contiguous combination of both upper and lower line data.
Utilities
See Utilities and Helpers for more information.
Example
from stock_indicators import indicators
# This method is NOT a part of the library.
quotes = get_historical_quotes("SPY")
# calculate 21-period ATR Stop
results = indicators.get_atr_stop(quotes)
About ATR Trailing Stop
Created by Welles Wilder, the ATR Trailing Stop indicator attempts to determine the primary trend of Close prices by using Average True Range (ATR) band thresholds. It can indicate a buy/sell signal or a trailing stop when the trend changes. [Discuss] 💬
