Note: This documents the legacy SMA/MACD/RSI derivative signal layer. See kalman_trend_analyzer.ts for the current trend detection implementation.
The derivative analyzer uses four indicators:
SMA(slow) for macro trend / regimefastSMA(optional) for short-term direction — used as the trend filter source and fast-SMA commitment gateMACDfor momentumRSIfor exhaustion and counter-trend filtering
The output signal is one of:
BULLBULL_WEAKBEARBEAR_WEAKOVERBOUGHTOVERSOLDNEUTRAL
There are three independent output layers:
trend/rawTrend/isConfirmedcome from SMA direction alone.--confirmcontrols only this MA-trend confirmation layer.interpretation/interpretationRaware the trading-style states (BULL,BEAR,OVERBOUGHT, etc.).--interp-confirmand--interp-holdcontrol only this signal layer.entryBiasand its boolean helpers are derived execution hints built on top of the finalinterpretationstate. They do not change the base signal engine. They classify whether a directional setup is an early weak entry or a proper confirmation once slow and fast SMA alignment is in place.
Simple moving average over the configured slow period.
Derivative signal
d(SMA)/dt > 0 -> UP
d(SMA)/dt < 0 -> DOWN
d(SMA)/dt = 0 -> NEUTRAL
Flag
| Flag | Default | Meaning |
|---|---|---|
--sma N |
500 | Slow SMA period |
The slow SMA defines the macro regime. It is the reference line for the price regime gate and the macro disagree cap (see Trend filter).
Optional second moving average over a shorter period. When present it takes over from the slow SMA as the primary trend filter direction source and enables two additional signal quality checks.
Derivative signal
d(fastSMA)/dt > 0 -> UP
d(fastSMA)/dt < 0 -> DOWN
d(fastSMA)/dt = 0 -> NEUTRAL
Flag
| Flag | Default | Meaning |
|---|---|---|
--fast-sma N |
off | Fast SMA period (e.g. 100) |
When --fast-sma is set:
- The trend filter reads fastSMA direction instead of slow SMA direction.
- Macro disagree cap: if fastSMA and slow SMA point in opposite directions, a full
BULL/BEARis capped toBULL_WEAK/BEAR_WEAK. - Fast-SMA commitment gate:
BULL/BEARconfirmation requires price to have been on the correct side of fastSMA for ≥--fast-sma-commitment-barsconsecutive bars (default 2). Failing bars reset the confirmation counter.
Both the price overlay line and the derivative direction panel in the chart show fastSMA alongside slow SMA.
Momentum indicator built from the normalized MACD line, signal line, and histogram.
Interpretation
- Histogram > 0: bullish momentum
- Histogram < 0: bearish momentum
- Histogram shrinking: momentum fading
- MACD line > 0: positive regime
- MACD line < 0: negative regime
Flags
| Flag | Default | Meaning |
|---|---|---|
--macd-fast N |
12 | Fast EMA period |
--macd-slow N |
26 | Slow EMA period |
--macd-signal N |
9 | Signal EMA period |
--macd-min-hist F |
0.02 | Minimum histogram magnitude before a directional signal is allowed |
Relative Strength Index used as a confidence modifier and exhaustion gate.
Zones
| RSI | Meaning |
|---|---|
> --rsi-extreme |
OVERBOUGHT |
50 + --rsi-zone |
Bullish zone |
50 - --rsi-zone |
Bearish zone |
< 100 - --rsi-extreme |
OVERSOLD |
Flags
| Flag | Default | Meaning |
|---|---|---|
--rsi N |
14 | RSI period |
--rsi-zone N |
10 | Distance from 50 for counter-trend downgrade |
--rsi-extreme N |
90 | Exhaustion threshold |
RSI no longer hard-gates the base signal. It only downgrades or overrides it.
MACD histogram decides the initial directional candidate:
hist > macd-min-hist -> BULL candidate
hist < -macd-min-hist -> BEAR candidate
otherwise -> NEUTRAL
BULL and BEAR require sustained raw direction before they are confirmed.
Flag
| Flag | Default | Meaning |
|---|---|---|
--interp-confirm N |
3 | Bars required to confirm a raw BULL/BEAR |
Confirmed BULL/BEAR states do not drop immediately on a minor fluctuation.
Flag
| Flag | Default | Meaning |
|---|---|---|
--interp-hold N |
3 | Bars a downgrade must persist before it is applied |
Some regime failures bypass hysteresis completely. A confirmed BULL/BEAR is dropped immediately when the signal is no longer structurally valid.
Immediate invalidation triggers:
- Post-filter MACD line regime failure —
BULLrequires MACD line >=macd-min-hist;BEARrequires MACD line <=-macd-min-hist. - Macro disagree failure — when fastSMA and slow SMA disagree strongly enough to trigger the macro cap, a confirmed
BULL/BEARcan no longer be held. - Price regime failure — price loses the buffered slow-SMA regime gate.
BULL+ RSI >--rsi-extreme->OVERBOUGHTBEAR+ RSI <100 - --rsi-extreme->OVERSOLD
BULL+ RSI below the bearish zone and not rising ->BULL_WEAKBEAR+ RSI above the bullish zone and not falling ->BEAR_WEAK
The trend filter suppresses counter-trend signals when the fast MA (fastSMA if set, otherwise slow SMA) is clearly pointing the other way.
Flags
| Flag | Default | Meaning |
|---|---|---|
--trend-filter |
off | Enable trend direction filter |
--trend-filter-min-bars N |
3 | Fast MA trend must persist this many bars before the filter applies |
When fastSMA is present, two additional checks run inside the trend filter:
- Macro disagree cap — fastSMA and slow SMA point in opposite directions → full
BULL/BEARcapped toBULL_WEAK/BEAR_WEAK. - Fast-SMA commitment —
BULLrequires price above fastSMA for ≥ N bars;BEARrequires price below fastSMA for ≥ N bars. Failing this downgrades toBULL_WEAK/BEAR_WEAK.
When the trend filter suppresses a directional candidate to NEUTRAL, the momentum gate can restore it as weak if MACD and RSI both support the reversal for enough bars.
Flags
| Flag | Default | Meaning |
|---|---|---|
--momentum-gate |
off | Enable recovery gate |
--momentum-gate-bars N |
3 | Bars of sustained divergence required |
--momentum-gate-rsi-zone F |
35 | RSI threshold for the divergence check |
The gate is only checked after a directional state was suppressed by the primary trend filter. It does not create weak signals from an already-neutral MACD/RSI reading.
Any directional state (BULL, BULL_WEAK, BEAR, BEAR_WEAK) is suppressed if price has not cleared the slow SMA by a small buffer.
Flags
| Flag | Default | Meaning |
|---|---|---|
--price-regime-buffer-pct N |
0.35 | Required clearance from the slow SMA, in percent |
--no-price-regime-gate |
off | Disable the gate |
This is the trap filter that removes shallow bull/bear crosses from the chart.
The same gate is also treated as a hard invalidation for hysteresis. A confirmed BULL/BEAR is dropped immediately when the buffered slow-SMA regime is lost.
Inside the trend filter, the MACD line itself must agree with the regime:
BULLneeds MACD line > 0BEARneeds MACD line < 0
There is one extra bearish downgrade:
BEAR+ MACD histogram > 0 ->BEAR_WEAK
The final hard gate suppresses any remaining directional state while the MACD line is still too close to the wrong side of zero.
The threshold is not pure zero. It reuses --macd-min-hist as a small regime buffer:
BULL/BULL_WEAKrequire MACD line >=macd-min-histBEAR/BEAR_WEAKrequire MACD line <=-macd-min-hist
That means stale bullish or bearish holds are cleared immediately when the regime is invalidated.
The analyzer also exposes a derived entryBias classification for downstream execution logic and chart overlays.
Possible values:
NONEEARLY_LONGCONFIRM_LONGEARLY_SHORTCONFIRM_SHORT
Boolean helpers are emitted alongside it:
isBullWeakEntryisBullConfirmationisBearWeakEntryisBearConfirmation
These fields are computed from the final post-hysteresis interpretation, not from raw MACD/RSI candidates.
They are additionally gated by MA alignment:
- long entry hints require slow SMA
UPand fast SMAUP - short entry hints require slow SMA
DOWNand fast SMADOWN
NEUTRAL -> BULL_WEAK=>EARLY_LONGBULL_WEAK -> BULL=>CONFIRM_LONG
NEUTRAL -> BEAR_WEAK=>EARLY_SHORTBEAR_WEAK -> BEAR=>CONFIRM_SHORT
If a weak setup fails back to NEUTRAL or the signal flips to the opposite side, the setup state is cleared.
|hist| <= macd-min-hist -> NEUTRAL
BULL candidate:
RSI > extreme -> OVERBOUGHT
RSI weakens bullishly -> BULL_WEAK
MACD line regime disagrees -> BULL_WEAK
trend filter rejects (fastSMA DOWN) -> NEUTRAL
macro disagree cap (fastSMA≠SMA) -> BULL_WEAK
Fast-SMA commitment: price below fastSMA < N bars-> BULL_WEAK
momentum gate restores -> BULL_WEAK
price regime gate rejects -> NEUTRAL
post-filter trap suppression -> NEUTRAL
Fast-SMA commitment not met -> resets confirmation counter
confirmed and held -> BULL
BEAR candidate:
RSI < 100-extreme -> OVERSOLD
RSI weakens bearishly -> BEAR_WEAK
MACD line regime disagrees -> BEAR_WEAK
trend filter rejects (fastSMA UP) -> NEUTRAL
macro disagree cap (fastSMA≠SMA) -> BEAR_WEAK
Fast-SMA commitment: price above fastSMA < N bars-> BEAR_WEAK
momentum gate restores -> BEAR_WEAK
price regime gate rejects -> NEUTRAL
post-filter trap suppression -> NEUTRAL
Fast-SMA commitment not met -> resets confirmation counter
confirmed and held -> BEAR
Start with the base indicator set below. These are the parameters that define the signal model itself. The remaining flags are optional gates or advanced defaults that only need adjustment when you want to change how strict the signal is.
| Flag | Default | Purpose |
|---|---|---|
--sma N |
500 | Slow macro regime anchor |
--macd-fast N |
12 | MACD fast EMA period |
--macd-slow N |
26 | MACD slow EMA period |
--macd-signal N |
9 | MACD signal EMA period |
--macd-min-hist F |
0.02 | Minimum histogram magnitude for direction |
--rsi N |
14 | RSI period |
| Flag | Default | Purpose |
|---|---|---|
--fast-sma N |
off | Short-term direction source and fast-SMA commitment gate |
--trend-filter |
off | Enables counter-trend suppression |
--fast-sma-commitment-bars N |
2 | Requires price to stay beyond fastSMA before confirming |
--price-regime-buffer-pct N |
0.35 | Requires price clearance from slow SMA |
| Flag | Default | Description |
|---|---|---|
--confirm N |
3 | Bars required for trend confirmation |
--interp-confirm N |
3 | Confirmation bars for BULL/BEAR |
--interp-hold N |
3 | Hysteresis bars for downgrades |
| Flag | Default | Description |
|---|---|---|
--trend-filter-min-bars N |
3 | SMA trend persistence before filtering |
--momentum-gate |
off | Enable MACD+RSI recovery gate |
--momentum-gate-bars N |
3 | Momentum gate persistence |
--momentum-gate-rsi-zone F |
35 | RSI divergence threshold |
--no-price-regime-gate |
off | Disable slow-SMA regime gate |
| Flag | Default | Description |
|---|---|---|
--source |
market_adapter | Data source |
--file PATH |
— | JSON candle input |
--bot-key KEY |
— | Market adapter bot key used to load market_adapter/state/market_adapter_centers.json |
| Flag | Default | Description |
|---|---|---|
--chart FILE |
analysis/charts/derivative_chart.html | HTML output path |
node dist/analysis/analyze_derivatives.js \
--source json \
--file market_adapter/data/lp/<pair>/lp_pool_<id>_<interval>.json \
--sma 500 --fast-sma 100 \
--macd-fast 48 --macd-slow 104 --macd-signal 36 --macd-min-hist 0.02 \
--rsi 96 --rsi-extreme 90 --rsi-zone 10 \
--interp-confirm 3 --interp-hold 3 \
--trend-filter --trend-filter-min-bars 3If you want fewer shallow traps, keep the price regime gate enabled. If you want to
see every MACD/RSI turn regardless of slow-SMA clearance, disable it with
--no-price-regime-gate.