Overlap Studies¶
Overlap studies are indicators that overlay directly on price charts, helping to identify trends and support/resistance levels.
Moving Averages¶
SMA - Simple Moving Average¶
SMA
¶
Simple Moving Average (SMA)
The Simple Moving Average (SMA) is calculated by adding the closing prices of the last N periods and dividing by N. This indicator is used to smooth price data and identify trends.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the moving average (default: 30)
Returns¶
np.ndarray Array of SMA values with NaN for the lookback period
Notes¶
- The first (timeperiod - 1) values will be NaN
- Compatible with TA-Lib SMA signature
- Uses Numba JIT compilation for maximum performance
Examples¶
import numpy as np from numta import SMA close = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) sma = SMA(close, timeperiod=3) print(sma) [nan nan 2. 3. 4. 5. 6. 7. 8. 9.]
Source code in src/numta/api/overlap.py
EMA - Exponential Moving Average¶
EMA
¶
Exponential Moving Average (EMA)
The Exponential Moving Average (EMA) is a type of moving average that places a greater weight and significance on the most recent data points. The EMA responds more quickly to recent price changes than a simple moving average.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the moving average (default: 30)
Returns¶
np.ndarray Array of EMA values with NaN for the lookback period
Notes¶
- The first (timeperiod - 1) values will be NaN
- Compatible with TA-Lib EMA signature
- Uses Numba JIT compilation for maximum performance
- The first EMA value is initialized as the SMA of the first timeperiod values
- Smoothing factor: 2 / (timeperiod + 1)
Formula¶
Multiplier = 2 / (timeperiod + 1) EMA[0] = SMA(close[0:timeperiod]) EMA[i] = (Close[i] - EMA[i-1]) * Multiplier + EMA[i-1]
Examples¶
import numpy as np from numta import EMA close = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ema = EMA(close, timeperiod=3) print(ema) [nan nan 2. 3. 4. 5. 6. 7. 8. 9.]
Source code in src/numta/api/overlap.py
WMA - Weighted Moving Average¶
WMA
¶
Weighted Moving Average (WMA)
WMA assigns greater weight to recent data points and less weight to older data points. The weights decrease linearly from the most recent to the oldest data point.
Parameters¶
data : array-like Input data array timeperiod : int, optional Number of periods for the moving average (default: 30)
Returns¶
np.ndarray Array of WMA values
Notes¶
- More weight on recent data
- Linear weight decrease
- More responsive than SMA
- Less responsive than EMA
- Compatible with TA-Lib WMA signature
Formula¶
WMA = (P1n + P2(n-1) + P3(n-2) + ... + Pn1) / (n*(n+1)/2)
Where: - P1 = most recent price - P2 = second most recent price - Pn = oldest price in the window - n = timeperiod
Weight Calculation: - Sum of weights = 1 + 2 + 3 + ... + n = n*(n+1)/2 - Most recent: weight = n - Second most recent: weight = n-1 - Oldest: weight = 1
Example with period=4: - Most recent: weight 4/10 = 40% - Previous: weight 3/10 = 30% - Next: weight 2/10 = 20% - Oldest: weight 1/10 = 10% - Sum = 4+3+2+1 = 10
Interpretation: - Emphasizes recent price action - Smoother than EMA - Less lag than SMA - Good balance of smoothness and responsiveness
Comparison with Other MAs: - SMA: Equal weights - WMA: Linear decreasing weights - EMA: Exponential decreasing weights - Response: EMA > WMA > SMA
Applications: - Trend identification - Support/resistance levels - Crossover systems - Price filtering - Momentum confirmation
Trading Signals: - Price above WMA: Uptrend - Price below WMA: Downtrend - WMA slope up: Bullish - WMA slope down: Bearish - Short/Long WMA cross: Trend change
Advantages: - More responsive than SMA - Smoother than short-period EMA - Clear weighting scheme - Good for intermediate trends
Disadvantages: - More lag than EMA - Complex than SMA - Can overshoot in volatile markets - Weights somewhat arbitrary
Common Periods: - 10: Short-term (day trading) - 20: Medium-term (swing trading) - 50: Long-term (position trading) - 200: Very long-term (investors)
Examples¶
import numpy as np from numta import WMA close = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) wma = WMA(close, timeperiod=5)
See Also¶
SMA : Simple Moving Average EMA : Exponential Moving Average DEMA : Double Exponential Moving Average TEMA : Triple Exponential Moving Average
Source code in src/numta/api/overlap.py
1126 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 | |
DEMA - Double Exponential Moving Average¶
DEMA
¶
Double Exponential Moving Average (DEMA)
The Double Exponential Moving Average (DEMA) is a smoothing indicator that reduces lag compared to traditional EMAs. Despite its name, it's not simply two EMAs but rather a composite of single and double EMAs designed to follow prices more closely.
Developed by Patrick Mulloy and published in February 1994, DEMA aims to provide a moving average with less lag than traditional moving averages.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the calculation (default: 30)
Returns¶
np.ndarray Array of DEMA values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib DEMA signature
- Uses Numba JIT compilation for maximum performance
- The first (2 * timeperiod - 2) values will be NaN
- Lookback period: 2 * timeperiod - 2
- More responsive than standard EMA
Formula¶
EMA1 = EMA(close, timeperiod) EMA2 = EMA(EMA1, timeperiod) DEMA = 2 * EMA1 - EMA2
The formula removes lag by subtracting the "EMA of EMA" from double the original EMA. This creates a faster-reacting moving average.
Lookback period: 2 * timeperiod - 2 (For timeperiod=30, lookback=58)
Interpretation: - DEMA follows prices more closely than SMA or EMA - Crossovers generate earlier signals than traditional MAs - Steeper slope indicates stronger trend - Use for trend following and dynamic support/resistance - Less prone to whipsaws in trending markets
Advantages: - Reduced lag compared to SMA and EMA - Smoother than short-period EMAs - Earlier trend change signals - Better tracking of price movements
Common Uses: - Trend identification and confirmation - Dynamic support/resistance levels - Crossover trading systems - Identifying entry/exit points - Filtering market noise
Examples¶
import numpy as np from numta import DEMA close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109]) dema = DEMA(close, timeperiod=5) print(dema)
See Also¶
EMA : Exponential Moving Average TEMA : Triple Exponential Moving Average SMA : Simple Moving Average
Source code in src/numta/api/overlap.py
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 318 319 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 | |
TEMA - Triple Exponential Moving Average¶
TEMA
¶
Triple Exponential Moving Average (TEMA)
TEMA uses multiple EMAs to reduce lag and provide a smoother trend indicator.
Parameters¶
data : array-like Input data array timeperiod : int, optional Period for EMA calculations (default: 30)
Returns¶
np.ndarray Array of TEMA values
Formula¶
TEMA = 3EMA - 3EMA(EMA) + EMA(EMA(EMA))
See Also¶
EMA : Exponential Moving Average DEMA : Double Exponential Moving Average
Source code in src/numta/api/overlap.py
KAMA - Kaufman Adaptive Moving Average¶
KAMA
¶
Kaufman Adaptive Moving Average (KAMA)
The Kaufman Adaptive Moving Average (KAMA) is an intelligent moving average developed by Perry Kaufman. Unlike traditional moving averages with fixed smoothing, KAMA adapts its smoothing constant based on market efficiency.
KAMA uses an Efficiency Ratio (ER) to measure the directional movement relative to volatility. When prices move efficiently in one direction, KAMA responds quickly (like a fast EMA). During choppy, sideways markets, KAMA slows down (like a slow EMA), reducing noise and false signals.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the efficiency ratio calculation (default: 30)
Returns¶
np.ndarray Array of KAMA values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib KAMA signature
- Uses Numba JIT compilation for maximum performance
- The first timeperiod values will be NaN
- Lookback period: timeperiod
- Adapts to market conditions automatically
Formula¶
- Efficiency Ratio (ER): ER = Change / Volatility where:
- Change = |Close[i] - Close[i - timeperiod]|
-
Volatility = Sum of |Close[j] - Close[j-1]| over timeperiod
-
Smoothing Constant (SC): SC = [ER × (Fastest - Slowest) + Slowest]² where:
- Fastest = 2/(2+1) = 0.6667 (2-period EMA constant)
-
Slowest = 2/(30+1) = 0.0645 (30-period EMA constant)
-
KAMA: KAMA[0] = Close[timeperiod] KAMA[i] = KAMA[i-1] + SC × (Close[i] - KAMA[i-1])
Lookback period: timeperiod (For timeperiod=30, lookback=30)
Interpretation: - ER near 1.0: Strong directional move (low noise) → KAMA reacts quickly - ER near 0.0: Choppy market (high noise) → KAMA smooths heavily - KAMA above price: Potential resistance / bearish signal - KAMA below price: Potential support / bullish signal - KAMA slope indicates trend strength and direction - Price crossing KAMA: Potential trend change signal
Advantages: - Self-adjusting to market conditions - Reduces whipsaws in ranging markets - Responsive during trending markets - Better signal-to-noise ratio than fixed MAs - Fewer false signals than traditional MAs
Common Uses: - Trend identification in various market conditions - Dynamic support/resistance levels - Crossover trading systems with price or other MAs - Trailing stop placement - Market regime detection (trending vs ranging)
Trading Signals: - Buy: Price crosses above KAMA with positive slope - Sell: Price crosses below KAMA with negative slope - Strong trend: KAMA shows smooth, consistent slope - Consolidation: KAMA flattens, indicating market indecision
Examples¶
import numpy as np from numta import KAMA close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109]) kama = KAMA(close, timeperiod=5) print(kama)
See Also¶
EMA : Exponential Moving Average DEMA : Double Exponential Moving Average SMA : Simple Moving Average
References¶
Kaufman, P. J. (1995). "Smarter Trading: Improving Performance in Changing Markets"
Source code in src/numta/api/overlap.py
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 412 413 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 | |
MAMA - MESA Adaptive Moving Average¶
MAMA
¶
MESA Adaptive Moving Average (MAMA)
MAMA (MESA Adaptive Moving Average) was developed by John Ehlers and uses the Hilbert Transform to adapt to price movement. It features a fast attack average and a slow decay average, allowing it to quickly respond to price changes while holding its value during consolidations.
Returns both MAMA and FAMA (Following Adaptive Moving Average) lines.
Parameters¶
close : array-like Close prices array fastlimit : float, optional Upper limit for the adaptive alpha (default: 0.5) slowlimit : float, optional Lower limit for the adaptive alpha (default: 0.05)
Returns¶
tuple of np.ndarray (mama, fama) - Two arrays with the MAMA and FAMA values
Notes¶
- Compatible with TA-Lib MAMA signature
- This is a simplified implementation
- Uses EMA-based adaptation instead of full Hilbert Transform
- Lookback period: approximately 32 bars
- MAMA responds faster than FAMA to price changes
Interpretation: - MAMA > FAMA: Bullish signal (uptrend) - MAMA < FAMA: Bearish signal (downtrend) - MAMA crossing above FAMA: Buy signal - MAMA crossing below FAMA: Sell signal - Distance between MAMA and FAMA indicates trend strength
Advantages: - Adaptive to market conditions - Reduces whipsaw trades - Fast response to trend changes - Holds value during consolidations - Dual lines provide crossover signals
Common Uses: - Trend following and identification - Entry/exit signals via crossovers - Dynamic support/resistance levels - Trend strength measurement - Filter for trading systems
Examples¶
import numpy as np from numta import MAMA close = np.linspace(100, 150, 50) mama, fama = MAMA(close, fastlimit=0.5, slowlimit=0.05) print(f"MAMA: {mama[-1]:.2f}, FAMA: {fama[-1]:.2f}")
See Also¶
KAMA : Kaufman Adaptive Moving Average EMA : Exponential Moving Average HT_TRENDLINE : Hilbert Transform - Instantaneous Trendline
References¶
Ehlers, J. F. (2001). "MAMA - The Mother of Adaptive Moving Averages" Stocks & Commodities Magazine, September 2001
Source code in src/numta/api/overlap.py
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 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
T3 - Triple Exponential T3¶
T3
¶
Triple Exponential Moving Average (T3)
T3 is a smoothed moving average developed by Tim Tillson that uses multiple EMAs with a volume factor for improved smoothness and reduced lag.
Parameters¶
data : array-like Input data array timeperiod : int, optional Period for EMA calculations (default: 5) vfactor : float, optional Volume factor (default: 0.7, range: 0 to 1)
Returns¶
np.ndarray Array of T3 values
Notes¶
T3 applies 6 EMAs with coefficients based on vfactor
Source code in src/numta/api/overlap.py
TRIMA - Triangular Moving Average¶
TRIMA
¶
Triangular Moving Average (TRIMA)
TRIMA is a double-smoothed simple moving average that places more weight on the middle portion of the data series. It's calculated as an SMA of an SMA, creating a triangular weighting pattern.
Parameters¶
data : array-like Input data array timeperiod : int, optional Period for the moving average (default: 30)
Returns¶
np.ndarray Array of TRIMA values
Notes¶
- Provides extra smoothing compared to SMA
- Lags more than SMA but filters noise better
- Compatible with TA-Lib TRIMA signature
- More weight on middle data points
Formula¶
When period is odd: n = (period + 1) / 2 TRIMA = SMA(SMA(data, n), n)
When period is even
n1 = period / 2 n2 = n1 + 1 TRIMA = SMA(SMA(data, n1), n2)
Interpretation: - Smoother than SMA due to double averaging - Good for identifying long-term trends - Filters out short-term noise - Slower to react to price changes
Examples¶
import numpy as np from numta import TRIMA close = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) trima = TRIMA(close, timeperiod=5)
See Also¶
SMA : Simple Moving Average EMA : Exponential Moving Average DEMA : Double Exponential Moving Average
Source code in src/numta/api/overlap.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | |
MA - Generic Moving Average¶
MA
¶
Moving Average (MA)
Generic moving average function that can calculate different types of moving averages based on the matype parameter. This provides a unified interface for accessing various moving average implementations.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the moving average (default: 30) matype : int, optional Type of moving average (default: 0) - 0: SMA (Simple Moving Average) - 1: EMA (Exponential Moving Average) - 2: WMA (Weighted Moving Average) - 3: DEMA (Double Exponential Moving Average) - 4: TEMA (Triple Exponential Moving Average) - 5: TRIMA (Triangular Moving Average) - 6: KAMA (Kaufman Adaptive Moving Average) - 7: MAMA (Mesa Adaptive Moving Average) - 8: T3 (Triple Exponential T3)
Returns¶
np.ndarray Array of moving average values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib MA signature
- Uses Numba JIT compilation for maximum performance
- Lookback period varies by MA type
- All MA types fully implemented and optimized
Supported Moving Average Types¶
SMA (matype=0): Simple Moving Average - Arithmetic mean of prices over timeperiod - Equal weight to all data points - Lookback: timeperiod - 1
EMA (matype=1): Exponential Moving Average - Exponentially weighted moving average - More weight to recent prices - Responds faster to price changes than SMA - Lookback: timeperiod - 1
WMA (matype=2): Weighted Moving Average - Linear weighted moving average - More weight to recent prices (linear weighting) - Lookback: timeperiod - 1
DEMA (matype=3): Double Exponential Moving Average - Reduced lag compared to EMA - Formula: 2EMA - EMA(EMA) - Lookback: 2timeperiod - 2
TEMA (matype=4): Triple Exponential Moving Average - Even lower lag than DEMA - Formula: 3EMA - 3EMA(EMA) + EMA(EMA(EMA)) - Lookback: 3*timeperiod - 3
TRIMA (matype=5): Triangular Moving Average - Double-smoothed simple moving average - Very smooth, high lag - Lookback: varies by timeperiod
KAMA (matype=6): Kaufman Adaptive Moving Average - Adapts to market conditions - Fast in trending markets, slow in ranging markets - Uses Efficiency Ratio for adaptation - Lookback: timeperiod
MAMA (matype=7): Mesa Adaptive Moving Average - Adaptive MA using Hilbert Transform concepts - Fast attack and slow decay - Lookback: approximately 32 bars
T3 (matype=8): Triple Exponential T3 - Smoothest of the exponential MAs - Uses 6 EMAs with volume factor - Lookback: 6*timeperiod - 6
Interpretation: - MA smooths price action to reveal underlying trend - Price above MA: Potential uptrend - Price below MA: Potential downtrend - MA slope indicates trend direction - Different MA types offer different lag vs smoothness tradeoffs
Common Uses: - Trend identification and confirmation - Dynamic support/resistance levels - Crossover trading systems - Filtering market noise - Identifying entry/exit points
Examples¶
import numpy as np from numta import MA close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109])
Simple Moving Average¶
sma = MA(close, timeperiod=5, matype=0)
Exponential Moving Average¶
ema = MA(close, timeperiod=5, matype=1)
Double Exponential Moving Average¶
dema = MA(close, timeperiod=5, matype=3)
Kaufman Adaptive Moving Average¶
kama = MA(close, timeperiod=5, matype=6)
See Also¶
SMA : Simple Moving Average EMA : Exponential Moving Average DEMA : Double Exponential Moving Average KAMA : Kaufman Adaptive Moving Average
Source code in src/numta/api/overlap.py
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 504 505 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 610 611 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 | |
Bands and Channels¶
BBANDS - Bollinger Bands¶
BBANDS
¶
BBANDS(close: Union[ndarray, list], timeperiod: int = 5, nbdevup: float = 2.0, nbdevdn: float = 2.0, matype: int = 0) -> tuple
Bollinger Bands (BBANDS)
Bollinger Bands are a volatility indicator that consists of three lines: a middle band (SMA), an upper band, and a lower band. The upper and lower bands are typically set 2 standard deviations away from the middle band.
Developed by John Bollinger, these bands expand and contract based on market volatility. They are widely used for identifying overbought/oversold conditions and potential breakouts.
Parameters¶
close : array-like Close prices array timeperiod : int, optional Number of periods for the moving average (default: 5) nbdevup : float, optional Number of standard deviations for upper band (default: 2.0) nbdevdn : float, optional Number of standard deviations for lower band (default: 2.0) matype : int, optional Moving average type: 0 = SMA (default). Note: Only SMA is currently supported.
Returns¶
tuple of np.ndarray (upperband, middleband, lowerband) - Three arrays with the band values
Notes¶
- Compatible with TA-Lib BBANDS signature
- Uses Numba JIT compilation for maximum performance
- The first (timeperiod - 1) values will be NaN
- Currently only supports SMA (matype=0)
- Bands widen during high volatility and narrow during low volatility
Formula¶
Middle Band = SMA(close, timeperiod) Upper Band = Middle Band + (nbdevup × StdDev) Lower Band = Middle Band - (nbdevdn × StdDev)
Where StdDev is the population standard deviation over the timeperiod.
Lookback period: timeperiod - 1 (For timeperiod=20, lookback=19)
Interpretation: - Price touching upper band: Potential overbought condition - Price touching lower band: Potential oversold condition - Band squeeze (narrow bands): Low volatility, potential breakout coming - Band expansion (wide bands): High volatility, trend in progress - Price breaking above upper band: Strong uptrend - Price breaking below lower band: Strong downtrend - Middle band acts as dynamic support/resistance
Common Trading Strategies: - Bollinger Bounce: Buy at lower band, sell at upper band (ranging markets) - Bollinger Squeeze: Trade breakouts after period of low volatility - Walking the Bands: In strong trends, price "walks" along one band - %b Indicator: (Price - Lower Band) / (Upper Band - Lower Band)
Examples¶
import numpy as np from numta import BBANDS close = np.array([100, 102, 101, 103, 105, 104, 106, 108, 107, 109]) upper, middle, lower = BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2) print(upper) print(middle) print(lower)
Source code in src/numta/api/overlap.py
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 213 214 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 | |
Trend Following¶
SAR - Parabolic SAR¶
SAR
¶
SAR(high: Union[ndarray, list], low: Union[ndarray, list], acceleration: float = 0.02, maximum: float = 0.2) -> np.ndarray
Parabolic SAR (Stop and Reverse)
Parabolic SAR, developed by J. Welles Wilder, is a trend-following indicator that provides entry and exit points. It appears as a series of dots placed above or below price bars, indicating the direction of the trend and potential reversal points.
The indicator accelerates with the trend, moving closer to price as the trend continues, providing trailing stop levels.
Parameters¶
high : array-like High prices array low : array-like Low prices array acceleration : float, optional Acceleration factor (default: 0.02) maximum : float, optional Maximum acceleration factor (default: 0.2)
Returns¶
np.ndarray Array of SAR values
Notes¶
- Compatible with TA-Lib SAR signature
- Uses Numba JIT compilation for performance
- No lookback period (starts from first bar)
- Default values from Wilder's recommendation
Algorithm¶
- Start with initial SAR and trend direction
- Each period:
- Calculate new SAR = Prior SAR + AF * (EP - Prior SAR)
- If long: SAR must be below prior 2 lows
- If short: SAR must be above prior 2 highs
- Check for reversal:
- Long: If low < SAR, reverse to short
- Short: If high > SAR, reverse to long
- Update EP (extreme point) and AF if trend continues
Where: - SAR: Stop and Reverse point - EP: Extreme Point (highest high or lowest low in current trend) - AF: Acceleration Factor (starts at 'acceleration', increases by 'acceleration' each time EP is updated, capped at 'maximum')
Interpretation: - SAR below price: Uptrend (bullish) - SAR above price: Downtrend (bearish) - SAR reversal: Trend change signal - Distance from price: Trend strength - AF increase: Trend acceleration
Advantages: - Clear buy/sell signals - Automatic trailing stop - Works well in trending markets - Objective entry/exit points - No lag (price-based, not average-based)
Disadvantages: - Whipsaw in sideways markets - Always in the market (long or short) - Cannot signal "no position" - Less effective in choppy conditions
Common Uses: - Trend direction identification - Trailing stop placement - Entry/exit signals - Stop loss management - Trend reversal detection
Trading Signals: 1. Basic: - Buy when SAR flips from above to below price - Sell when SAR flips from below to above price
- Trailing Stop:
- Long position: Use SAR as trailing stop loss
-
Short position: Use SAR as trailing stop loss
-
Combination:
- Use with trend filter (e.g., ADX)
- Confirm with other indicators
- Avoid in low ADX (choppy) conditions
Parameter Adjustment: - Acceleration (default 0.02): - Lower (0.01): More conservative, fewer signals - Higher (0.05): More aggressive, more signals
- Maximum (default 0.2):
- Lower (0.1): Slower acceleration
- Higher (0.3): Faster acceleration
Examples¶
import numpy as np from numta import SAR high = np.array([110, 112, 111, 113, 115, 114, 116, 118]) low = np.array([100, 102, 101, 103, 105, 104, 106, 108]) sar = SAR(high, low, acceleration=0.02, maximum=0.2)
SAR values indicate stop and reverse points¶
See Also¶
SAREXT : Parabolic SAR Extended ADX : Average Directional Index (trend strength)
Source code in src/numta/api/overlap.py
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 840 841 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 | |
SAREXT - Parabolic SAR Extended¶
SAREXT
¶
SAREXT(high: Union[ndarray, list], low: Union[ndarray, list], startvalue: float = 0.0, offsetonreverse: float = 0.0, accelerationinit_long: float = 0.02, accelerationlong: float = 0.02, accelerationmax_long: float = 0.2, accelerationinit_short: float = 0.02, accelerationshort: float = 0.02, accelerationmax_short: float = 0.2) -> np.ndarray
Parabolic SAR - Extended (SAREXT)
Extended version of Parabolic SAR with separate parameters for long and short positions. This allows for asymmetric acceleration and more fine-tuned control over the indicator's behavior in different market conditions.
Parameters¶
high : array-like High prices array low : array-like Low prices array startvalue : float, optional Starting value for SAR (default: 0.0, auto-calculated) offsetonreverse : float, optional Offset on reversal (default: 0.0) accelerationinit_long : float, optional Initial acceleration factor for long (default: 0.02) accelerationlong : float, optional Acceleration increment for long (default: 0.02) accelerationmax_long : float, optional Maximum acceleration for long (default: 0.2) accelerationinit_short : float, optional Initial acceleration factor for short (default: 0.02) accelerationshort : float, optional Acceleration increment for short (default: 0.02) accelerationmax_short : float, optional Maximum acceleration for short (default: 0.2)
Returns¶
np.ndarray Array of SAR values
Notes¶
- Compatible with TA-Lib SAREXT signature
- Allows asymmetric parameters for long/short
- More flexible than standard SAR
- Useful for markets with directional bias
See Also¶
SAR : Standard Parabolic SAR
Source code in src/numta/api/overlap.py
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 955 956 957 958 959 960 | |