contrarian-setup-gate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContrarian Setup Gate
逆向投资配置网关
Overview
概述
Synthesize the outputs of Jason Shapiro's 3-step contrarian process into one actionable state. cot-contrarian-detector (step 1) flags crowded positioning, news-reaction-failure-analyzer (step 2) tests whether the market failed to react to news favorable to the crowd, and technical-analyst's contrarian-confirmation mode (step 3) confirms weekly price-action evidence of a reversal. This gate reads those three report JSONs and applies an explicit, exhaustively-tested precedence rule set to produce one , with a fail-closed reason attached to every input that could not be confirmed.
setup_statusThe gate does no fetching, no API calls, and no computation beyond validating and combining the three inputs it is given. It is the pipeline's synthesis center, not a data source.
将Jason Shapiro三步逆向投资流程的输出整合为一个可执行状态。cot-contrarian-detector(第一步)标记拥挤持仓情况,news-reaction-failure-analyzer(第二步)测试市场是否未对有利于持仓群体的新闻做出反应,technical-analyst的逆向确认模式(第三步)确认周价格走势的反转迹象。该网关读取这三份报告JSON,并应用一套经过全面测试的明确优先级规则集,生成一个,同时为每一项无法确认的输入附上故障关闭原因。
setup_status该网关不进行任何数据抓取、API调用,仅对给定的三个输入进行验证和整合,无额外计算。它是流程的整合中心,而非数据源。
When to Use
使用场景
- After running cot-contrarian-detector (always required -- this is the pipeline's entry point)
- Mid-pipeline, with only the detector report, to see the CROWDED state and what steps remain
- After running news-reaction-failure-analyzer, to see whether the setup advances to WATCHING_PRICE or is REJECTED
- After running technical-analyst's contrarian-confirmation mode, to see whether the setup reaches READY_FOR_PLAN
- Before handing a symbol's direction and stop level to a position-sizing skill
- 运行cot-contrarian-detector之后(此为流程的必填入口步骤)
- 流程中途,仅持有检测器报告时,查看CROWDED状态及剩余待执行步骤
- 运行news-reaction-failure-analyzer之后,查看配置是否推进至WATCHING_PRICE状态或被REJECTED
- 运行technical-analyst的逆向确认模式之后,查看配置是否达到READY_FOR_PLAN状态
- 将标的的方向和止损水平交付给仓位管理工具之前
Prerequisites
前置条件
- Python 3.9+
- No API keys -- this skill is fully offline
- A cot-contrarian-detector JSON report for the symbol under evaluation (required)
- Optionally, a news-reaction-failure-analyzer JSON report for the same symbol (step 2)
- Optionally, a technical-analyst contrarian-confirmation JSON report for the same symbol (step 3)
- Python 3.9+
- 无需API密钥——本工具完全离线运行
- 待评估标的的cot-contrarian-detector JSON报告(必填)
- 可选:同一标的的news-reaction-failure-analyzer JSON报告(第二步)
- 可选:同一标的的technical-analyst逆向确认JSON报告(第三步)
Workflow
工作流程
Step 1: Run the Gate
步骤1:运行网关
bash
python3 skills/contrarian-setup-gate/scripts/run_contrarian_setup_gate.py \
--symbol B6 \
--detector-json reports/cot_crowding_2026-07-12.json \
--news-json reports/nrf_B6_2026-07-12.json \
--price-action-json reports/ta_confirmation_B6_2026-07-12.json \
--as-of 2026-07-15 \
--output-dir reports/--symbol--detector-json--news-json--price-action-json--as-ofExit behavior is intentionally asymmetric: a missing or malformed (or any other CLI usage error) is an operator config mistake, so the CLI exits with usage text and writes no report. A problem with one of the three untrusted report files -- unreadable, malformed, stale, inconsistent -- is always handled fail-closed instead: the CLI exits and writes a report naming the reason, exactly like every other skill in this pipeline.
--as-of20bash
python3 skills/contrarian-setup-gate/scripts/run_contrarian_setup_gate.py \
--symbol B6 \
--detector-json reports/cot_crowding_2026-07-12.json \
--news-json reports/nrf_B6_2026-07-12.json \
--price-action-json reports/ta_confirmation_B6_2026-07-12.json \
--as-of 2026-07-15 \
--output-dir reports/--symbol--detector-json--news-json--price-action-json--as-of退出行为具有明确的不对称性:若缺失或格式错误(或其他CLI使用错误),属于操作者配置失误,CLI将以状态码退出并输出使用说明,且不生成报告。若三份不可信报告文件存在问题——无法读取、格式错误、过期、不一致——则始终按故障关闭逻辑处理:CLI以状态码退出并生成报告,明确标注原因,与本流程中的其他工具保持一致。
--as-of20Step 2: Read the Setup Status
步骤2:查看配置状态
| Status | Meaning | Next Step |
|---|---|---|
| All three steps confirmed; direction, entry_trigger, and invalidation_level are populated | Hand |
| Crowding + news confirmed; price action still pending | Run technical-analyst's contrarian-confirmation mode |
| Crowding confirmed; news and/or price still pending | Run news-reaction-failure-analyzer |
| Crowding is NOT_CONFIRMED (classification NEUTRAL), or news/price came back NOT_CONFIRMED | Stop -- do not run further steps for this symbol/direction |
| A required input is missing, unreadable, stale, inconsistent, or could not itself reach a verdict | Stop -- fix or regenerate the named input before rerunning |
missing_confirmationsstatereasonwarnings| 状态 | 含义 | 下一步操作 |
|---|---|---|
| 三步均已确认;已填充方向、entry_trigger和invalidation_level | 将 |
| 拥挤度+新闻反应已确认;价格走势仍待确认 | 运行technical-analyst的逆向确认模式 |
| 拥挤度已确认;新闻反应和/或价格走势仍待确认 | 运行news-reaction-failure-analyzer |
| 拥挤度未确认(分类为NEUTRAL),或新闻反应/价格走势未确认 | 终止——无需对该标的/方向执行后续步骤 |
| 缺失必填输入、输入无法读取、过期、不一致,或无法得出判定结果 | 终止——修复或重新生成指定输入后再重新运行 |
missing_confirmationsstatereasonwarningsStep 3: Act on READY_FOR_PLAN Only
步骤3:仅对READY_FOR_PLAN状态执行操作
At , (SHORT/LONG, the fade side of the crowd), (a factual echo of the confirming weekly signal), and (the stop reference from the price-action report) are populated. is the weaker of the news and price-action confidences (HIGH/MEDIUM/LOW -- is a token both upstream skills document as reserved but never actually emit; the gate accepts it and ranks it weakest rather than rejecting it as unknown). Position sizing is the next pipeline stage (not yet built as of this skill's release -- see the roadmap in the repository's workflow docs); this gate never places or recommends an order.
READY_FOR_PLANdirectionentry_triggerinvalidation_levelgate_confidenceLOW当状态为时,(SHORT/LONG,即反向操作持仓群体的方向)、(确认周信号的事实性描述)和(价格走势报告中的止损参考值)已填充。取新闻反应和价格走势置信度中的较低值(HIGH/MEDIUM/LOW——为上游工具预留但实际从未输出的标识;网关会接受该值并将其列为最低置信度,而非视为未知值拒绝)。仓位管理为流程的下一阶段(本工具发布时尚未开发——详见仓库工作流文档中的路线图);本网关绝不下达或推荐订单。
READY_FOR_PLANdirectionentry_triggerinvalidation_levelgate_confidenceLOWPrecedence (Summary)
优先级规则(摘要)
Each step is evaluated in strict pipeline order -- crowding, then news, then price-action -- and each step fully settles before the next step's file is even consulted. An earlier step's definitive verdict is never softened by a later step's problem.
- Crowding is evaluated first and exclusively: INVALID/INSUFFICIENT crowding is always ; a NOT_CONFIRMED (NEUTRAL) classification is always
INSUFFICIENT_EVIDENCE, regardless of any downstream file's state or corruption.REJECTED - With crowding CONFIRMED, news is evaluated next, on its own: INVALID (unreadable, malformed, stale, symbol mismatch, direction mismatch, unsupported schema) forces ; NOT_CONFIRMED forces
INSUFFICIENT_EVIDENCE; INSUFFICIENT forcesREJECTED-- in every one of these cases, price-action is never even inspected for the decision.INSUFFICIENT_EVIDENCE - Once news is CONFIRMED (or PENDING, for out-of-order use), price-action is evaluated last, with the same four-way settlement. Running price-action before news (out-of-order pipeline use) caps the status at with a warning -- a NOT_CONFIRMED price-action verdict still REJECTs even out of order, since price-action is still fully evaluated in that branch.
CROWDED - Crowding confirmed, both downstream steps pending -> .
CROWDED - Crowding + news confirmed, price-action pending -> .
WATCHING_PRICE - All three confirmed -> .
READY_FOR_PLAN
See for the full decision table (every reachable {crowding} x {news} x {price-action} state combination), the reason-token glossary, and worked examples.
references/gate-decision-table.md各步骤严格按照流程顺序评估——先拥挤度,再新闻反应,最后价格走势——且前一步骤得出明确判定后才会查看下一步骤的文件。早步骤的明确判定不会因晚步骤的问题而弱化。
- 首先且仅评估拥挤度:无效/证据不足的拥挤度始终对应;未确认(NEUTRAL)的分类始终对应
INSUFFICIENT_EVIDENCE,与下游文件的状态或损坏情况无关。REJECTED - 若拥挤度已确认,接下来评估新闻反应:无效(无法读取、格式错误、过期、标的不匹配、方向不匹配、不支持的 schema)将触发;未确认将触发
INSUFFICIENT_EVIDENCE;证据不足将触发REJECTED——在上述所有情况下,价格走势文件不会被用于决策。INSUFFICIENT_EVIDENCE - 若新闻反应已确认(或流程乱序使用时处于待确认状态),最后评估价格走势,遵循相同的四种判定结果。若在新闻反应之前运行价格走势(流程乱序使用),状态将上限为并附带警告——即使乱序,未确认的价格走势判定仍会触发
CROWDED,因为该分支中价格走势仍会被完整评估。REJECTED - 拥挤度已确认,下游两步均待确认 ->
CROWDED - 拥挤度+新闻反应已确认,价格走势待确认 ->
WATCHING_PRICE - 三步均已确认 ->
READY_FOR_PLAN
详见获取完整决策表(所有可达的{拥挤度}x{新闻反应}x{价格走势}状态组合)、原因标识术语表及示例。
references/gate-decision-table.mdOutput Contract
输出约定
The script writes and to :
contrarian_setup_gate_<SYMBOL>_<as-of>.json.md--output-diryaml
symbol: B6
setup_status: READY_FOR_PLAN | WATCHING_PRICE | CROWDED | REJECTED | INSUFFICIENT_EVIDENCE
direction: SHORT | LONG | null
gate_confidence: HIGH | MEDIUM | LOW | null
entry_trigger: string | null
invalidation_level: number | null
missing_confirmations: [{step, state, reason}, ...]
warnings: [string, ...]
inputs:
crowding: {state, classification, data_date, age_days, report_path}
news_failure: {state, verdict, confidence, verdict_reason, as_of, age_days, report_path}
price_action: {state, verdict, confidence, verdict_reason, stop_reference, as_of, age_days, report_path}
run_context: {symbol, as_of, max_detector_age_days, max_report_age_days, schema_version, skill}Every input's is one of , , , (report not provided), or (a report was provided but is unusable -- unreadable, malformed, stale, or inconsistent with the other inputs; always carries a named reason).
stateCONFIRMEDNOT_CONFIRMEDINSUFFICIENTPENDINGINVALID脚本会在目录下生成和文件:
--output-dircontrarian_setup_gate_<SYMBOL>_<as-of>.json.mdyaml
symbol: B6
setup_status: READY_FOR_PLAN | WATCHING_PRICE | CROWDED | REJECTED | INSUFFICIENT_EVIDENCE
direction: SHORT | LONG | null
gate_confidence: HIGH | MEDIUM | LOW | null
entry_trigger: string | null
invalidation_level: number | null
missing_confirmations: [{step, state, reason}, ...]
warnings: [string, ...]
inputs:
crowding: {state, classification, data_date, age_days, report_path}
news_failure: {state, verdict, confidence, verdict_reason, as_of, age_days, report_path}
price_action: {state, verdict, confidence, verdict_reason, stop_reference, as_of, age_days, report_path}
run_context: {symbol, as_of, max_detector_age_days, max_report_age_days, schema_version, skill}每个输入的为以下值之一:、、、(未提供报告)或(提供了报告但无法使用——无法读取、格式错误、过期或与其他输入不一致;始终附带明确原因)。
stateCONFIRMEDNOT_CONFIRMEDINSUFFICIENTPENDINGINVALIDGuardrails
防护规则
- Never places or recommends orders. is the furthest state this skill reaches. Order entry and position sizing are separate, downstream decisions.
READY_FOR_PLAN - INSUFFICIENT_EVIDENCE and REJECTED never advance. No warning, confidence, or partial input ever pushes the status past what the precedence rules allow.
- Fail closed on every input, always. An unreadable, malformed, stale, symbol-mismatched, or unknown-enum report is never treated as a pass -- it is named and blocks or downgrades the status. This includes the price-action report's (allowlisted against technical-analyst's actual confirming-signal vocabulary, not merely type-checked) and its
verdict_reason(must be a finite, positive number -- never non-finite, zero, negative, or a boolean). Before any of the three report files reaches this validation, the CLI also rejects a file outright (reasonstop_reference) if it contains a non-finite number (<input>_non_finite/Infinity/-Infinity, including an ordinary-looking number likeNaNthat overflows on parse) ANYWHERE in it, not just in a field the gate reads -- this is what keeps every report a valid, complete JSON file even under adversarial input.1e309 - always carries a usable plan.
READY_FOR_PLANis guaranteed non-empty andentry_triggeris guaranteed a finite positive number whenever the status isinvalidation_level-- enforced both by input validation and by a defensive invariant check.READY_FOR_PLAN - Not investment advice. and
entry_triggerare factual echoes of the upstream price-action report, not recommendations.invalidation_level
- 绝不下达或推荐订单。是本工具能达到的最高状态。订单下达和仓位管理是独立的下游决策环节。
READY_FOR_PLAN - INSUFFICIENT_EVIDENCE和REJECTED状态绝不推进。任何警告、置信度或部分输入都不会突破优先级规则允许的状态上限。
- 对所有输入始终执行故障关闭逻辑。无法读取、格式错误、过期、标的不匹配或枚举值未知的报告绝不会被视为通过——会被明确标记并阻止或降低状态。这包括价格走势报告的(需与technical-analyst实际使用的确认信号词汇表匹配,而非仅做类型检查)及其
verdict_reason(必须为有限正数——绝不能是非有限值、零、负数或布尔值)。在对三份报告文件进行上述验证之前,若文件中任何位置包含非有限数值(stop_reference/Infinity/-Infinity,包括解析时会溢出的普通数字如NaN),CLI会直接拒绝该文件(原因标识为1e309)——这确保即使在恶意输入下,每份报告仍是有效的完整JSON文件。<input>_non_finite - READY_FOR_PLAN状态始终包含可用方案。当状态为时,
READY_FOR_PLAN保证非空,entry_trigger保证为有限正数——通过输入验证和防御性不变量检查双重保障。invalidation_level - 不构成投资建议。和
entry_trigger是上游价格走势报告的事实性转述,而非建议。invalidation_level
Resources
资源
- -- CLI: hardened JSON loading (unreadable / parse_error incl. RecursionError / non_finite via an iterative whole-file scan), report generation
scripts/run_contrarian_setup_gate.py - -- Pure synthesis core: normalization (incl. malformed-shape detection), consistency checks, the precedence state machine
scripts/gate_logic.py - -- Full decision table, reason-token glossary, worked examples (including the real B6 REJECTED case)
references/gate-decision-table.md
- ——CLI:增强型JSON加载(处理无法读取/解析错误包括RecursionError/通过迭代全文件扫描检测非有限值)、报告生成
scripts/run_contrarian_setup_gate.py - ——纯整合核心:标准化(包括格式错误检测)、一致性检查、优先级状态机
scripts/gate_logic.py - ——完整决策表、原因标识术语表、示例(包括真实的B6标的REJECTED案例)
references/gate-decision-table.md