Trend¶

Trend indicators answer: which way is price heading, and how strongly? Where momentum measures speed, trend tools estimate direction and persistence — the smoothed path, its slope, and whether a directional move is worth following or is just noise.
Moving averages — the building blocks¶
sma_indicator— the plain average; simple, laggy.ema_indicator— weights recent bars more, so it turns faster than the SMA.wma_indicator/hull_moving_average— the WMA and the Hull MA cut lag further; the Hull is the smoothest-yet-responsive of the set.dema/tema— the lag-cancelling pair. An EMA always trails price; DEMA estimates that lag with a second EMA and subtracts it (2*EMA - EMA(EMA)), and TEMA carries the idea one order further. On a constant-slope move they track it exactly, where an EMA never catches up — the trade is overshoot at sharp reversals.t3— Tillson's T3: six chained EMAs recombined via av_factor(default0.7) that dials between smoothness and responsiveness. Smoother than DEMA/TEMA while keeping much of their speed.trima— the opposite trade: an SMA of an SMA, weighting the middle of the window most. Smoother and laggier than an SMA, useful when you want a stable baseline rather than a fast one.
Picking a moving average
Lag and smoothness are a single dial, and each average here sits somewhere
on it: trima → sma → ema → t3 → hull → dema → tema, roughly
from laggiest-smoothest to fastest-noisiest. Faster is not better; a fast
MA on noisy data mostly produces whipsaws.
Direction & strength¶
macd/macd_signal/macd_diff— the workhorse: the gap between a fast and slow EMA (line), its own EMA (signal), and their difference (histogram, an early momentum-of-trend read).adx+adx_pos/adx_neg— ADX measures trend strength regardless of direction; the ±DI pair supplies the direction. The single best "should I even be trend-following right now?" gate.dx/adxr/plus_dm/minus_dm— the rest of Wilder's directional ladder, exposed separately because each stage is useful on its own. Rawplus_dm/minus_dmkeep the magnitude of directional movement that ±DI normalizes away;dxis ADX before its final smoothing, so it reacts a full period sooner at the cost of noise;adxraverages ADX with its valuewindowbars ago, smoothing further to show whether trend strength is building or fading.aroon_up/aroon_down— how recently the window's high / low was set; a clean way to detect the start of a new trend.vortex_indicator_pos/vortex_indicator_neg— trend direction from the relationship between consecutive highs and lows.
Trend-following systems & filters¶
psar— Parabolic SAR: a trailing stop-and-reverse dot that also marks the trend side.supertrend— an ATR-banded trend line; a popular, readable stop/entry rail.ichimoku_a/ichimoku_band the conversion/base lines — a whole trend-and-support system in one overlay (the "cloud").cci/trix/dpo/kst/stc/mass_index— oscillator-style trend measures: deviation from the mean (CCI), triple-smoothed rate of change (TRIX), a detrended price cycle (DPO), a summed multi-timeframe momentum (KST), a Schaff cycle (STC), and a range-expansion reversal warning (Mass Index).elder_bull_power/elder_bear_power— how far buyers / sellers push price beyond a baseline EMA.
Gate momentum with trend strength
A classic combination: use adx to decide whether
the market is trending, then follow macd when it
is and fade a momentum oscillator when it isn't. See the
regime-conditional switch.
polars_ta.trend
¶
TrendIndicators
¶
Trend Indicators translated to Polars Expressions.
aroon_up
staticmethod
¶
aroon_up(high: str | Expr, window: int = 25, fillna: bool = False) -> Expr
Aroon Up Channel
Source code in polars_ta/trend.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
aroon_down
staticmethod
¶
aroon_down(low: str | Expr, window: int = 25, fillna: bool = False) -> Expr
Aroon Down Channel
Source code in polars_ta/trend.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
aroon_indicator
staticmethod
¶
aroon_indicator(high: str | Expr, low: str | Expr, window: int = 25, fillna: bool = False) -> Expr
Aroon Indicator (Up - Down)
Source code in polars_ta/trend.py
46 47 48 49 50 51 52 53 54 | |
macd
staticmethod
¶
macd(close: str | Expr, window_slow: int = 26, window_fast: int = 12, fillna: bool = False) -> Expr
MACD Line
Source code in polars_ta/trend.py
59 60 61 62 63 64 65 66 67 68 69 70 71 | |
macd_signal
staticmethod
¶
macd_signal(close: str | Expr, window_slow: int = 26, window_fast: int = 12, window_sign: int = 9, fillna: bool = False) -> Expr
MACD Signal Line
Source code in polars_ta/trend.py
73 74 75 76 77 78 79 80 81 82 83 84 | |
macd_diff
staticmethod
¶
macd_diff(close: str | Expr, window_slow: int = 26, window_fast: int = 12, window_sign: int = 9, fillna: bool = False) -> Expr
MACD Histogram
Source code in polars_ta/trend.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
ema_indicator
staticmethod
¶
ema_indicator(close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Exponential Moving Average (EMA)
Source code in polars_ta/trend.py
105 106 107 108 109 110 | |
sma_indicator
staticmethod
¶
sma_indicator(close: str | Expr, window: int, fillna: bool = False) -> Expr
Simple Moving Average (SMA)
Source code in polars_ta/trend.py
112 113 114 115 116 117 | |
wma_indicator
staticmethod
¶
wma_indicator(close: str | Expr, window: int = 9, fillna: bool = False) -> Expr
Weighted Moving Average (WMA)
Source code in polars_ta/trend.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
dema
staticmethod
¶
dema(close: str | Expr, window: int = 30, fillna: bool = False) -> Expr
Double Exponential Moving Average (DEMA).
2 * EMA - EMA(EMA). The second term estimates the EMA's own lag, so
subtracting it lets DEMA track price far more closely than an EMA of
the same window — at the cost of overshooting sharp reversals.
Source code in polars_ta/trend.py
148 149 150 151 152 153 154 155 156 157 158 159 | |
tema
staticmethod
¶
tema(close: str | Expr, window: int = 30, fillna: bool = False) -> Expr
Triple Exponential Moving Average (TEMA).
3*EMA - 3*EMA(EMA) + EMA(EMA(EMA)) — the same lag-cancelling idea as
DEMA carried one order further, so it is faster still and noisier still.
Source code in polars_ta/trend.py
161 162 163 164 165 166 167 168 169 170 171 172 173 | |
trima
staticmethod
¶
trima(close: str | Expr, window: int = 30, fillna: bool = False) -> Expr
Triangular Moving Average (TRIMA).
An SMA of an SMA, which weights the middle of the window most
heavily. Smoother and laggier than an SMA — the opposite trade to
DEMA/TEMA. Matches TA-Lib's split of an odd window into
(n+1)/2 twice, and an even window into n/2 + 1 then n/2.
Source code in polars_ta/trend.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
t3
staticmethod
¶
t3(close: str | Expr, window: int = 5, v_factor: float = 0.7, fillna: bool = False) -> Expr
Tillson T3 moving average.
Six chained EMAs recombined with weights derived from v_factor. The
result is smoother than a DEMA/TEMA of the same window while keeping
much of their responsiveness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
close
|
str | Expr
|
Price series. |
required |
window
|
int
|
EMA period used for every stage. |
5
|
v_factor
|
float
|
Volume factor in |
0.7
|
fillna
|
bool
|
Forward-fill gaps when True. |
False
|
Source code in polars_ta/trend.py
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 | |
trix
staticmethod
¶
trix(close: str | Expr, window: int = 15, fillna: bool = False) -> Expr
Trix (TRIX) - Triple exponentially smoothed moving average percent change
Source code in polars_ta/trend.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
mass_index
staticmethod
¶
mass_index(high: str | Expr, low: str | Expr, window_fast: int = 9, window_slow: int = 25, fillna: bool = False) -> Expr
Mass Index (MI)
Source code in polars_ta/trend.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
ichimoku_conversion_line
staticmethod
¶
ichimoku_conversion_line(high: str | Expr, low: str | Expr, window1: int = 9, fillna: bool = False) -> Expr
Tenkan-sen (Conversion Line)
Source code in polars_ta/trend.py
286 287 288 289 290 291 292 293 294 295 | |
ichimoku_base_line
staticmethod
¶
ichimoku_base_line(high: str | Expr, low: str | Expr, window2: int = 26, fillna: bool = False) -> Expr
Kijun-sen (Base Line)
Source code in polars_ta/trend.py
297 298 299 300 301 302 303 304 305 306 | |
ichimoku_a
staticmethod
¶
ichimoku_a(high: str | Expr, low: str | Expr, window1: int = 9, window2: int = 26, visual: bool = False, fillna: bool = False) -> Expr
Senkou Span A (Leading Span A)
Source code in polars_ta/trend.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
ichimoku_b
staticmethod
¶
ichimoku_b(high: str | Expr, low: str | Expr, window2: int = 26, window3: int = 52, visual: bool = False, fillna: bool = False) -> Expr
Senkou Span B (Leading Span B)
Source code in polars_ta/trend.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
kst
staticmethod
¶
kst(close: str | Expr, roc1: int = 10, roc2: int = 15, roc3: int = 20, roc4: int = 30, window1: int = 10, window2: int = 10, window3: int = 10, window4: int = 15, fillna: bool = False) -> Expr
Know Sure Thing (KST)
Source code in polars_ta/trend.py
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 | |
kst_sig
staticmethod
¶
kst_sig(close: str | Expr, roc1: int = 10, roc2: int = 15, roc3: int = 20, roc4: int = 30, window1: int = 10, window2: int = 10, window3: int = 10, window4: int = 15, nsig: int = 9, fillna: bool = False) -> Expr
Signal Line Know Sure Thing (KST)
Source code in polars_ta/trend.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
kst_diff
staticmethod
¶
kst_diff(close: str | Expr, roc1: int = 10, roc2: int = 15, roc3: int = 20, roc4: int = 30, window1: int = 10, window2: int = 10, window3: int = 10, window4: int = 15, nsig: int = 9, fillna: bool = False) -> Expr
Diff Know Sure Thing (KST)
Source code in polars_ta/trend.py
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 | |
ComplexTrendIndicators
¶
dpo
staticmethod
¶
dpo(close: str | Expr, window: int = 20, fillna: bool = False) -> Expr
Detrended Price Oscillator (DPO)
Source code in polars_ta/trend.py
446 447 448 449 450 451 452 453 454 455 456 457 458 | |
cci
staticmethod
¶
cci(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 20, constant: float = 0.015, fillna: bool = False) -> Expr
Commodity Channel Index (CCI)
Source code in polars_ta/trend.py
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 | |
vortex_pos
staticmethod
¶
vortex_pos(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
+VI (Positive Vortex Indicator)
Source code in polars_ta/trend.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
vortex_neg
staticmethod
¶
vortex_neg(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
-VI (Negative Vortex Indicator)
Source code in polars_ta/trend.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
vortex_diff
staticmethod
¶
vortex_diff(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Diff VI
Source code in polars_ta/trend.py
540 541 542 543 544 545 546 547 548 549 550 551 552 | |
adx_pos
staticmethod
¶
adx_pos(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
+DI
Source code in polars_ta/trend.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
adx_neg
staticmethod
¶
adx_neg(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
-DI
Source code in polars_ta/trend.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 | |
adx
staticmethod
¶
adx(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Average Directional Index (ADX)
Source code in polars_ta/trend.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
dx
staticmethod
¶
dx(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Directional Movement Index (DX) — ADX before its final smoothing.
100 * |+DI - -DI| / (+DI + -DI). Noisier than ADX but reacts a full
smoothing period sooner, which is why it is worth having separately.
Source code in polars_ta/trend.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
adxr
staticmethod
¶
adxr(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Average Directional Movement Index Rating (ADXR).
The mean of ADX now and ADX window bars ago. Smoother than ADX and
traditionally used to judge whether trend strength itself is building
or fading.
Source code in polars_ta/trend.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
plus_dm
staticmethod
¶
plus_dm(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Plus Directional Movement (+DM), Wilder-smoothed.
The raw upward component behind +DI, before it is normalized by true range. Useful as a model feature on its own, since it keeps the magnitude of directional movement that +DI divides away.
Source code in polars_ta/trend.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
minus_dm
staticmethod
¶
minus_dm(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 14, fillna: bool = False) -> Expr
Minus Directional Movement (-DM), Wilder-smoothed.
The downward counterpart of plus_dm.
Source code in polars_ta/trend.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
psar
staticmethod
¶
psar(high: str | Expr, low: str | Expr, close: str | Expr, step: float = 0.02, max_step: float = 0.2, fillna: bool = False) -> Expr
Parabolic SAR computed using map_batches for stateful execution.
Source code in polars_ta/trend.py
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 | |
stc
staticmethod
¶
stc(close: str | Expr, window_slow: int = 50, window_fast: int = 23, cycle: int = 10, smooth1: int = 3, smooth2: int = 3, fillna: bool = False) -> Expr
Schaff Trend Cycle (STC)
Source code in polars_ta/trend.py
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 | |
hull_moving_average
staticmethod
¶
hull_moving_average(close: str | Expr, window: int = 9, fillna: bool = False) -> Expr
Hull Moving Average: WMA(2*WMA(n/2) - WMA(n), sqrt(n)).
Reduces the lag inherent in a plain moving average while staying
smoother than price itself, at the cost of the extra WMA passes
needing window + round(sqrt(window)) - 1 bars of warm-up.
Source code in polars_ta/trend.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | |
supertrend
staticmethod
¶
supertrend(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 10, multiplier: float = 3.0, fillna: bool = False) -> Expr
SuperTrend line: an ATR-banded trend-following stop-and-reverse
indicator, computed via map_batches for the stateful band-flip
logic (the same style as psar).
Source code in polars_ta/trend.py
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 | |
elder_bull_power
staticmethod
¶
elder_bull_power(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 13, fillna: bool = False) -> Expr
Bull Power: high minus a 13-bar EMA of close.
Source code in polars_ta/trend.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
elder_bear_power
staticmethod
¶
elder_bear_power(high: str | Expr, low: str | Expr, close: str | Expr, window: int = 13, fillna: bool = False) -> Expr
Bear Power: low minus a 13-bar EMA of close.
Source code in polars_ta/trend.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |