turtle_quant_1.strategies.helpers.support_resistance.stnry_local_extrema¶
turtle_quant_1.strategies.helpers.support_resistance.stnry_local_extrema
¶
Stationary local extrema static support and resistance strategy.
StnryLocalExtrema
¶
StnryLocalExtrema(
strong_peak_distance: int = 10,
strong_peak_prominence_pct: float = 0.01,
peak_distance: int = 5,
peak_rank_width: float = 2.0,
res_min_pivot_rank: int = 3,
)
Bases: BaseSupResStrategy
Stationary local extrema static support and resistance strategy.
Refer to https://medium.com/@itay1542/how-to-calculate-support-and-resistance-levels-using-python-a-step-by-step-guide-e94a33c6cbda.
This strategy identifies support and resistance levels by finding local extrema (peaks and troughs) in the price data and ranking them based on their frequency and proximity to other extrema.
Initialize the StnryLocalExtrema strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strong_peak_distance
|
int
|
Distance between strong peaks (in days). |
10
|
strong_peak_prominence_pct
|
float
|
Prominence for strong peaks (as fraction of price range). |
0.01
|
peak_distance
|
int
|
Distance between general peaks (in days). |
5
|
peak_rank_width
|
float
|
Width for grouping nearby peaks. |
2.0
|
res_min_pivot_rank
|
int
|
Minimum rank for resistance levels. |
3
|
Source code in src/turtle_quant_1/strategies/helpers/support_resistance/stnry_local_extrema.py
generate_historical_levels
¶
Generate all support and resistance levels for historical data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data containing columns: ['datetime', 'Open', 'High', 'Low', 'Close', 'Volume'] |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with support and resistance levels. |
DataFrame
|
The columns are: ['datetime', 'level_values']. |