@pgnio/helios-mcp 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -2
- package/dist/chunk-EIAUO3XE.mjs +2955 -0
- package/dist/chunk-NCF7ASJB.mjs +2986 -0
- package/dist/chunk-NWGWXYTS.mjs +2964 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2968 -0
- package/dist/cli.mjs +24 -0
- package/dist/index.d.mts +2138 -0
- package/dist/index.d.ts +2138 -0
- package/dist/index.js +3043 -0
- package/dist/index.mjs +52 -0
- package/docs/ai-agent-indicators/00_index.txt +210 -0
- package/docs/ai-agent-indicators/activity_ratio.txt +166 -0
- package/docs/ai-agent-indicators/activity_zscore.txt +166 -0
- package/docs/ai-agent-indicators/bayesian_overbought.txt +134 -0
- package/docs/ai-agent-indicators/directional_efficiency.txt +134 -0
- package/docs/ai-agent-indicators/hfi.txt +172 -0
- package/docs/ai-agent-indicators/hfi_weights.txt +124 -0
- package/docs/ai-agent-indicators/hmi.txt +305 -0
- package/docs/ai-agent-indicators/hmi_velocity.txt +155 -0
- package/docs/ai-agent-indicators/hurst_exponent.txt +136 -0
- package/docs/ai-agent-indicators/macd_divergence.txt +133 -0
- package/docs/ai-agent-indicators/macd_histogram.txt +145 -0
- package/docs/ai-agent-indicators/macd_signal.txt +119 -0
- package/docs/ai-agent-indicators/market_structure.txt +201 -0
- package/docs/ai-agent-indicators/poc.txt +131 -0
- package/docs/ai-agent-indicators/poc_distance.txt +129 -0
- package/docs/ai-agent-indicators/regime.txt +225 -0
- package/docs/ai-agent-indicators/rsi_divergence.txt +145 -0
- package/docs/ai-agent-indicators/squeeze_duration.txt +115 -0
- package/docs/ai-agent-indicators/squeeze_energy.txt +128 -0
- package/docs/ai-agent-indicators/support_resistance.txt +169 -0
- package/docs/ai-agent-indicators/tf_alignment.txt +165 -0
- package/docs/ai-agent-indicators/trend_interpretation.txt +98 -0
- package/docs/ai-agent-indicators/trend_strength.txt +134 -0
- package/docs/ai-agent-indicators/value_area_position.txt +142 -0
- package/docs/ai-agent-indicators/volatility_clustering.txt +160 -0
- package/docs/ai-agent-indicators/volatility_squeeze.txt +169 -0
- package/docs/ai-agent-indicators/volume_change_point.txt +151 -0
- package/docs/ai-agent-indicators/vwap.txt +133 -0
- package/docs/ai-agent-indicators/vwap_zscore.txt +154 -0
- package/docs/ai-agent-indicators/weighted_rsi.txt +148 -0
- package/docs/ai-agent-mcp/00_index.txt +110 -0
- package/docs/ai-agent-mcp/01_auth/00_overview.txt +51 -0
- package/docs/ai-agent-mcp/01_auth/01_tools.txt +94 -0
- package/docs/ai-agent-mcp/01_auth/02_data_contracts.txt +38 -0
- package/docs/ai-agent-mcp/01_auth/03_decision_rules.txt +25 -0
- package/docs/ai-agent-mcp/01_auth/04_failures_and_recovery.txt +46 -0
- package/docs/ai-agent-mcp/02_account/00_overview.txt +29 -0
- package/docs/ai-agent-mcp/02_account/01_tools.txt +67 -0
- package/docs/ai-agent-mcp/02_account/02_data_contracts.txt +34 -0
- package/docs/ai-agent-mcp/02_account/03_decision_rules.txt +17 -0
- package/docs/ai-agent-mcp/02_account/04_failures_and_recovery.txt +17 -0
- package/docs/ai-agent-mcp/03_market/00_overview.txt +27 -0
- package/docs/ai-agent-mcp/03_market/01_tools.txt +102 -0
- package/docs/ai-agent-mcp/03_market/02_data_contracts.txt +39 -0
- package/docs/ai-agent-mcp/03_market/03_decision_rules.txt +22 -0
- package/docs/ai-agent-mcp/03_market/04_failures_and_recovery.txt +18 -0
- package/docs/ai-agent-mcp/04_trading/00_overview.txt +25 -0
- package/docs/ai-agent-mcp/04_trading/01_tools.txt +123 -0
- package/docs/ai-agent-mcp/04_trading/02_data_contracts.txt +42 -0
- package/docs/ai-agent-mcp/04_trading/03_decision_rules.txt +30 -0
- package/docs/ai-agent-mcp/04_trading/04_failures_and_recovery.txt +25 -0
- package/docs/ai-agent-mcp/05_ledger/00_overview.txt +31 -0
- package/docs/ai-agent-mcp/05_ledger/01_tools.txt +80 -0
- package/docs/ai-agent-mcp/05_ledger/02_data_contracts.txt +46 -0
- package/docs/ai-agent-mcp/05_ledger/03_decision_rules.txt +44 -0
- package/docs/ai-agent-mcp/05_ledger/04_failures_and_recovery.txt +24 -0
- package/package.json +66 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
INDICATOR: MACD_DIVERGENCE — MACD HISTOGRAM DIVERGENCE
|
|
3
|
+
================================================================================
|
|
4
|
+
id: macd_divergence
|
|
5
|
+
data_field: indicators.macd_divergence
|
|
6
|
+
type: CATEGORICAL
|
|
7
|
+
values: BULLISH | BEARISH | "" (empty string = no divergence)
|
|
8
|
+
update_rate: per_tick
|
|
9
|
+
latency_profile: LAGGING (requires minimum 2 peaks/troughs to be detected)
|
|
10
|
+
|
|
11
|
+
--------------------------------------------------------------------------------
|
|
12
|
+
CONSTRUCT
|
|
13
|
+
--------------------------------------------------------------------------------
|
|
14
|
+
macd_divergence detects classic price-MACD histogram divergence by comparing
|
|
15
|
+
rolling peak and trough values in the MACD histogram against corresponding
|
|
16
|
+
price high/low levels.
|
|
17
|
+
|
|
18
|
+
Implementation:
|
|
19
|
+
MAX_PEAKS = 5 peak inputs, MAX_PEAKS = 5 trough inputs maintained as
|
|
20
|
+
rolling windows.
|
|
21
|
+
|
|
22
|
+
A histogram PEAK is recorded when histogram switches from positive to near-zero
|
|
23
|
+
or negative after a positive run. A histogram TROUGH is recorded when it
|
|
24
|
+
switches from negative to near-zero or positive after a negative run.
|
|
25
|
+
|
|
26
|
+
BEARISH DIVERGENCE (histogram bearish):
|
|
27
|
+
Requires >= 2 histogram peaks in rolling window.
|
|
28
|
+
price makes HIGHER HIGH (priceHigh[current] > priceHigh[prior])
|
|
29
|
+
AND histogram peak makes LOWER HIGH (histPeak[current] < histPeak[prior])
|
|
30
|
+
→ Price is rising but MACD histogram peaks are declining.
|
|
31
|
+
Upside price momentum is structurally weakening.
|
|
32
|
+
|
|
33
|
+
BULLISH DIVERGENCE (histogram bullish):
|
|
34
|
+
Requires >= 2 histogram troughs in rolling window.
|
|
35
|
+
price makes LOWER LOW (priceLow[current] < priceLow[prior])
|
|
36
|
+
AND histogram trough makes HIGHER LOW (histTrough[current] > histTrough[prior])
|
|
37
|
+
→ Price is dropping but MACD histogram troughs are becoming less negative.
|
|
38
|
+
Downside price momentum is structurally weakening.
|
|
39
|
+
|
|
40
|
+
"" (empty string): no divergence detected, or insufficient data for comparison.
|
|
41
|
+
|
|
42
|
+
--------------------------------------------------------------------------------
|
|
43
|
+
IMPORTANT DISTINCTION FROM RSI DIVERGENCE
|
|
44
|
+
--------------------------------------------------------------------------------
|
|
45
|
+
# macd_divergence is computed from PEAK/TROUGH comparison (swing analysis).
|
|
46
|
+
# rsi_divergence is computed from SLOPE comparison over 20-bar windows.
|
|
47
|
+
# These are independent computations using different methods.
|
|
48
|
+
# Agreement between both divergences is a materially stronger signal.
|
|
49
|
+
|
|
50
|
+
# macd_divergence uses LABELED peaks/troughs (requires swing reversal to record).
|
|
51
|
+
# It is typically LESS frequent than rsi_divergence but captures
|
|
52
|
+
# clearer structural commitments in momentum.
|
|
53
|
+
|
|
54
|
+
--------------------------------------------------------------------------------
|
|
55
|
+
STATE DEFINITIONS
|
|
56
|
+
--------------------------------------------------------------------------------
|
|
57
|
+
BULLISH
|
|
58
|
+
Price has made a lower low but the corresponding MACD histogram trough
|
|
59
|
+
is less negative than the prior one. Less selling pressure at a lower
|
|
60
|
+
price point — the downswing is losing force. Context for a return watch:
|
|
61
|
+
this does not indicate when or from where price will recover.
|
|
62
|
+
|
|
63
|
+
BEARISH
|
|
64
|
+
Price has made a higher high but the corresponding MACD histogram peak
|
|
65
|
+
is smaller than the prior one. Less buying pressure at a higher price
|
|
66
|
+
point — the upswing is losing force.
|
|
67
|
+
|
|
68
|
+
"" (empty string / no divergence)
|
|
69
|
+
Neither condition met, or there are insufficient peaks/troughs in the
|
|
70
|
+
rolling window to perform a comparison. NONE is the expected state during
|
|
71
|
+
straight-line trending periods.
|
|
72
|
+
|
|
73
|
+
--------------------------------------------------------------------------------
|
|
74
|
+
INDICATOR RELATIONSHIPS
|
|
75
|
+
--------------------------------------------------------------------------------
|
|
76
|
+
indicators.macd_histogram | REQUIRED_COMPANION
|
|
77
|
+
macd_divergence is computed from macd_histogram peak/trough tracking.
|
|
78
|
+
The current histogram sign provides context: bearish divergence forming
|
|
79
|
+
while histogram is still positive is an early warning; forming after
|
|
80
|
+
a cross makes it a later-stage confirmation.
|
|
81
|
+
|
|
82
|
+
indicators.macd_signal | CONTEXT
|
|
83
|
+
IF macd_divergence = BEARISH AND macd_signal later transitions to BEARISH_CROSS
|
|
84
|
+
→ Divergence was a leading warning; cross is lagging confirmation.
|
|
85
|
+
Combination increases conviction for downside momentum shift.
|
|
86
|
+
|
|
87
|
+
indicators.rsi_divergence | CROSS_VALIDATE
|
|
88
|
+
Independent divergence detection method. Agreement between both
|
|
89
|
+
(macd_divergence = BEARISH AND rsi_divergence = BEARISH_DIVERGENCE)
|
|
90
|
+
materially strengthens the signal. Disagreement reduces confidence.
|
|
91
|
+
|
|
92
|
+
indicators.bayesian_overbought | CONTEXT
|
|
93
|
+
IF macd_divergence = BEARISH AND bayesian_overbought > 0.85
|
|
94
|
+
→ Both momentum and RSI metrics at historically extreme levels while
|
|
95
|
+
divergence is forming. Compound fatigue signal.
|
|
96
|
+
|
|
97
|
+
indicators.regime | CONTEXT
|
|
98
|
+
Divergence is most predictive when regime is EXHAUST_UP or EXHAUST_DN.
|
|
99
|
+
Divergence in CASCADE conditions often fails (cascades can sustain
|
|
100
|
+
diminishing histogram peaks while price keeps making higher highs).
|
|
101
|
+
|
|
102
|
+
--------------------------------------------------------------------------------
|
|
103
|
+
DEPENDENCY ORDER
|
|
104
|
+
--------------------------------------------------------------------------------
|
|
105
|
+
1 Regime: CASCADE/PARABOLIC conditions have high false-positive rate for divergence.
|
|
106
|
+
2 Read divergence state.
|
|
107
|
+
3 If not empty: cross-validate with rsi_divergence.
|
|
108
|
+
4 Track whether macd_signal subsequently confirms with a cross.
|
|
109
|
+
|
|
110
|
+
--------------------------------------------------------------------------------
|
|
111
|
+
INVALIDATION CONDITIONS
|
|
112
|
+
--------------------------------------------------------------------------------
|
|
113
|
+
IF fewer than 2 recorded peaks (for BEARISH) or 2 recorded troughs (for BULLISH)
|
|
114
|
+
→ Empty string is expected. Do not interpret as "no divergence" — it may
|
|
115
|
+
be insufficient data. Check tick age since start-up.
|
|
116
|
+
|
|
117
|
+
IF regime = CASCADE or PARABOLIC
|
|
118
|
+
→ Divergence in extreme trending conditions has high false positive rate.
|
|
119
|
+
Discount macd_divergence during these regimes.
|
|
120
|
+
|
|
121
|
+
--------------------------------------------------------------------------------
|
|
122
|
+
ANTI-PATTERNS — DETECTABLE MISUSE CONDITIONS
|
|
123
|
+
--------------------------------------------------------------------------------
|
|
124
|
+
IF BULLISH macd_divergence is used as a stop-exit point
|
|
125
|
+
→ INCORRECT SCOPE. Divergence indicates weakening momentum; it does NOT
|
|
126
|
+
indicate a floor. Price can continue making lower lows while histogram
|
|
127
|
+
troughs improve. Divergence can persist across many ticks.
|
|
128
|
+
|
|
129
|
+
IF divergence is expected to appear immediately after a pivot
|
|
130
|
+
→ STRUCTURAL CONSTRAINT. macd_divergence requires at least 2 full
|
|
131
|
+
peak/trough cycle completions. It will not appear on the first
|
|
132
|
+
swing — it requires a COMPARISON between at least two swings.
|
|
133
|
+
Newly formed momentum shifts won't have divergence yet.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
INDICATOR: MACD_HISTOGRAM — MACD HISTOGRAM (NORMALIZED)
|
|
3
|
+
================================================================================
|
|
4
|
+
id: macd_histogram
|
|
5
|
+
data_field: indicators.macd_histogram
|
|
6
|
+
type: NUMERIC
|
|
7
|
+
range: Unbounded (normalized by price; practically ±5 for most assets)
|
|
8
|
+
precision: 4 decimal places
|
|
9
|
+
update_rate: per_tick
|
|
10
|
+
latency_profile: LAGGING (EMA-based, inherits smoothing from 26-period slow EMA)
|
|
11
|
+
|
|
12
|
+
--------------------------------------------------------------------------------
|
|
13
|
+
CONSTRUCT
|
|
14
|
+
--------------------------------------------------------------------------------
|
|
15
|
+
Standard MACD(12, 26, 9) computed on the most recent close prices.
|
|
16
|
+
|
|
17
|
+
EMA parameters:
|
|
18
|
+
alphaFast = 2 / (12 + 1) = 0.1538
|
|
19
|
+
alphaSlow = 2 / (26 + 1) = 0.0741
|
|
20
|
+
alphaSignal = 2 / (9 + 1) = 0.2000
|
|
21
|
+
|
|
22
|
+
emaFast = EMA(closes, alphaFast)
|
|
23
|
+
emaSlow = EMA(closes, alphaSlow)
|
|
24
|
+
macdLine = emaFast - emaSlow
|
|
25
|
+
signalEMA = EMA(macdLine, alphaSignal)
|
|
26
|
+
histogram = macdLine - signalEMA
|
|
27
|
+
|
|
28
|
+
Normalization for cross-asset comparison:
|
|
29
|
+
histogramNorm = histogram / lastClose × 100
|
|
30
|
+
|
|
31
|
+
The normalized histogram (histogramNorm) is what is stored in indicators.macd_histogram.
|
|
32
|
+
This allows comparison of MACD strength across assets with different price levels.
|
|
33
|
+
|
|
34
|
+
Histogram behavior:
|
|
35
|
+
Positive value → macdLine above signalEMA → bullish momentum
|
|
36
|
+
Negative value → macdLine below signalEMA → bearish momentum
|
|
37
|
+
Growing positive → momentum accelerating upward
|
|
38
|
+
Shrinking positive → momentum decelerating but still bullish
|
|
39
|
+
Zero crossing (- to +) → triggers BULLISH_CROSS in macd_signal
|
|
40
|
+
Zero crossing (+ to -) → triggers BEARISH_CROSS in macd_signal
|
|
41
|
+
|
|
42
|
+
--------------------------------------------------------------------------------
|
|
43
|
+
RANGE INTERPRETATION
|
|
44
|
+
--------------------------------------------------------------------------------
|
|
45
|
+
# Ranges are relative — values depend on asset volatility and regime.
|
|
46
|
+
# Use magnitude comparisons to recent history rather than absolute thresholds.
|
|
47
|
+
|
|
48
|
+
value > 0 AND growing (vs prior tick reading)
|
|
49
|
+
Bullish momentum accelerating. macdLine is above signal and the gap is
|
|
50
|
+
widening. Short-term EMA is separating further from slow EMA. Associated
|
|
51
|
+
with early-to-mid breakout or trend conditions.
|
|
52
|
+
|
|
53
|
+
value > 0 AND shrinking (vs prior tick reading)
|
|
54
|
+
Bullish momentum decelerating. The gap between macdLine and signal is
|
|
55
|
+
narrowing. MACD is still bullish but fading. Associated with later-stage
|
|
56
|
+
trends or pullback conditions within a bullish structure.
|
|
57
|
+
|
|
58
|
+
value ≈ 0 (near zero from above, crossing down)
|
|
59
|
+
Bearish cross imminent or just occurred. Triggers BEARISH_CROSS in
|
|
60
|
+
macd_signal. Momentum has shifted from bullish to neutral/bearish.
|
|
61
|
+
|
|
62
|
+
value < 0 AND growing in magnitude (more negative)
|
|
63
|
+
Bearish momentum accelerating. The downside MACD gap is widening.
|
|
64
|
+
|
|
65
|
+
value < 0 AND shrinking in magnitude (less negative)
|
|
66
|
+
Bearish momentum decelerating. Downside fading. May precede a bullish
|
|
67
|
+
cross if combined with RSI divergence or HMI recovery.
|
|
68
|
+
|
|
69
|
+
value ≈ 0 (near zero from below, crossing up)
|
|
70
|
+
Bullish cross imminent or just occurred. Triggers BULLISH_CROSS.
|
|
71
|
+
|
|
72
|
+
--------------------------------------------------------------------------------
|
|
73
|
+
TRAJECTORY — HOW TO DETECT GROWING vs SHRINKING
|
|
74
|
+
--------------------------------------------------------------------------------
|
|
75
|
+
# macd_histogram does not have a built-in velocity field.
|
|
76
|
+
# Compute trajectory from two consecutive readings:
|
|
77
|
+
IF macd_histogram[current] > macd_histogram[prior] → growing (more positive)
|
|
78
|
+
IF macd_histogram[current] < macd_histogram[prior] → shrinking (less positive)
|
|
79
|
+
#
|
|
80
|
+
# Or use macd_signal state (BULLISH_CROSS, BEARISH_CROSS) as proxy for direction.
|
|
81
|
+
|
|
82
|
+
--------------------------------------------------------------------------------
|
|
83
|
+
INDICATOR RELATIONSHIPS
|
|
84
|
+
--------------------------------------------------------------------------------
|
|
85
|
+
indicators.macd_signal | REQUIRED_COMPANION
|
|
86
|
+
macd_signal is derived from this same MACD computation and encodes the
|
|
87
|
+
most recent directional state (CROSS events). Check macd_signal
|
|
88
|
+
to know whether a zero crossing just occurred.
|
|
89
|
+
|
|
90
|
+
indicators.macd_divergence | COMPANION
|
|
91
|
+
macd_divergence monitors peaks and troughs in the histogram for
|
|
92
|
+
price-MACD divergence patterns. See macd_divergence.txt.
|
|
93
|
+
|
|
94
|
+
indicators.hmi | CROSS_VALIDATE
|
|
95
|
+
HMI and MACD both capture momentum but via different computations
|
|
96
|
+
(Kalman/Bayesian vs EMA-based). They should generally agree on direction.
|
|
97
|
+
IF hmi >= 50 AND macd_histogram < 0: conflicting signals. One is lagging.
|
|
98
|
+
IF hmi < -30 AND macd_histogram > 0: MACD recently crossed positive but
|
|
99
|
+
medium-TF alignment (captured by hmi) remains negative. Potential
|
|
100
|
+
false MACD positive in a bearish broader context.
|
|
101
|
+
|
|
102
|
+
indicators.weighted_rsi | CONTEXT
|
|
103
|
+
MACD captures trend momentum; RSI captures oscillation/overextension.
|
|
104
|
+
Both can diverge from price motion and both reward that divergence
|
|
105
|
+
as a potential signal. Cross-referencing both divergences strengthens
|
|
106
|
+
the combined signal.
|
|
107
|
+
|
|
108
|
+
indicators.regime | GATE
|
|
109
|
+
IF regime = CHOP: MACD produces frequent low-quality crosses. Discard
|
|
110
|
+
MACD signals in CHOP until regime confirms directional state.
|
|
111
|
+
|
|
112
|
+
--------------------------------------------------------------------------------
|
|
113
|
+
DEPENDENCY ORDER
|
|
114
|
+
--------------------------------------------------------------------------------
|
|
115
|
+
1 Regime gate: ignore MACD crosses in CHOP.
|
|
116
|
+
2 Read value sign (positive vs negative).
|
|
117
|
+
3 Read trend of value (growing vs shrinking vs at zero).
|
|
118
|
+
4 Read macd_signal for cross event state.
|
|
119
|
+
5 Check macd_divergence for peak-based divergence.
|
|
120
|
+
|
|
121
|
+
--------------------------------------------------------------------------------
|
|
122
|
+
INVALIDATION CONDITIONS
|
|
123
|
+
--------------------------------------------------------------------------------
|
|
124
|
+
IF regime = CHOP or CONSOL
|
|
125
|
+
→ MACD crosses in non-directional conditions are statistically unreliable.
|
|
126
|
+
|
|
127
|
+
IF fewer than 26 close prices on the slow EMA
|
|
128
|
+
→ Initialization period. EMA output is heavily biased. Treat as warm-up.
|
|
129
|
+
|
|
130
|
+
--------------------------------------------------------------------------------
|
|
131
|
+
ANTI-PATTERNS — DETECTABLE MISUSE CONDITIONS
|
|
132
|
+
--------------------------------------------------------------------------------
|
|
133
|
+
IF BULLISH_CROSS is used as a standalone entry signal
|
|
134
|
+
→ INCOMPLETE. A cross merely signals that short-term EMA crossed above
|
|
135
|
+
signal EMA. In CHOP regimes this happens repeatedly with no follow-through.
|
|
136
|
+
Require: regime NOT in CHOP + hmi direction confirmation before acting.
|
|
137
|
+
|
|
138
|
+
IF histogram magnitude is compared across different assets
|
|
139
|
+
→ CORRECT USE requires normalized form (histogramNorm). Confirm you are
|
|
140
|
+
reading indicators.macd_histogram and not an internal un-normalized value.
|
|
141
|
+
|
|
142
|
+
IF lagging is not accounted for after fast moves
|
|
143
|
+
→ The slow EMA (26-period, alpha=0.074) takes many ticks to respond
|
|
144
|
+
to sudden moves. After a sharp impulse, MACD may not cross for 5-10+ ticks.
|
|
145
|
+
Regime and hmi detect momentum faster; MACD confirms after the fact.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
INDICATOR: MACD_SIGNAL — MACD SIGNAL STATE
|
|
3
|
+
================================================================================
|
|
4
|
+
id: macd_signal
|
|
5
|
+
data_field: indicators.macd_signal
|
|
6
|
+
type: CATEGORICAL
|
|
7
|
+
values: BULLISH_CROSS | BEARISH_CROSS | BULLISH | BEARISH | NEUTRAL
|
|
8
|
+
update_rate: per_tick
|
|
9
|
+
latency_profile: LAGGING (derived from EMA-based MACD system)
|
|
10
|
+
|
|
11
|
+
--------------------------------------------------------------------------------
|
|
12
|
+
CONSTRUCT
|
|
13
|
+
--------------------------------------------------------------------------------
|
|
14
|
+
macd_signal encodes the directional state of the MACD histogram computation.
|
|
15
|
+
It is derived from the same MACD(12, 26, 9) system as indicators.macd_histogram.
|
|
16
|
+
|
|
17
|
+
State rules:
|
|
18
|
+
BULLISH_CROSS:
|
|
19
|
+
histogram crossed from <= 0 to > 0 this tick (or very recently).
|
|
20
|
+
Marks the end of a bearish MACD phase and start of a bullish one.
|
|
21
|
+
This is the signal that would trigger a traditional MACD buy signal.
|
|
22
|
+
|
|
23
|
+
BEARISH_CROSS:
|
|
24
|
+
histogram crossed from >= 0 to < 0 this tick.
|
|
25
|
+
Marks the end of a bullish MACD phase and start of a bearish one.
|
|
26
|
+
|
|
27
|
+
BULLISH:
|
|
28
|
+
histogram > 0 but no cross occurred this tick.
|
|
29
|
+
Continuation of prior bullish MACD phase. macdLine still above signal.
|
|
30
|
+
|
|
31
|
+
BEARISH:
|
|
32
|
+
histogram < 0 but no cross occurred this tick.
|
|
33
|
+
Continuation of prior bearish MACD phase. macdLine still below signal.
|
|
34
|
+
|
|
35
|
+
NEUTRAL:
|
|
36
|
+
histogram ≈ 0. At/near the zero line without a detected cross, or
|
|
37
|
+
during EMA initialization period.
|
|
38
|
+
|
|
39
|
+
--------------------------------------------------------------------------------
|
|
40
|
+
STATE DEFINITIONS
|
|
41
|
+
--------------------------------------------------------------------------------
|
|
42
|
+
BULLISH_CROSS
|
|
43
|
+
Most significant upside signal from MACD. Momentum has just shifted from
|
|
44
|
+
bearish EMA structure to bullish. Highest value when accompanied by an
|
|
45
|
+
expanding histogram (histogram growing positive after the cross).
|
|
46
|
+
Context required: Is this a trend resumption or a countertrend bounce?
|
|
47
|
+
Check hmi direction to distinguish.
|
|
48
|
+
|
|
49
|
+
BEARISH_CROSS
|
|
50
|
+
Most significant downside signal from MACD. Mirror of BULLISH_CROSS.
|
|
51
|
+
Most reliable when preceded by a period of histogram shrinkage (momentum
|
|
52
|
+
was already decelerating before the cross occurred).
|
|
53
|
+
|
|
54
|
+
BULLISH
|
|
55
|
+
Bullish phase in progress. The MACD histogram has been positive for
|
|
56
|
+
some duration. Check histogram magnitude and trend to assess vigor.
|
|
57
|
+
A shrinking positive histogram in BULLISH state precedes BEARISH_CROSS.
|
|
58
|
+
|
|
59
|
+
BEARISH
|
|
60
|
+
Mirror of BULLISH. Downside MACD phase in progress.
|
|
61
|
+
|
|
62
|
+
NEUTRAL
|
|
63
|
+
At the MACD zero line. Either a cross is about to occur, or histogram is
|
|
64
|
+
bouncing near zero without committing to either direction (common in CHOP).
|
|
65
|
+
|
|
66
|
+
--------------------------------------------------------------------------------
|
|
67
|
+
INDICATOR RELATIONSHIPS
|
|
68
|
+
--------------------------------------------------------------------------------
|
|
69
|
+
indicators.macd_histogram | REQUIRED_COMPANION
|
|
70
|
+
macd_signal encodes the state; macd_histogram provides the magnitude.
|
|
71
|
+
Use macd_signal to identify cross events, then use macd_histogram to
|
|
72
|
+
assess whether the cross has building momentum behind it.
|
|
73
|
+
|
|
74
|
+
indicators.macd_divergence | CONTEXT
|
|
75
|
+
Prior divergence that resolves into a cross is a higher-quality signal.
|
|
76
|
+
IF macd_divergence = BULLISH AND then macd_signal transitions to BULLISH_CROSS
|
|
77
|
+
→ Divergence-confirmed cross. Stronger signal.
|
|
78
|
+
|
|
79
|
+
indicators.hmi | CROSS_VALIDATE
|
|
80
|
+
IF macd_signal = BULLISH_CROSS AND hmi < -40
|
|
81
|
+
→ MACD momentum cross but broader timeframe alignment is still very
|
|
82
|
+
bearish. This may be a countertrend recovery, not a trend reversal.
|
|
83
|
+
IF macd_signal = BULLISH AND hmi >= 60
|
|
84
|
+
→ Both indicators in sustained bullish agreement. Trend continuation
|
|
85
|
+
is the dominant condition.
|
|
86
|
+
|
|
87
|
+
indicators.regime | GATE
|
|
88
|
+
IF regime = CHOP: all MACD signal states are unreliable.
|
|
89
|
+
Do not use BULLISH_CROSS or BEARISH_CROSS in CHOP. They will fire
|
|
90
|
+
frequently with no follow-through.
|
|
91
|
+
|
|
92
|
+
--------------------------------------------------------------------------------
|
|
93
|
+
DEPENDENCY ORDER
|
|
94
|
+
--------------------------------------------------------------------------------
|
|
95
|
+
1 Regime gate: if CHOP, all MACD signal states are unreliable.
|
|
96
|
+
2 Read state.
|
|
97
|
+
3 For BULLISH_CROSS or BEARISH_CROSS: cross-validate with hmi direction and regime context.
|
|
98
|
+
4 For BULLISH or BEARISH: read histogram magnitude and trend.
|
|
99
|
+
|
|
100
|
+
--------------------------------------------------------------------------------
|
|
101
|
+
INVALIDATION CONDITIONS
|
|
102
|
+
--------------------------------------------------------------------------------
|
|
103
|
+
IF regime IN [CHOP, CONSOL, RANGING]: discard signal.
|
|
104
|
+
|
|
105
|
+
IF initialization period (< 26 closes seen): NEUTRAL is expected.
|
|
106
|
+
Treat NEUTRAL in first 50 ticks as warm-up noise.
|
|
107
|
+
|
|
108
|
+
--------------------------------------------------------------------------------
|
|
109
|
+
ANTI-PATTERNS — DETECTABLE MISUSE CONDITIONS
|
|
110
|
+
--------------------------------------------------------------------------------
|
|
111
|
+
IF every BULLISH_CROSS triggers a trade
|
|
112
|
+
→ OVER-FITTING TO SIGNAL. In non-trending or choppy conditions, MACD
|
|
113
|
+
crosses are false signals. Apply context filter (regime + hmi) first.
|
|
114
|
+
|
|
115
|
+
IF BULLISH state is treated as "buy" and BEARISH as "sell"
|
|
116
|
+
→ INCORRECT SCOPE. BULLISH/BEARISH describe the MACD phase (histogram
|
|
117
|
+
above/below zero) — not market direction readiness. A BEARISH phase
|
|
118
|
+
with a shrinking histogram in a trending market is a normal pause,
|
|
119
|
+
not a sell signal.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
INDICATOR: MARKET_STRUCTURE — MARKET STRUCTURE STATE
|
|
3
|
+
================================================================================
|
|
4
|
+
id: market_structure
|
|
5
|
+
data_field: indicators.market_structure
|
|
6
|
+
type: CATEGORICAL (with confidence sub-field)
|
|
7
|
+
values: RANGING | CONSOL | BREAKING_UP | BREAKING_DOWN |
|
|
8
|
+
CONFIRMED_BREAK_UP | CONFIRMED_BREAK_DOWN |
|
|
9
|
+
TEST_RS | FAILED_BREAK
|
|
10
|
+
update_rate: per_tick (with HMM smoothing)
|
|
11
|
+
latency_profile: LAGGING (9-state HMM + ATR-based confirmation ticks)
|
|
12
|
+
|
|
13
|
+
ADDITIONAL SUB-FIELD:
|
|
14
|
+
indicators.market_structure.transitionConfidence
|
|
15
|
+
type: NUMERIC [0, 1]
|
|
16
|
+
The HMM posterior probability of the current state. Higher = more certain.
|
|
17
|
+
|
|
18
|
+
--------------------------------------------------------------------------------
|
|
19
|
+
CONSTRUCT
|
|
20
|
+
--------------------------------------------------------------------------------
|
|
21
|
+
market_structure classifies the current price action structure using a
|
|
22
|
+
9-state Hidden Markov Model (HMM) with ATR-relative transition logic.
|
|
23
|
+
|
|
24
|
+
INPUT SIGNALS:
|
|
25
|
+
- currentATR: 14-period ATR (Average True Range)
|
|
26
|
+
- baselineATR: longer-period ATR for compression comparison
|
|
27
|
+
- currentPrice: most recent close
|
|
28
|
+
- resistanceLevels / supportLevels: from support/resistance indicator
|
|
29
|
+
- momentum: avg(recent 3 closes) vs avg(prior 3 closes) / avg(prior 3)
|
|
30
|
+
- Proximity threshold: 0.5 × ATR for S/R level proximity testing
|
|
31
|
+
|
|
32
|
+
KEY COMPUTATIONAL RULES:
|
|
33
|
+
|
|
34
|
+
CONSOLIDATION DETECTION:
|
|
35
|
+
compression = currentATR / baselineATR
|
|
36
|
+
IF compression < CONSOLIDATION_THRESHOLD (0.30)
|
|
37
|
+
→ 30% ATR compression below baseline = structural consolidation
|
|
38
|
+
|
|
39
|
+
BREAKOUT CONFIRMATION:
|
|
40
|
+
BREAKOUT_CONFIRM_TICKS = 3
|
|
41
|
+
Price must trade above a resistance level (or below support) for 3
|
|
42
|
+
consecutive ticks before transitioning from BREAKING to CONFIRMED_BREAK.
|
|
43
|
+
This prevents whipsaw false breakouts.
|
|
44
|
+
|
|
45
|
+
HMM SMOOTHING:
|
|
46
|
+
9×9 transition matrix with emission probability 0.75 (self-stay) /
|
|
47
|
+
0.03125 (any other state). The HMM smooths noisy state transitions —
|
|
48
|
+
brief 1-2 tick excursions may not change the published state.
|
|
49
|
+
transitionConfidence gives the posterior probability of the current
|
|
50
|
+
HMM state assignment.
|
|
51
|
+
|
|
52
|
+
--------------------------------------------------------------------------------
|
|
53
|
+
STATE DEFINITIONS
|
|
54
|
+
--------------------------------------------------------------------------------
|
|
55
|
+
RANGING
|
|
56
|
+
Price is moving within a defined range between support and resistance.
|
|
57
|
+
No breakout attempt currently in progress. The market has established
|
|
58
|
+
a recognizable trading range. Normal oscillation between S/R levels.
|
|
59
|
+
|
|
60
|
+
CONSOL
|
|
61
|
+
Volatility compression is active (currentATR < 30% of baselineATR).
|
|
62
|
+
Price is consolidating in a tighter-than-normal range. This is not
|
|
63
|
+
merely quiet trading — it is structurally compressed. See also
|
|
64
|
+
volatility_squeeze for the GARCH view of the same phenomenon.
|
|
65
|
+
|
|
66
|
+
BREAKING_UP
|
|
67
|
+
Price has moved above a resistance level but has NOT yet sustained
|
|
68
|
+
above it for 3 consecutive ticks. Unconfirmed upside breakout attempt.
|
|
69
|
+
High false-positive rate here — many BREAKING_UP states fail and
|
|
70
|
+
return to RANGING or FAILED_BREAK.
|
|
71
|
+
|
|
72
|
+
BREAKING_DOWN
|
|
73
|
+
Mirror of BREAKING_UP. Price has moved below support but < 3 ticks
|
|
74
|
+
of sustained closure. Unconfirmed downside breakout.
|
|
75
|
+
|
|
76
|
+
CONFIRMED_BREAK_UP
|
|
77
|
+
Price has traded above resistance for >= 3 consecutive ticks.
|
|
78
|
+
Prior resistance level now becomes potential support.
|
|
79
|
+
This state represents a confirmed upside structural change.
|
|
80
|
+
|
|
81
|
+
CONFIRMED_BREAK_DOWN
|
|
82
|
+
Mirror of CONFIRMED_BREAK_UP. >= 3 ticks below prior support.
|
|
83
|
+
|
|
84
|
+
TEST_RS
|
|
85
|
+
Price is within proximity (0.5 × ATR) of a support OR resistance
|
|
86
|
+
level but has not yet broken it. Testing the level — decision zone.
|
|
87
|
+
The next few ticks will determine RANGING continuation, BREAKING,
|
|
88
|
+
or bounce back into range.
|
|
89
|
+
|
|
90
|
+
FAILED_BREAK
|
|
91
|
+
Price moved above resistance or below support (BREAKING state) but
|
|
92
|
+
then reversed back into the prior range without achieving 3-tick
|
|
93
|
+
confirmation. Classic bull/bear trap pattern. The level held.
|
|
94
|
+
Associated with a return to RANGING or TEST_RS.
|
|
95
|
+
|
|
96
|
+
--------------------------------------------------------------------------------
|
|
97
|
+
STATE TRANSITIONS — COMMON SEQUENCES
|
|
98
|
+
--------------------------------------------------------------------------------
|
|
99
|
+
# Understanding likely next states from each current state:
|
|
100
|
+
|
|
101
|
+
CONSOL → BREAKING_UP or BREAKING_DOWN
|
|
102
|
+
Compression resolved with a directional break. The squeeze_energy at
|
|
103
|
+
the time of this transition indicates the force of pent-up energy behind it.
|
|
104
|
+
|
|
105
|
+
BREAKING_UP → CONFIRMED_BREAK_UP (3 ticks hold above resistance)
|
|
106
|
+
BREAKING_UP → FAILED_BREAK (reversal back into range)
|
|
107
|
+
|
|
108
|
+
CONFIRMED_BREAK_UP → RANGING (at new higher range)
|
|
109
|
+
Post-breakout consolidation at the new level.
|
|
110
|
+
|
|
111
|
+
TEST_RS → BREAKING_UP / BREAKING_DOWN / RANGING
|
|
112
|
+
Decision: break through, fail the test, or bounce off.
|
|
113
|
+
|
|
114
|
+
FAILED_BREAK → TEST_RS or RANGING
|
|
115
|
+
Level has been confirmed to hold. Price oscillates around it.
|
|
116
|
+
|
|
117
|
+
--------------------------------------------------------------------------------
|
|
118
|
+
INDICATOR RELATIONSHIPS
|
|
119
|
+
--------------------------------------------------------------------------------
|
|
120
|
+
indicators.volatility_squeeze | COMPANION
|
|
121
|
+
For CONSOL: cross-reference with volatility_squeeze < 0.6.
|
|
122
|
+
Both should agree when a genuine structural consolidation is present.
|
|
123
|
+
IF market_structure = CONSOL AND volatility_squeeze >= 0.8:
|
|
124
|
+
→ ATR says consolidated; GARCH says volatility is normal.
|
|
125
|
+
Potential disagreement — check timeframe alignment of each.
|
|
126
|
+
|
|
127
|
+
indicators.support / indicators.resistance | PREREQUISITE DATA
|
|
128
|
+
market_structure uses S/R levels to detect BREAKING and TEST_RS states.
|
|
129
|
+
The quality of S/R levels (bayesianStrength) directly affects whether
|
|
130
|
+
BREAKING_UP from a weak resistance is meaningful.
|
|
131
|
+
IF market_structure = CONFIRMED_BREAK_UP FROM a weak resistance level
|
|
132
|
+
(bayesianStrength < 0.4) → lower significance than breaking from STRONG S/R.
|
|
133
|
+
|
|
134
|
+
indicators.regime | CROSS_VALIDATE
|
|
135
|
+
CONFIRMED_BREAK_UP should co-occur with BREAKOUT or TREND_UP regime.
|
|
136
|
+
IF market_structure = CONFIRMED_BREAK_UP AND regime = CHOP
|
|
137
|
+
→ Conflict. One is stale. Check timestamps.
|
|
138
|
+
IF market_structure = CONSOL AND regime = CONSOL
|
|
139
|
+
→ Double confirmation of consolidation from two independent systems.
|
|
140
|
+
|
|
141
|
+
indicators.squeeze_energy | CONTEXT
|
|
142
|
+
The amount of squeeze_energy at the moment of structural breakout
|
|
143
|
+
amplifies expected move magnitude. Match timing of squeeze_energy release
|
|
144
|
+
with BREAKING state transitions.
|
|
145
|
+
|
|
146
|
+
indicators.hmi | CONTEXT
|
|
147
|
+
CONFIRMED_BREAK_UP should be accompanied by rising or already-elevated hmi.
|
|
148
|
+
IF market_structure = CONFIRMED_BREAK_UP AND hmi < 10
|
|
149
|
+
→ Structural break confirmed by price action but momentum stack not
|
|
150
|
+
yet significantly aligned. Partial breakout condition.
|
|
151
|
+
|
|
152
|
+
indicators.transitionConfidence | COMPANION
|
|
153
|
+
Read transitionConfidence when state is ambiguous.
|
|
154
|
+
IF state = TEST_RS AND transitionConfidence = 0.6
|
|
155
|
+
→ HMM is 60% confident in TEST_RS. 40% probability among other states.
|
|
156
|
+
Treat as moderate confidence — not a definitive read.
|
|
157
|
+
IF state = CONFIRMED_BREAK_UP AND transitionConfidence = 0.92
|
|
158
|
+
→ High HMM posterior. Very confident state assignment.
|
|
159
|
+
|
|
160
|
+
--------------------------------------------------------------------------------
|
|
161
|
+
DEPENDENCY ORDER
|
|
162
|
+
--------------------------------------------------------------------------------
|
|
163
|
+
1 Read market_structure state.
|
|
164
|
+
2 Read transitionConfidence; if < 0.65, treat state as lower certainty.
|
|
165
|
+
3 For BREAK states: check which S/R level was broken and its bayesianStrength.
|
|
166
|
+
4 For CONSOL: cross-reference with volatility_squeeze and squeeze_energy.
|
|
167
|
+
5 Cross-validate with regime for directional context.
|
|
168
|
+
6 FAILED_BREAK: the level that held is now confirmed as significant.
|
|
169
|
+
|
|
170
|
+
--------------------------------------------------------------------------------
|
|
171
|
+
INVALIDATION CONDITIONS
|
|
172
|
+
--------------------------------------------------------------------------------
|
|
173
|
+
IF support/resistance data is unavailable or empty arrays
|
|
174
|
+
→ BREAKING, CONFIRMED, and TEST_RS states cannot be determined.
|
|
175
|
+
Only RANGING, CONSOL, or RANGING may be emitted.
|
|
176
|
+
|
|
177
|
+
IF currentATR = 0 (extreme illiquidity)
|
|
178
|
+
→ ATR-based proximity and confirmation logic fails. Treat as unavailable.
|
|
179
|
+
|
|
180
|
+
IF transitionConfidence < 0.55
|
|
181
|
+
→ HMM state is ambiguous. Do not act on the state alone. Require
|
|
182
|
+
additional confirmation from regime and squeeze indicators.
|
|
183
|
+
|
|
184
|
+
--------------------------------------------------------------------------------
|
|
185
|
+
ANTI-PATTERNS — DETECTABLE MISUSE CONDITIONS
|
|
186
|
+
--------------------------------------------------------------------------------
|
|
187
|
+
IF BREAKING_UP is acted on immediately (before CONFIRMED_BREAK)
|
|
188
|
+
→ HIGH RISK. BREAKING_UP states have non-trivial false-positive rates.
|
|
189
|
+
They may transition to FAILED_BREAK. Wait for CONFIRMED_BREAK_UP
|
|
190
|
+
unless accepting reduced certainty for earlier entry.
|
|
191
|
+
|
|
192
|
+
IF CONSOL is treated as equivalent to RANGING
|
|
193
|
+
→ INCORRECT. CONSOL specifically requires 30% ATR compression below
|
|
194
|
+
baseline — a structural squeeze condition. RANGING is just a price
|
|
195
|
+
channel without compression. They imply different break dynamics.
|
|
196
|
+
CONSOL breaks tend to be more violent.
|
|
197
|
+
|
|
198
|
+
IF CONFIRMED_BREAK_UP is treated as a stop target for shorts
|
|
199
|
+
→ EVALUATION ORDER ISSUE. CONFIRMED_BREAK_UP is a state, not a level.
|
|
200
|
+
The specific resistance LEVEL that was broken is the reference price.
|
|
201
|
+
Identify the price level of the break via support/resistance data.
|