Pivot Detection¶
pivots
¶
Pivot extraction utilities (EMA-derivative based).
Public API
ema_derivative_pivots(df: pd.DataFrame, ...) -> dict
Returns pivot indices for price & RSI along with metadata.
ema_derivative_pivots(df, price_col='Close', rsi_col='RSI', price_span=5, rsi_span=5)
¶
Detect pivot highs/lows via sign changes in first derivative of EMA-smoothed series.
Method
- Smooth price & RSI with EMA.
- Compute first difference (derivative).
- Identify sign-change points as pivots:
- Pivot Low: derivative < 0 then > 0.
- Pivot High: derivative > 0 then < 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing at least |
required |
price_col
|
str
|
Price column name (default "Close"). |
'Close'
|
rsi_col
|
str
|
RSI column name (default "RSI"). |
'RSI'
|
price_span
|
int
|
EMA span for price smoothing. |
5
|
rsi_span
|
int
|
EMA span for RSI smoothing. |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: |
dict[str, Any]
|
|
Source code in src/stockcharts/indicators/pivots.py
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 | |
EMA-Derivative Method (Merged Guide)¶
Replaces earlier ZigZag approach for cleaner, parameter-light pivot extraction.
Logic¶
- Smooth series with EMA (price & RSI).
- Compute first derivative (rate of change).
- Sign change identifies pivot (negative→positive = low, positive→negative = high).
Advantages¶
- Minimal parameters (span only).
- Robust against noise.
- Symmetric application to price & RSI.
- Linear complexity.
Span Selection¶
| Span | Sensitivity | Use Case |
|---|---|---|
| 3-4 | High | Intraday/fast scans |
| 5-6 | Balanced | Swing trading (default) |
| 7-9 | Smooth | Position trading |
| 10+ | Very Smooth | Major turns only |
CLI Flags¶
--pivot-method ema-deriv --ema-price-span N --ema-rsi-span N
Example¶
stockcharts-rsi-divergence --type bullish --pivot-method ema-deriv --ema-price-span 7 --ema-rsi-span 7
Future Enhancements¶
Adaptive spans, derivative thresholding, multi-span confirmation.