Momentum Indicators¶
Momentum indicators measure the rate of price change and help identify overbought/oversold conditions and trend strength.
Oscillators¶
RSI - Relative Strength Index¶
RSI
¶
Relative Strength Index (RSI)
RSI is a momentum oscillator that measures the speed and magnitude of price changes. Developed by J. Welles Wilder in 1978, it oscillates between 0 and 100 and is primarily used to identify overbought and oversold conditions.
RSI compares the magnitude of recent gains to recent losses to determine whether an asset is overbought or oversold. It uses Wilder's smoothing method for the average gains and losses.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Number of periods for RSI calculation (default: 14)
Returns¶
np.ndarray Array of RSI values (0-100)
Notes¶
- Compatible with TA-Lib RSI signature
- Uses Numba JIT compilation for performance
- The first timeperiod values will be NaN
- Lookback period: timeperiod
- Bounded oscillator (0-100)
- Uses Wilder's smoothing method
Formula¶
-
Calculate price changes: Gain = max(0, Price[i] - Price[i-1]) Loss = max(0, Price[i-1] - Price[i])
-
Calculate average gain and loss using Wilder's smoothing: First Average Gain = Sum(Gains over timeperiod) / timeperiod First Average Loss = Sum(Losses over timeperiod) / timeperiod
Subsequent: Average Gain = ((Previous Avg Gain) * (timeperiod-1) + Current Gain) / timeperiod Average Loss = ((Previous Avg Loss) * (timeperiod-1) + Current Loss) / timeperiod
-
Calculate Relative Strength (RS): RS = Average Gain / Average Loss
-
Calculate RSI: RSI = 100 - (100 / (1 + RS))
Alternative formula
RSI = 100 * (Average Gain / (Average Gain + Average Loss))
Lookback period: timeperiod (For timeperiod=14, lookback=14)
Interpretation: - RSI > 70: Overbought (potential sell signal) - RSI < 30: Oversold (potential buy signal) - RSI = 50: Neutral (equal buying/selling pressure) - RSI crossing 50: Trend change signal - Divergence: Price vs RSI moving in opposite directions
Traditional Levels: - Overbought: RSI > 70 - Oversold: RSI < 30 - In strong trends, use 80/20 instead of 70/30
Advantages: - Bounded (0-100) for easy interpretation - Works in trending and ranging markets - Identifies overbought/oversold conditions - Detects divergences - Widely used and understood - Multiple timeframes applicable
Common Uses: - Overbought/oversold identification - Divergence detection - Trend strength measurement - Support/resistance levels - Centerline crossovers (50) - Failure swings (reversal patterns)
Trading Signals:
- Overbought/Oversold:
- Buy when RSI crosses above 30 (leaving oversold)
-
Sell when RSI crosses below 70 (leaving overbought)
-
Centerline Crossover:
- Buy when RSI crosses above 50 (bullish)
-
Sell when RSI crosses below 50 (bearish)
-
Divergence:
- Bullish: Price makes lower low, RSI makes higher low
-
Bearish: Price makes higher high, RSI makes lower high
-
Failure Swings:
- Top: RSI > 70, pullback, fails to exceed previous high, then breaks pullback low
- Bottom: RSI < 30, bounce, fails to break previous low, then breaks bounce high
Timeframe Adjustments: - Short-term: RSI(9) - More sensitive, more signals - Standard: RSI(14) - Wilder's original recommendation - Long-term: RSI(25) - Less sensitive, fewer signals
Limitations: - Can remain overbought/oversold for extended periods - Less effective in strong trending markets - Whipsaw signals in choppy conditions - Lag due to smoothing
Comparison with Related Indicators: - Stochastic: Similar concept, different calculation - MFI: Volume-weighted version of RSI - ROC: Unbounded momentum indicator - MACD: Trend-following momentum indicator
Examples¶
import numpy as np from numta import RSI close = np.array([44, 44.5, 45, 45.5, 45, 44.5, 44, 44.5, 45, 45.5, ... 46, 46.5, 47, 47.5, 48]) rsi = RSI(close, timeperiod=14) print(rsi)
Values will be between 0 and 100¶
See Also¶
MFI : Money Flow Index (volume-weighted RSI) ROC : Rate of Change STOCH : Stochastic Oscillator
Source code in src/numta/api/momentum_indicators.py
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
STOCH - Stochastic Oscillator¶
STOCH
¶
STOCH(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], fastk_period: int = 5, slowk_period: int = 3, slowk_matype: int = 0, slowd_period: int = 3, slowd_matype: int = 0) -> tuple
Stochastic (STOCH)
Stochastic oscillator that shows the position of the closing price relative to the high-low range over a set period. The slow version applies additional smoothing to reduce noise.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array fastk_period : int, optional Period for initial %K calculation (default: 5) slowk_period : int, optional Period for smoothing fast %K to slow %K (default: 3) slowk_matype : int, optional Type of moving average for slow %K (default: 0 = SMA) slowd_period : int, optional Period for smoothing slow %K to slow %D (default: 3) slowd_matype : int, optional Type of moving average for slow %D (default: 0 = SMA)
Returns¶
tuple of np.ndarray (slowk, slowd) - Slow %K and Slow %D arrays
Notes¶
Fast %K = ((Close - Lowest Low) / (Highest High - Lowest Low)) * 100 Slow %K = SMA(Fast %K, slowk_period) Slow %D = SMA(Slow %K, slowd_period)
Source code in src/numta/api/momentum_indicators.py
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | |
STOCHF - Stochastic Fast¶
STOCHF
¶
STOCHF(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], fastk_period: int = 5, fastd_period: int = 3, fastd_matype: int = 0) -> tuple
Stochastic Fast (STOCHF)
Fast Stochastic oscillator that shows the position of the closing price relative to the high-low range over a set period. Returns Fast %K and Fast %D.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array fastk_period : int, optional Period for Fast %K calculation (default: 5) fastd_period : int, optional Period for Fast %D (SMA of Fast %K) (default: 3) fastd_matype : int, optional Type of moving average for Fast %D (default: 0 = SMA)
Returns¶
tuple of np.ndarray (fastk, fastd) - Fast %K and Fast %D arrays
Notes¶
Fast %K = ((Close - Lowest Low) / (Highest High - Lowest Low)) * 100 Fast %D = SMA(Fast %K, fastd_period)
Source code in src/numta/api/momentum_indicators.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 | |
CCI - Commodity Channel Index¶
CCI
¶
CCI(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Commodity Channel Index (CCI)
The Commodity Channel Index (CCI) is a momentum-based oscillator developed by Donald Lambert and featured in Commodities magazine in 1980. CCI measures the variation of a security's price from its statistical mean.
High CCI values indicate that prices are unusually high compared to average, while low values indicate that prices are unusually low. The indicator can be used to identify overbought and oversold levels, as well as divergences that may signal trend reversals.
Formula¶
- Typical Price (TP) = (High + Low + Close) / 3
- SMA of TP = Simple Moving Average of Typical Price over timeperiod
- Mean Absolute Deviation = Mean of |TP - SMA of TP| over timeperiod
- CCI = (TP - SMA of TP) / (0.015 × Mean Absolute Deviation)
The constant 0.015 was chosen by Lambert to ensure that approximately 70-80% of CCI values fall between -100 and +100.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the calculation (default: 14)
Returns¶
np.ndarray Array of CCI values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib CCI signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Lookback period: timeperiod - 1
- All input arrays must have the same length
- When Mean Absolute Deviation is 0, CCI is set to 0
Interpretation¶
- CCI > +100: Overbought condition (prices unusually high)
- CCI < -100: Oversold condition (prices unusually low)
- CCI crossing above +100: Buy signal
- CCI crossing below -100: Sell signal
- CCI returning to 0 line: Trend weakening
- Divergence between CCI and price: Potential reversal
Trading Levels¶
- +100: Overbought threshold
- 0: Centerline (neutral)
- -100: Oversold threshold
- +200: Extremely overbought
- -200: Extremely oversold
Common Uses¶
- Identify cyclical trends in commodities
- Detect overbought/oversold conditions
- Confirm price breakouts
- Spot divergences for reversal signals
- Trade mean reversion strategies
Examples¶
import numpy as np from numta import CCI high = np.array([83, 84, 85, 86, 87]) low = np.array([81, 82, 83, 84, 85]) close = np.array([82, 83, 84, 85, 86]) cci = CCI(high, low, close, timeperiod=5) print(cci)
See Also¶
RSI : Relative Strength Index STOCH : Stochastic Oscillator MFI : Money Flow Index WILLR : Williams %R
Source code in src/numta/api/momentum_indicators.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |
WILLR - Williams %R¶
WILLR
¶
WILLR(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Williams' %R (WILLR)
Williams %R is a momentum indicator created by Larry Williams that measures overbought and oversold levels. It is the inverse of the Fast Stochastic Oscillator.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for %R calculation (default: 14)
Returns¶
np.ndarray Array of Williams %R values (range: 0 to -100)
Notes¶
- Range: 0 to -100
- Overbought: 0 to -20
- Oversold: -80 to -100
- Compatible with TA-Lib WILLR signature
- Inverse of Fast Stochastic %K
Formula¶
%R = ((Highest High - Close) / (Highest High - Lowest Low)) * -100
Where: - Highest High = Highest high over the lookback period - Lowest Low = Lowest low over the lookback period
Interpretation: - 0 to -20: Overbought (potential sell signal) - -80 to -100: Oversold (potential buy signal) - -50: Neutral/midpoint - Rising %R: Strengthening momentum - Falling %R: Weakening momentum
Trading Signals: - Buy: %R crosses above -80 from below - Sell: %R crosses below -20 from above - Buy: Bullish divergence at oversold levels - Sell: Bearish divergence at overbought levels
Relationship to Stochastic: - Williams %R = Fast Stochastic %K * -1 - 100 - Both use same high/low/close data - Different scaling: Stoch (0-100), %R (0 to -100) - Same interpretation, opposite scale
Larry Williams' Original: - Larry Williams originally used 10-day period - Modern default is 14 periods - Can be used on any timeframe - Works best in ranging markets
Advantages: - Clear overbought/oversold levels - Easy to interpret - Works on all timeframes - Good for divergence trading - Fewer parameters than Stochastic
Disadvantages: - Can stay overbought/oversold in trends - Whipsaw signals in choppy markets - Best combined with trend indicators - Less smoothing than Slow Stochastic
Common Periods: - 10: Original Larry Williams setting - 14: Modern default (more common) - 20: Slower, fewer signals - 7: Faster, more signals
Examples¶
import numpy as np from numta import WILLR high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) close = np.array([105, 107, 109, 108, 110, 112, 111]) willr = WILLR(high, low, close, timeperiod=14)
See Also¶
STOCHF : Fast Stochastic Oscillator STOCH : Slow Stochastic Oscillator RSI : Relative Strength Index CCI : Commodity Channel Index
Source code in src/numta/api/momentum_indicators.py
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 | |
MFI - Money Flow Index¶
MFI
¶
MFI(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], volume: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Money Flow Index (MFI)
The Money Flow Index is a momentum indicator that uses both price and volume to measure buying and selling pressure. Often called the "volume-weighted RSI", MFI oscillates between 0 and 100 and is used to identify overbought and oversold conditions.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array volume : array-like Volume array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of MFI values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib MFI signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- MFI values range from 0 to 100
- MFI > 80 typically indicates overbought conditions
- MFI < 20 typically indicates oversold conditions
Formula¶
- Typical Price = (High + Low + Close) / 3
- Raw Money Flow = Typical Price * Volume
- Money Flow is positive when Typical Price increases, negative when it decreases
- Money Flow Ratio = (Sum of Positive Money Flow) / (Sum of Negative Money Flow) over timeperiod
- MFI = 100 - [100 / (1 + Money Flow Ratio)]
Interpretation: - MFI > 80: Overbought (potential sell signal) - MFI < 20: Oversold (potential buy signal) - Divergences between MFI and price indicate potential reversals
Examples¶
import numpy as np from numta import MFI high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) close = np.array([105, 107, 109, 108, 110, 112, 111]) volume = np.array([1000, 1200, 1100, 1300, 1400, 1250, 1350]) mfi = MFI(high, low, close, volume, timeperiod=14)
See Also¶
RSI : Relative Strength Index OBV : On Balance Volume
Source code in src/numta/api/momentum_indicators.py
2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 | |
ULTOSC - Ultimate Oscillator¶
ULTOSC
¶
ULTOSC(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod1: int = 7, timeperiod2: int = 14, timeperiod3: int = 28) -> np.ndarray
Ultimate Oscillator (ULTOSC)
The Ultimate Oscillator was developed by Larry Williams in 1976 to measure momentum across three different timeframes. It addresses the problem of traditional oscillators using only one timeframe.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod1 : int, optional First (short) period (default: 7) timeperiod2 : int, optional Second (medium) period (default: 14) timeperiod3 : int, optional Third (long) period (default: 28)
Returns¶
np.ndarray Array of Ultimate Oscillator values (0-100 range)
Notes¶
- Combines three timeframes for better signals
- Oscillates between 0 and 100
- Overbought: > 70
- Oversold: < 30
- Compatible with TA-Lib ULTOSC signature
Formula¶
For each period: 1. Buying Pressure (BP) = Close - True Low where True Low = min(Low, Previous Close)
-
True Range (TR) = True High - True Low where True High = max(High, Previous Close) True Low = min(Low, Previous Close)
-
Average = sum(BP over period) / sum(TR over period)
-
Ultimate Oscillator = 100 * [(4Avg7 + 2Avg14 + Avg28) / (4 + 2 + 1)]
Interpretation: - Range: 0 to 100 - > 70: Overbought condition - < 30: Oversold condition - 50: Neutral - Rising: Bullish momentum - Falling: Bearish momentum
Trading Signals: - Buy: Bullish divergence below 30 - Sell: Bearish divergence above 70 - Buy: Cross above 30 from below - Sell: Cross below 70 from above - Confirmation: Use with trend indicators
Divergence Signals: - Bullish: Price makes lower low, UO higher low - Bearish: Price makes higher high, UO lower high - Most reliable when UO in extreme zones
Advantages: - Multiple timeframes reduce whipsaws - Good for divergence trading - Objective overbought/oversold levels - Works in trending and ranging markets
Larry Williams' Original Rules: 1. Bullish divergence forms below 30 2. UO rises above 50 3. UO pulls back but stays above 30 4. Buy on break above pullback high
Examples¶
import numpy as np from numta import ULTOSC high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) close = np.array([105, 107, 109, 108, 110, 112, 111]) ultosc = ULTOSC(high, low, close)
See Also¶
RSI : Relative Strength Index STOCH : Stochastic Oscillator MFI : Money Flow Index
Source code in src/numta/api/momentum_indicators.py
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 | |
Trend Strength¶
MACD - Moving Average Convergence/Divergence¶
MACD
¶
MACD(close: Union[ndarray, list], fastperiod: int = 12, slowperiod: int = 26, signalperiod: int = 9) -> tuple
Moving Average Convergence/Divergence (MACD)
MACD is one of the most popular and widely used technical indicators. It shows the relationship between two exponential moving averages (EMAs) of prices. Developed by Gerald Appel in the late 1970s, MACD is used to identify trend direction, strength, momentum, and potential reversal points.
The MACD consists of three components: 1. MACD Line: Difference between fast and slow EMAs 2. Signal Line: EMA of the MACD line 3. Histogram: Difference between MACD and Signal lines
Parameters¶
close : array-like Close prices array fastperiod : int, optional Period for fast EMA (default: 12) slowperiod : int, optional Period for slow EMA (default: 26) signalperiod : int, optional Period for signal line EMA (default: 9)
Returns¶
tuple of np.ndarray (macd, signal, histogram) - Three arrays with the MACD components
Notes¶
- Compatible with TA-Lib MACD signature
- Uses Numba JIT compilation for maximum performance
- Lookback period: slowperiod + signalperiod - 2
- Standard settings: 12, 26, 9
- All three outputs have the same length as input
Formula¶
- Fast EMA = EMA(close, fastperiod)
- Slow EMA = EMA(close, slowperiod)
- MACD Line = Fast EMA - Slow EMA
- Signal Line = EMA(MACD Line, signalperiod)
- Histogram = MACD Line - Signal Line
Lookback period: slowperiod + signalperiod - 2 (For default 12/26/9, lookback = 26 + 9 - 2 = 33)
Interpretation: - MACD > 0: Price is above equilibrium (bullish) - MACD < 0: Price is below equilibrium (bearish) - MACD crossing above Signal: Bullish signal - MACD crossing below Signal: Bearish signal - Histogram > 0: MACD above Signal (bullish momentum) - Histogram < 0: MACD below Signal (bearish momentum) - Histogram increasing: Momentum strengthening - Histogram decreasing: Momentum weakening
Trading Signals: - Crossovers: MACD crossing Signal line - Bullish: MACD crosses above Signal - Bearish: MACD crosses below Signal - Centerline Crossovers: MACD crossing zero line - Bullish: MACD crosses above 0 - Bearish: MACD crosses below 0 - Divergences: Price and MACD moving in opposite directions - Bullish: Price makes lower low, MACD makes higher low - Bearish: Price makes higher high, MACD makes lower high
Histogram Analysis: - Histogram peak: Maximum momentum, potential reversal ahead - Histogram trough: Minimum momentum, potential reversal ahead - Histogram approaching zero: Momentum fading - Histogram expanding: Momentum accelerating
Common Settings: - Default (12, 26, 9): Standard for daily charts - Faster (5, 35, 5): More responsive, more signals - Slower (19, 39, 9): Less sensitive, fewer signals - Weekly (12, 26, 9): Same periods on weekly charts
Advantages: - Combines trend following and momentum - Shows both direction and strength - Multiple signal types (crossovers, divergences) - Widely recognized and tested - Works across different timeframes
Limitations: - Lagging indicator (based on moving averages) - Can generate false signals in ranging markets - Requires confirmation from other indicators - Less effective in choppy conditions
Examples¶
import numpy as np from numta import MACD close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109, ... 110, 112, 111, 113, 115, 114, 116, 118, 117, 119, ... 120, 122, 121, 123, 125, 124, 126, 128, 127, 129, ... 130, 132, 131, 133, 135]) macd, signal, hist = MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) print(f"MACD: {macd[-1]:.4f}") print(f"Signal: {signal[-1]:.4f}") print(f"Histogram: {hist[-1]:.4f}")
See Also¶
MACDEXT : MACD with controllable MA type MACDFIX : MACD with fixed 12/26 periods EMA : Exponential Moving Average
Source code in src/numta/api/momentum_indicators.py
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 | |
MACDEXT - MACD with Controllable MA Type¶
MACDEXT
¶
MACDEXT(close: Union[ndarray, list], fastperiod: int = 12, fastmatype: int = 0, slowperiod: int = 26, slowmatype: int = 0, signalperiod: int = 9, signalmatype: int = 0) -> tuple
MACD with Controllable MA Type (MACDEXT)
MACDEXT is an extended version of MACD that allows you to specify different types of moving averages for each component (fast MA, slow MA, and signal line). This provides flexibility to experiment with different smoothing methods beyond the standard exponential moving average.
Parameters¶
close : array-like Close prices array fastperiod : int, optional Period for fast MA (default: 12) fastmatype : int, optional Type of MA for fast line (default: 0) slowperiod : int, optional Period for slow MA (default: 26) slowmatype : int, optional Type of MA for slow line (default: 0) signalperiod : int, optional Period for signal line (default: 9) signalmatype : int, optional Type of MA for signal line (default: 0)
MA Types
- 0: SMA (Simple Moving Average)
- 1: EMA (Exponential Moving Average)
- 2: WMA (Weighted Moving Average) [Not yet implemented]
- 3: DEMA (Double Exponential Moving Average)
- 4: TEMA (Triple Exponential Moving Average) [Not yet implemented]
- 5: TRIMA (Triangular Moving Average) [Not yet implemented]
- 6: KAMA (Kaufman Adaptive Moving Average)
- 7: MAMA (Mesa Adaptive Moving Average) [Not yet implemented]
- 8: T3 (Triple Exponential T3) [Not yet implemented]
Returns¶
tuple of np.ndarray (macd, signal, histogram) - Three arrays with the MACD components
Notes¶
- Compatible with TA-Lib MACDEXT signature
- Lookback period varies based on MA types used
- Default matype=0 (EMA) matches standard MACD
- Allows mixing different MA types
Formula¶
- Fast MA = MA(close, fastperiod, fastmatype)
- Slow MA = MA(close, slowperiod, slowmatype)
- MACD Line = Fast MA - Slow MA
- Signal Line = MA(MACD Line, signalperiod, signalmatype)
- Histogram = MACD Line - Signal Line
Examples¶
import numpy as np from numta import MACDEXT close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109, ... 110, 112, 111, 113, 115, 114, 116, 118, 117, 119, ... 120, 122, 121, 123, 125, 124, 126, 128, 127, 129, ... 130, 132, 131, 133, 135])
Use DEMA for fast, EMA for slow, SMA for signal¶
macd, signal, hist = MACDEXT(close, fastperiod=12, fastmatype=3, ... slowperiod=26, slowmatype=1, ... signalperiod=9, signalmatype=0)
See Also¶
MACD : Standard MACD with EMA MACDFIX : MACD with fixed 12/26 periods MA : Generic Moving Average function
Source code in src/numta/api/momentum_indicators.py
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 | |
MACDFIX - MACD Fix 12/26¶
MACDFIX
¶
Moving Average Convergence/Divergence Fix (MACDFIX)
MACDFIX is a variant of MACD with fixed fast and slow periods (12 and 26). This optimized version provides faster computation by hard-coding the standard MACD periods while still allowing customization of the signal period.
Parameters¶
close : array-like Close prices array signalperiod : int, optional Period for signal line EMA (default: 9)
Returns¶
tuple of np.ndarray (macd, signal, histogram) - Three arrays with the MACD components
Notes¶
- Compatible with TA-Lib MACDFIX signature
- Uses Numba JIT compilation for maximum performance
- Fixed fast period: 12
- Fixed slow period: 26
- Lookback period: 26 + signalperiod - 2
- All three outputs have the same length as input
Formula¶
- Fast EMA = EMA(close, 12)
- Slow EMA = EMA(close, 26)
- MACD Line = Fast EMA - Slow EMA
- Signal Line = EMA(MACD Line, signalperiod)
- Histogram = MACD Line - Signal Line
Examples¶
import numpy as np from numta import MACDFIX close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109, ... 110, 112, 111, 113, 115, 114, 116, 118, 117, 119, ... 120, 122, 121, 123, 125, 124, 126, 128, 127, 129, ... 130, 132, 131, 133, 135]) macd, signal, hist = MACDFIX(close, signalperiod=9)
See Also¶
MACD : MACD with customizable fast/slow periods MACDEXT : MACD with controllable MA type
Source code in src/numta/api/momentum_indicators.py
2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 | |
ADX - Average Directional Movement Index¶
ADX
¶
ADX(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Average Directional Movement Index (ADX)
The Average Directional Movement Index (ADX) is used to measure the strength of a trend. ADX is non-directional; it quantifies trend strength regardless of whether the trend is up or down.
The ADX is derived from the relationship of the Directional Movement Index (DMI) and the Average True Range (ATR). It uses smoothed moving averages of the difference between two consecutive lows and highs.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of ADX values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib ADX signature
- Uses Numba JIT compilation for maximum performance
- The first (2 * timeperiod - 1) values will be NaN
- ADX values range from 0 to 100
- ADX > 25 typically indicates a strong trend
- ADX < 20 typically indicates a weak trend or ranging market
Formula¶
-
Calculate True Range (TR): TR = max(high - low, |high - prev_close|, |low - prev_close|)
-
Calculate Directional Movement (+DM, -DM): +DM = high - prev_high (if positive and > down_move, else 0) -DM = prev_low - low (if positive and > up_move, else 0)
-
Smooth TR, +DM, -DM using Wilder's smoothing: First value = sum of first timeperiod values Subsequent = prev_smooth - prev_smooth/timeperiod + current_value
-
Calculate Directional Indicators: +DI = 100 * smoothed(+DM) / smoothed(TR) -DI = 100 * smoothed(-DM) / smoothed(TR)
-
Calculate DX (Directional Index): DX = 100 * |+DI - -DI| / (+DI + -DI)
-
Calculate ADX (smoothed DX): First ADX = average of first timeperiod DX values Subsequent ADX = prev_ADX + (DX - prev_ADX) / timeperiod
Interpretation: - ADX measures trend strength (not direction) - Rising ADX indicates strengthening trend - Falling ADX indicates weakening trend - Use with +DI/-DI to determine trend direction
Examples¶
import numpy as np from numta import ADX high = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) low = np.array([9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) close = np.array([9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5]) adx = ADX(high, low, close, timeperiod=5) print(adx)
Source code in src/numta/api/momentum_indicators.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
ADXR - Average Directional Movement Index Rating¶
ADXR
¶
ADXR(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Average Directional Movement Index Rating (ADXR)
The Average Directional Movement Index Rating (ADXR) is a smoothed version of the ADX indicator. It is calculated as the average of the current ADX and the ADX from (timeperiod - 1) bars ago.
ADXR provides a smoother trend strength measurement than ADX, reducing short-term volatility while maintaining sensitivity to longer-term trends.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of ADXR values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib ADXR signature
- Uses Numba JIT compilation for maximum performance
- The first (3 * timeperiod - 2) values will be NaN
- ADXR values range from 0 to 100
- ADXR provides a smoother reading than ADX
Formula¶
ADXR[i] = (ADX[i] + ADX[i - (timeperiod - 1)]) / 2
Where ADX is the Average Directional Movement Index.
Lookback period: 3 * timeperiod - 2 (For timeperiod=14, lookback=40)
Interpretation: - ADXR measures trend strength with less noise than ADX - Similar thresholds as ADX apply: - ADXR > 25: Strong trend - ADXR < 20: Weak trend or ranging market - Rising ADXR: Strengthening trend - Falling ADXR: Weakening trend - ADXR lags ADX by approximately (timeperiod - 1) / 2 periods
Examples¶
import numpy as np from numta import ADXR high = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) low = np.array([9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) close = np.array([9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5]) adxr = ADXR(high, low, close, timeperiod=5) print(adxr)
Source code in src/numta/api/momentum_indicators.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
DX - Directional Movement Index¶
DX
¶
DX(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Directional Movement Index (DX)
The Directional Movement Index (DX) measures the strength of directional movement in a market. It is derived from the relationship between the Plus Directional Indicator (+DI) and Minus Directional Indicator (-DI).
DX is a component of the ADX (Average Directional Index) indicator and represents the absolute difference between +DI and -DI divided by their sum.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of DX values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib DX signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- DX values range from 0 to 100
- Higher values indicate stronger directional movement
Formula¶
-
Calculate True Range (TR): TR = max(high - low, |high - prev_close|, |low - prev_close|)
-
Calculate Directional Movement (+DM, -DM): +DM = high - prev_high (if positive and > down_move, else 0) -DM = prev_low - low (if positive and > up_move, else 0)
-
Smooth TR, +DM, -DM using Wilder's smoothing: First value = sum of first timeperiod values Subsequent = prev_smooth - prev_smooth/timeperiod + current_value
-
Calculate Directional Indicators: +DI = 100 * smoothed(+DM) / smoothed(TR) -DI = 100 * smoothed(-DM) / smoothed(TR)
-
Calculate DX: DX = 100 * |+DI - -DI| / (+DI + -DI)
Lookback period: timeperiod (For timeperiod=14, lookback=14)
Interpretation: - DX = 0-25: Weak or absent trend - DX = 25-50: Moderate trend strength - DX = 50-75: Strong trend - DX = 75-100: Very strong trend - Rising DX: Trend strengthening - Falling DX: Trend weakening
Relationship to ADX: - DX is the raw calculation before smoothing - ADX = smoothed average of DX - DX is more volatile than ADX - ADX smooths out DX fluctuations
Common Uses: - Measure trend strength (not direction) - Identify potential trend reversals - Filter weak trends from strong trends - Component in ADX calculation - Confirm breakout strength
Examples¶
import numpy as np from numta import DX high = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) low = np.array([9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) close = np.array([9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5]) dx = DX(high, low, close, timeperiod=5) print(dx)
See Also¶
ADX : Average Directional Index ADXR : Average Directional Index Rating PLUS_DI : Plus Directional Indicator MINUS_DI : Minus Directional Indicator
Source code in src/numta/api/momentum_indicators.py
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 | |
PLUS_DI - Plus Directional Indicator¶
PLUS_DI
¶
PLUS_DI(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Plus Directional Indicator (PLUS_DI)
The Plus Directional Indicator is a component of the Directional Movement System developed by J. Welles Wilder. It measures the strength of upward price movement and is used in conjunction with MINUS_DI to determine trend direction and strength.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of Plus Directional Indicator values
Notes¶
- Compatible with TA-Lib PLUS_DI signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Values range from 0 to 100
- Higher values indicate stronger upward movement
Formula¶
- Calculate True Range (TR) and Plus Directional Movement (+DM)
- Apply Wilder's smoothing to both TR and +DM
- +DI = 100 * (Smoothed +DM / Smoothed TR)
Interpretation: - +DI > -DI: Uptrend dominates - +DI < -DI: Downtrend dominates - Use with -DI and ADX for complete trend analysis
Examples¶
import numpy as np from numta import PLUS_DI high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) close = np.array([105, 107, 109, 108, 110, 112, 111]) plus_di = PLUS_DI(high, low, close, timeperiod=14)
See Also¶
MINUS_DI : Minus Directional Indicator ADX : Average Directional Movement Index DX : Directional Movement Index
Source code in src/numta/api/momentum_indicators.py
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 | |
MINUS_DI - Minus Directional Indicator¶
MINUS_DI
¶
MINUS_DI(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Minus Directional Indicator (MINUS_DI)
The Minus Directional Indicator is a component of the Directional Movement System developed by J. Welles Wilder. It measures the strength of downward price movement and is used in conjunction with PLUS_DI to determine trend direction and strength.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of Minus Directional Indicator values
Notes¶
- Compatible with TA-Lib MINUS_DI signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Values range from 0 to 100
- Higher values indicate stronger downward movement
Formula¶
- Calculate True Range (TR) and Minus Directional Movement (-DM)
- Apply Wilder's smoothing to both TR and -DM
- -DI = 100 * (Smoothed -DM / Smoothed TR)
Interpretation: - -DI > +DI: Downtrend dominates - -DI < +DI: Uptrend dominates - Use with +DI and ADX for complete trend analysis
Examples¶
import numpy as np from numta import MINUS_DI high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) close = np.array([105, 107, 109, 108, 110, 112, 111]) minus_di = MINUS_DI(high, low, close, timeperiod=14)
See Also¶
PLUS_DI : Plus Directional Indicator ADX : Average Directional Movement Index DX : Directional Movement Index
Source code in src/numta/api/momentum_indicators.py
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 | |
PLUS_DM - Plus Directional Movement¶
PLUS_DM
¶
Plus Directional Movement (PLUS_DM)
The Plus Directional Movement is a component of the Directional Movement System developed by J. Welles Wilder. It represents the smoothed value of upward price movement.
Parameters¶
high : array-like High prices array low : array-like Low prices array timeperiod : int, optional Number of periods for smoothing (default: 14)
Returns¶
np.ndarray Array of smoothed Plus Directional Movement values
Notes¶
- Compatible with TA-Lib PLUS_DM signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Uses Wilder's smoothing method
Formula¶
- Raw +DM = Current High - Previous High (when up move > down move and > 0)
- Otherwise +DM = 0
- Apply Wilder's smoothing over timeperiod
Examples¶
import numpy as np from numta import PLUS_DM high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) plus_dm = PLUS_DM(high, low, timeperiod=14)
See Also¶
MINUS_DM : Minus Directional Movement PLUS_DI : Plus Directional Indicator ADX : Average Directional Movement Index
Source code in src/numta/api/momentum_indicators.py
2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 | |
MINUS_DM - Minus Directional Movement¶
MINUS_DM
¶
Minus Directional Movement (MINUS_DM)
The Minus Directional Movement is a component of the Directional Movement System developed by J. Welles Wilder. It represents the smoothed value of downward price movement.
Parameters¶
high : array-like High prices array low : array-like Low prices array timeperiod : int, optional Number of periods for smoothing (default: 14)
Returns¶
np.ndarray Array of smoothed Minus Directional Movement values
Notes¶
- Compatible with TA-Lib MINUS_DM signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Uses Wilder's smoothing method
Formula¶
- Raw -DM = Previous Low - Current Low (when down move > up move and > 0)
- Otherwise -DM = 0
- Apply Wilder's smoothing over timeperiod
Examples¶
import numpy as np from numta import MINUS_DM high = np.array([110, 112, 114, 113, 115, 117, 116]) low = np.array([100, 102, 104, 103, 105, 107, 106]) minus_dm = MINUS_DM(high, low, timeperiod=14)
See Also¶
PLUS_DM : Plus Directional Movement MINUS_DI : Minus Directional Indicator ADX : Average Directional Movement Index
Source code in src/numta/api/momentum_indicators.py
2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 | |
Rate of Change¶
ROC - Rate of Change¶
ROC
¶
Rate of Change (ROC)
ROC measures the percentage change in price over a specified time period. It is a momentum oscillator that oscillates above and below a zero line, showing the velocity of price changes.
ROC is the percentage version of the Momentum (MOM) indicator, making it easier to compare across different securities regardless of price level.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Number of periods for calculation (default: 10)
Returns¶
np.ndarray Array of ROC values (percentage change)
Notes¶
- Compatible with TA-Lib ROC signature
- Uses Numba JIT compilation for performance
- The first timeperiod values will be NaN
- Lookback period: timeperiod
- Unbounded oscillator (no fixed range)
Formula¶
ROC[i] = ((Price[i] / Price[i - timeperiod]) - 1) * 100
Equivalent to: ((Price[i] - Price[i - timeperiod]) / Price[i - timeperiod]) * 100
Lookback period: timeperiod (For timeperiod=10, lookback=10)
Interpretation: - Positive ROC: Price rising (bullish momentum) - Negative ROC: Price falling (bearish momentum) - ROC = 0: No change over period - Increasing ROC: Accelerating momentum - Decreasing ROC: Decelerating momentum - ROC crossing zero: Potential trend change
Advantages: - Normalized for price level (percentage) - Comparable across different securities - Identifies momentum strength - Leading indicator - Simple and intuitive
Common Uses: - Trend identification - Momentum strength measurement - Divergence analysis - Overbought/oversold detection - Confirmation signals - Cross-security comparison
Trading Applications: - Buy when ROC crosses above zero - Sell when ROC crosses below zero - Divergence: Price makes new high but ROC doesn't (bearish) - Divergence: Price makes new low but ROC doesn't (bullish) - Overbought: ROC > +threshold (e.g., +10%) - Oversold: ROC < -threshold (e.g., -10%)
Comparison with Related Indicators: - MOM: Absolute price difference (not percentage) - ROCP: Same as ROC but decimal form - ROCR: Ratio form (price/prevPrice) - RSI: Bounded version (0-100) with smoothing
Examples¶
import numpy as np from numta import ROC close = np.array([100, 102, 104, 103, 105, 107, 106, 108, 110, 109, 111]) roc = ROC(close, timeperiod=10) print(roc)
roc[10] = ((111 / 100) - 1) * 100 = 11%¶
See Also¶
MOM : Momentum ROCP : Rate of Change Percentage ROCR : Rate of Change Ratio RSI : Relative Strength Index
Source code in src/numta/api/momentum_indicators.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | |
ROCP - Rate of Change Percentage¶
ROCP
¶
Rate of Change Percentage (ROCP)
ROCP calculates the percentage change in price as a decimal value (not multiplied by 100). It is mathematically equivalent to ROC / 100.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Number of periods for calculation (default: 10)
Returns¶
np.ndarray Array of ROCP values (decimal percentage change)
Notes¶
- Compatible with TA-Lib ROCP signature
- Values are decimals (0.10 = 10%)
- ROCP = ROC / 100
Formula¶
ROCP[i] = (Price[i] - Price[i - timeperiod]) / Price[i - timeperiod]
Examples¶
import numpy as np from numta import ROCP close = np.array([100, 102, 104, 103, 105, 107, 106, 108, 110, 109, 111]) rocp = ROCP(close, timeperiod=10)
rocp[10] = (111 - 100) / 100 = 0.11 (11%)¶
See Also¶
ROC : Rate of Change (percentage form) ROCR : Rate of Change Ratio
Source code in src/numta/api/momentum_indicators.py
ROCR - Rate of Change Ratio¶
ROCR
¶
Rate of Change Ratio (ROCR)
ROCR calculates the ratio of the current price to the price n periods ago. Values oscillate around 1.0, where 1.0 represents no change.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Number of periods for calculation (default: 10)
Returns¶
np.ndarray Array of ROCR values (ratio)
Notes¶
- Compatible with TA-Lib ROCR signature
- Values oscillate around 1.0
- ROCR > 1.0: Price increased
- ROCR < 1.0: Price decreased
- ROCR = 1.0: No change
Formula¶
ROCR[i] = Price[i] / Price[i - timeperiod]
Examples¶
import numpy as np from numta import ROCR close = np.array([100, 102, 104, 103, 105, 107, 106, 108, 110, 109, 111]) rocr = ROCR(close, timeperiod=10)
rocr[10] = 111 / 100 = 1.11¶
See Also¶
ROC : Rate of Change (percentage) ROCR100 : Rate of Change Ratio * 100
Source code in src/numta/api/momentum_indicators.py
ROCR100 - Rate of Change Ratio 100 Scale¶
ROCR100
¶
Rate of Change Ratio 100 Scale (ROCR100)
ROCR100 calculates the ratio of the current price to the price n periods ago, scaled to 100. Values oscillate around 100, where 100 represents no change.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Number of periods for calculation (default: 10)
Returns¶
np.ndarray Array of ROCR100 values (ratio * 100)
Notes¶
- Compatible with TA-Lib ROCR100 signature
- Values oscillate around 100
- ROCR100 > 100: Price increased
- ROCR100 < 100: Price decreased
- ROCR100 = 100: No change
- ROCR100 = ROCR * 100
Formula¶
ROCR100[i] = (Price[i] / Price[i - timeperiod]) * 100
Examples¶
import numpy as np from numta import ROCR100 close = np.array([100, 102, 104, 103, 105, 107, 106, 108, 110, 109, 111]) rocr100 = ROCR100(close, timeperiod=10)
rocr100[10] = (111 / 100) * 100 = 111¶
See Also¶
ROCR : Rate of Change Ratio ROC : Rate of Change (percentage)
Source code in src/numta/api/momentum_indicators.py
MOM - Momentum¶
MOM
¶
Momentum (MOM)
Momentum is a simple and direct measure of the rate of price change. It calculates the difference between the current price and the price n periods ago. Positive values indicate upward momentum, while negative values indicate downward momentum.
Parameters¶
real : array-like Array of real values (typically close prices) timeperiod : int, optional Number of periods to look back (default: 10)
Returns¶
np.ndarray Array of momentum values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib MOM signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- Unbounded indicator (can be any positive or negative value)
Formula¶
MOM = Current Price - Price n periods ago
Interpretation: - MOM > 0: Upward momentum (price increased) - MOM < 0: Downward momentum (price decreased) - MOM = 0: No momentum (price unchanged) - Increasing MOM: Accelerating trend - Decreasing MOM: Decelerating trend
Trading Signals: - Crossover above 0: Bullish signal - Crossover below 0: Bearish signal - Divergences indicate potential reversals
Examples¶
import numpy as np from numta import MOM close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109, 110]) mom = MOM(close, timeperiod=10)
See Also¶
ROC : Rate of Change (percentage-based momentum) RSI : Relative Strength Index MACD : Moving Average Convergence/Divergence
Source code in src/numta/api/momentum_indicators.py
2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 | |
TRIX - Triple Exponential Moving Average ROC¶
TRIX
¶
1-day Rate-Of-Change (ROC) of a Triple Smooth EMA (TRIX)
TRIX shows the percent rate of change of a triple exponentially smoothed moving average. It was developed by Jack Hutson in the early 1980s as a filtered momentum oscillator.
Parameters¶
data : array-like Input data array (typically close prices) timeperiod : int, optional Period for EMA calculations (default: 30)
Returns¶
np.ndarray Array of TRIX values (percentage)
Notes¶
- Shows momentum of triple-smoothed EMA
- Filters out insignificant price movements
- Values around zero indicate no trend
- Positive values indicate bullish momentum
- Negative values indicate bearish momentum
- Compatible with TA-Lib TRIX signature
Formula¶
- EMA1 = EMA(data, timeperiod)
- EMA2 = EMA(EMA1, timeperiod)
- EMA3 = EMA(EMA2, timeperiod)
- TRIX = 1-period ROC of EMA3 TRIX = ((EMA3[i] - EMA3[i-1]) / EMA3[i-1]) * 100
Interpretation: - TRIX > 0: Bullish momentum - TRIX < 0: Bearish momentum - TRIX crossing zero: Trend change - Divergence: Potential reversal signal - Rising TRIX: Strengthening uptrend - Falling TRIX: Strengthening downtrend
Trading Signals: - Buy: TRIX crosses above zero - Sell: TRIX crosses below zero - Buy: TRIX crosses above signal line - Sell: TRIX crosses below signal line - Bullish divergence: Price lower low, TRIX higher low - Bearish divergence: Price higher high, TRIX lower high
Advantages: - Triple smoothing filters noise - Fewer whipsaw signals - Good for trend identification - Works well in trending markets
Examples¶
import numpy as np from numta import TRIX close = np.linspace(100, 120, 100) trix = TRIX(close, timeperiod=15)
See Also¶
EMA : Exponential Moving Average ROC : Rate of Change
Source code in src/numta/api/momentum_indicators.py
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 | |
Price Oscillators¶
APO - Absolute Price Oscillator¶
APO
¶
APO(close: Union[ndarray, list], fastperiod: int = 12, slowperiod: int = 26, matype: int = 0) -> np.ndarray
Absolute Price Oscillator (APO)
The Absolute Price Oscillator (APO) displays the difference between two moving averages of a security's price. It is expressed in absolute terms (price points) rather than percentage terms.
APO is similar to MACD but shows the absolute difference between the MAs, while MACD shows the same values but is typically used with a signal line and histogram.
Parameters¶
close : array-like Close prices array fastperiod : int, optional Number of periods for the fast MA (default: 12) slowperiod : int, optional Number of periods for the slow MA (default: 26) matype : int, optional Moving average type: 0 = SMA (default), 1 = EMA
Returns¶
np.ndarray Array of APO values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib APO signature
- Uses Numba JIT compilation for maximum performance
- The first (slowperiod - 1) values will be NaN
- APO values can be positive or negative
- Positive APO indicates fast EMA > slow EMA (bullish)
- Negative APO indicates fast EMA < slow EMA (bearish)
Formula¶
APO = MA(close, fastperiod) - MA(close, slowperiod)
Where: - MA is either SMA (matype=0, default) or EMA (matype=1) - fastperiod < slowperiod (typically)
Lookback period: slowperiod - 1 (For fastperiod=12, slowperiod=26, lookback=25)
Interpretation: - APO > 0: Fast MA above slow MA (bullish signal) - APO < 0: Fast MA below slow MA (bearish signal) - APO crossing above 0: Potential buy signal - APO crossing below 0: Potential sell signal - Increasing APO: Strengthening uptrend - Decreasing APO: Strengthening downtrend
Difference from MACD: - APO shows absolute difference (price points) - MACD is essentially the same but typically includes signal line - APO = MACD line (without signal line or histogram)
Examples¶
import numpy as np from numta import APO close = np.array([100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) apo = APO(close, fastperiod=3, slowperiod=5) print(apo)
Source code in src/numta/api/momentum_indicators.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
PPO - Percentage Price Oscillator¶
PPO
¶
PPO(close: Union[ndarray, list], fastperiod: int = 12, slowperiod: int = 26, matype: int = 0) -> np.ndarray
Percentage Price Oscillator (PPO)
The Percentage Price Oscillator is a momentum oscillator that measures the difference between two moving averages as a percentage of the larger moving average. It is similar to MACD but expressed in percentage terms, making it more suitable for comparing securities with different price levels.
Parameters¶
close : array-like Close prices array fastperiod : int, optional Period for fast moving average (default: 12) slowperiod : int, optional Period for slow moving average (default: 26) matype : int, optional Type of moving average (default: 0 = EMA) Currently only EMA (0) is supported
Returns¶
np.ndarray Array of PPO values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib PPO signature
- Uses Numba JIT compilation for maximum performance
- Lookback period: slowperiod - 1
- Unbounded indicator (can be any percentage value)
- More suitable than MACD for comparing different securities
Formula¶
PPO = ((Fast EMA - Slow EMA) / Slow EMA) * 100
Where: - Fast EMA = EMA(close, fastperiod) - Slow EMA = EMA(close, slowperiod)
Interpretation: - PPO > 0: Fast MA above slow MA (bullish) - PPO < 0: Fast MA below slow MA (bearish) - Rising PPO: Increasing bullish momentum - Falling PPO: Increasing bearish momentum
Trading Signals: - Crossover above 0: Bullish signal - Crossover below 0: Bearish signal - Divergences indicate potential reversals
Advantages over MACD: - Percentage-based allows comparison across securities - Not affected by absolute price levels - Same interpretation regardless of price scale
Examples¶
import numpy as np from numta import PPO close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109, ... 110, 112, 111, 113, 115, 114, 116, 118, 117, 119, ... 120, 122, 121, 123, 125, 124, 126, 128, 127, 129]) ppo = PPO(close, fastperiod=12, slowperiod=26)
See Also¶
MACD : Moving Average Convergence/Divergence APO : Absolute Price Oscillator EMA : Exponential Moving Average
Source code in src/numta/api/momentum_indicators.py
2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 | |
Aroon Indicators¶
AROON - Aroon Indicator¶
AROON
¶
Aroon (Aroon Indicator)
The Aroon indicator is a technical indicator used to identify trend changes and the strength of a trend. It consists of two lines: Aroon Up and Aroon Down.
Aroon Up measures the time elapsed since the highest high over the period. Aroon Down measures the time elapsed since the lowest low over the period.
Parameters¶
high : array-like High prices array low : array-like Low prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
tuple of np.ndarray (aroondown, aroonup) - Two arrays with Aroon Down and Aroon Up values
Notes¶
- Compatible with TA-Lib AROON signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- Aroon values range from 0 to 100
- Aroon Up = 100 when current price is at the period high
- Aroon Down = 100 when current price is at the period low
Formula¶
Aroon Up = ((timeperiod - periods_since_high) / timeperiod) * 100 Aroon Down = ((timeperiod - periods_since_low) / timeperiod) * 100
Where: - periods_since_high = periods since the highest high in the window - periods_since_low = periods since the lowest low in the window
Lookback period: timeperiod (For timeperiod=14, lookback=14)
Interpretation: - Aroon Up > 70 and Aroon Down < 30: Strong uptrend - Aroon Down > 70 and Aroon Up < 30: Strong downtrend - Aroon Up crossing above Aroon Down: Potential bullish signal - Aroon Down crossing above Aroon Up: Potential bearish signal - Both lines between 30-70: Consolidation/ranging market - Aroon Up = 100: New high reached - Aroon Down = 100: New low reached
Examples¶
import numpy as np from numta import AROON high = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) low = np.array([9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) aroondown, aroonup = AROON(high, low, timeperiod=5) print(aroondown) print(aroonup)
Source code in src/numta/api/momentum_indicators.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
AROONOSC - Aroon Oscillator¶
AROONOSC
¶
Aroon Oscillator (AROONOSC)
The Aroon Oscillator is the difference between Aroon Up and Aroon Down. It oscillates between -100 and +100, with zero as the midpoint.
The oscillator helps identify the strength and direction of a trend. Positive values indicate bullish momentum, while negative values indicate bearish momentum.
Parameters¶
high : array-like High prices array low : array-like Low prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of Aroon Oscillator values
Notes¶
- Compatible with TA-Lib AROONOSC signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- Values range from -100 to +100
- Zero line crossovers can signal trend changes
Formula¶
AROONOSC = Aroon Up - Aroon Down
Where: - Aroon Up = ((timeperiod - periods_since_high) / timeperiod) * 100 - Aroon Down = ((timeperiod - periods_since_low) / timeperiod) * 100
Lookback period: timeperiod (For timeperiod=14, lookback=14)
Interpretation: - AROONOSC > 0: Aroon Up > Aroon Down (bullish, uptrend dominant) - AROONOSC < 0: Aroon Down > Aroon Up (bearish, downtrend dominant) - AROONOSC > 50: Strong uptrend - AROONOSC < -50: Strong downtrend - AROONOSC near 0: Consolidation or weak trend - AROONOSC crossing above 0: Potential bullish signal - AROONOSC crossing below 0: Potential bearish signal - Extreme values (+100 or -100): Very strong trend
Examples¶
import numpy as np from numta import AROONOSC high = np.array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) low = np.array([9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) aroonosc = AROONOSC(high, low, timeperiod=5) print(aroonosc)
Source code in src/numta/api/momentum_indicators.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
Other Momentum Indicators¶
BOP - Balance of Power¶
BOP
¶
BOP(open_price: Union[ndarray, list], high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list]) -> np.ndarray
Balance Of Power (BOP)
Balance of Power is a momentum indicator that measures the strength of buying and selling pressure. It was introduced by Igor Levshin in the August 2001 issue of Technical Analysis of Stocks & Commodities magazine.
The indicator calculates the ratio between the close-open range and the high-low range, providing insight into which side (buyers or sellers) is winning the battle for price control.
Formula¶
BOP = (Close - Open) / (High - Low)
When High equals Low (no price range), BOP is set to 0.
Parameters¶
open_price : array-like Open prices array high : array-like High prices array low : array-like Low prices array close : array-like Close prices array
Returns¶
np.ndarray Array of Balance of Power values (range: -1 to +1)
Notes¶
- Compatible with TA-Lib BOP signature
- No lookback period - returns values for all input bars
- Range: -1.0 to +1.0
- Positive values indicate buying pressure dominance (bulls in control)
- Negative values indicate selling pressure dominance (bears in control)
- Values near zero indicate balance between buyers and sellers
- When High = Low (no range), BOP is set to 0 to avoid division by zero
- All input arrays must have the same length
Interpretation¶
- BOP > 0: Bulls are winning (close > open, buyers dominating)
- BOP < 0: Bears are winning (close < open, sellers dominating)
- BOP = 0: Balance or no price range
- BOP near +1: Very strong buying pressure (close near high, open near low)
- BOP near -1: Very strong selling pressure (close near low, open near high)
- BOP oscillating around 0: Market indecision or consolidation
Trading Signals¶
- Crossing above 0: Potential bullish signal
- Crossing below 0: Potential bearish signal
- Divergence between BOP and price: Potential trend reversal
- Sustained positive BOP: Uptrend confirmation
- Sustained negative BOP: Downtrend confirmation
Common Usage¶
BOP is often smoothed with a moving average (e.g., 14-period SMA) to reduce noise and make trends more visible. The raw BOP can be quite volatile.
Examples¶
import numpy as np from numta import BOP open_price = np.array([100, 101, 102, 103, 104]) high = np.array([105, 106, 107, 108, 109]) low = np.array([99, 100, 101, 102, 103]) close = np.array([103, 104, 105, 106, 107]) bop = BOP(open_price, high, low, close) print(bop) [0.5 0.5 0.5 0.5 0.5]
See Also¶
ADX : Average Directional Index (trend strength) AROON : Aroon Indicator (trend identification) MFI : Money Flow Index (volume-weighted momentum)
Source code in src/numta/api/momentum_indicators.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
ATR - Average True Range¶
ATR
¶
ATR(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], timeperiod: int = 14) -> np.ndarray
Average True Range (ATR)
The Average True Range (ATR) is a volatility indicator that measures the average range of price movement. It was developed by J. Welles Wilder and is widely used to assess market volatility.
ATR is particularly useful for: - Setting stop-loss levels - Position sizing based on volatility - Identifying breakout potential - Comparing volatility across different instruments
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array timeperiod : int, optional Number of periods for the indicator (default: 14)
Returns¶
np.ndarray Array of ATR values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib ATR signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- ATR is always positive (measures absolute volatility, not direction)
- Higher ATR indicates higher volatility
- Lower ATR indicates lower volatility
Formula¶
-
Calculate True Range (TR) for each bar: TR = max(high - low, |high - prev_close|, |low - prev_close|)
-
Calculate ATR using Wilder's smoothing: First ATR = average of first timeperiod TR values Subsequent ATR = ((prev_ATR × (timeperiod - 1)) + current_TR) / timeperiod
Lookback period: timeperiod (For timeperiod=14, lookback=14)
Interpretation: - ATR measures volatility, not direction - Rising ATR indicates increasing volatility - Falling ATR indicates decreasing volatility - ATR is often used with multiples (e.g., 2×ATR for stop-loss) - Compare current ATR to historical ATR for context - Higher timeframes generally have higher ATR values
Common Uses: - Stop-loss placement: Close - (2 × ATR) for long positions - Position sizing: Risk a fixed dollar amount per ATR unit - Breakout confirmation: Look for ATR expansion on breakouts - Trend strength: Higher ATR often accompanies strong trends
Examples¶
import numpy as np from numta import ATR high = np.array([48, 49, 50, 51, 52, 51, 50, 49, 50, 51, 52]) low = np.array([46, 47, 48, 49, 50, 49, 48, 47, 48, 49, 50]) close = np.array([47, 48, 49, 50, 51, 50, 49, 48, 49, 50, 51]) atr = ATR(high, low, close, timeperiod=5) print(atr)
Source code in src/numta/api/momentum_indicators.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |