You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Indicators that combine trend detection with adaptive trailing stops.
912
+
913
+
#### SuperTrend Clustering
914
+
915
+
The SuperTrend Clustering indicator uses K-means clustering to optimize the ATR multiplier factor for the SuperTrend calculation. It computes multiple SuperTrend variations with different factors, evaluates their performance, and clusters them into "best", "average", and "worst" groups. The best-performing factor is then used to generate an adaptive trailing stop with buy/sell signals.
916
+
917
+
Based on the LuxAlgo SuperTrend AI indicator concept.
918
+
919
+
```python
920
+
defsupertrend_clustering(
921
+
data: Union[PdDataFrame, PlDataFrame],
922
+
atr_length: int=10,
923
+
min_mult: float=1.0,
924
+
max_mult: float=5.0,
925
+
step: float=0.5,
926
+
perf_alpha: float=10.0,
927
+
from_cluster: str='best',
928
+
max_iter: int=1000,
929
+
max_data: int=10000
930
+
) -> Union[PdDataFrame, PlDataFrame]:
931
+
```
932
+
933
+
Returns the following columns:
934
+
-`supertrend`: The optimized SuperTrend trailing stop
935
+
-`supertrend_trend`: Current trend (1=bullish, 0=bearish)
936
+
-`supertrend_ama`: Adaptive moving average of SuperTrend
937
+
-`supertrend_perf_idx`: Performance index (0–1 scale)
938
+
-`supertrend_factor`: Currently used ATR factor
939
+
-`supertrend_signal`: 1=buy signal, -1=sell signal, 0=no signal
940
+
941
+
Example
942
+
943
+
```python
944
+
from investing_algorithm_framework import download
945
+
946
+
from pyindicators import supertrend_clustering, get_supertrend_stats
The basic SuperTrend indicator uses a fixed ATR multiplier factor to create a trend-following trailing stop. When the price is above the SuperTrend line the trend is bullish; when below, bearish. Trend changes generate buy/sell signals.
982
+
983
+
```python
984
+
defsupertrend_basic(
985
+
data: Union[PdDataFrame, PlDataFrame],
986
+
atr_length: int=10,
987
+
factor: float=3.0
988
+
) -> Union[PdDataFrame, PlDataFrame]:
989
+
```
990
+
991
+
Returns the following columns:
992
+
-`supertrend`: The SuperTrend trailing stop value
993
+
-`supertrend_trend`: Current trend (1=bullish, 0=bearish)
994
+
-`supertrend_upper`: Upper band
995
+
-`supertrend_lower`: Lower band
996
+
-`supertrend_signal`: 1=buy signal, -1=sell signal, 0=no signal
997
+
998
+
Example
999
+
1000
+
```python
1001
+
from investing_algorithm_framework import download
0 commit comments