AI 交易系統如何透過連敗紀錄與鏈上數據修正決策
Giving AI Traders a 'Rearview Mirror': Decision Correction via Cold Streaks and On-Chain Data
AI 交易系統加入近期交易表現和鏈上數據,為交易訊號提供情境判斷,並在下單前攔截邊緣訊號。系統評估 XMRUSDT 做空訊號時,因帳戶最近 5 筆交易中只贏 1 筆,且鏈上數據顯示大戶正在累積多倉,最終否決交易。
Giving AI Traders a 'Rearview Mirror': Decision Correction via Cold Streaks and On-Chain Data
It’s 01:09 AM on a quiet Sunday. The crypto market is chopping sideways, and your AI trading bot is staring at a marginal short setup for XMRUSDT. The technical indicators are slightly bearish, and the baseline scoring engine spits out a confidence score of 56.1. In a traditional, stateless algorithmic setup, this might be enough to pull the trigger. But in our system, the AI pauses. It looks in the "rearview mirror," checks its recent track record, peers into the on-chain reality, and decides to kill the trade.
This is the story of how we moved beyond static, point-in-time predictions to build a context-aware AI trading system that actively protects capital during drawdown phases.
Background: The "Amnesia" Problem in AI Trading
Most algorithmic trading systems, including early iterations of AI-driven crypto bots, suffer from a critical flaw: amnesia. They evaluate every trade in a vacuum. The AI looks at the current order book, calculates the RSI, checks the MACD, and generates a signal. It doesn't remember that it just lost three trades in a row. It doesn't know that the broader market regime has shifted from trending to mean-reverting.
When an AI lacks contextual awareness, it tends to overtrade during choppy conditions. It will happily execute low-probability, marginal signals, leading to unnecessary algorithmic drawdowns and slow capital erosion. To fix this, we needed to give the AI a "rearview mirror"—a mechanism to evaluate its own recent performance and cross-reference its technical assumptions with fundamental, on-chain reality.
The Problem: A Marginal Signal in a Choppy Market
The issue materialized clearly in our recent system logs. The AI_ADVISOR module generated a short signal for XMRUSDT. The baseline technical score was 56.1. While this score was below our strict 65-point threshold for standard execution, the elastic threshold system was dynamically lowering the entry bar due to a lack of high-quality setups.
Relying solely on current market data and isolated technical indicators, the AI was dangerously close to executing this low-probability trade. Here is what the system state looked like right before the decision:
2026-10-26 01:07:04,200 [INFO] scoring_engine: F-229/F-230: Elastic threshold: 80 → 70 (consecutive_veto=365, original=80, floor=60)
2026-10-26 01:08:42,313 [INFO] main: [F-536] Global Trend: NEUTRAL | ruling=VETO delta=-15 conf=0.87 | System score only 50.0, far below main position threshold 80 (elastic floor 75) by over 25 points, signal invalid; news sentiment leans regulatory negative, no long catalyst; recently issued -15 ruling for BTCUSDT 3 times consecutively...
The global trend was neutral, and the system was already in a defensive posture (consecutive vetoes = 365). Yet, the sub-account AI was still evaluating a marginal short. Executing this trade would have been a classic "edge-case" trap, exposing the portfolio to unnecessary risk in a directionless market.
The Solution: The 'Rearview Mirror' Architecture
To prevent these edge-case losses, we implemented a multi-layered decision correction mechanism. This architecture introduces two critical filters before any order is sent to the exchange.
1. Historical Context: The 'Cold Streak' Metric
Moving beyond point-in-time predictions, we now feed the AI_ADVISOR recent historical context. We calculate a "cold streak" metric based on the sub-account's recent trade history. For instance, if the sub-account is in a state of "1 win in the last 5 trades," it is flagged as being in a cold streak.
During a cold streak, the system dynamically adjusts its risk tolerance. The mathematical penalty applied to the baseline score increases, effectively raising the bar for new entries. The logic is simple: if the AI's recent read on the market is poor, it should not be allowed to forcefully execute marginal signals. It must wait for a high-conviction setup to break the streak.
2. Cross-Dimensional On-Chain Validation
Technical analysis tells you what the price is doing; on-chain data tells you what the smart money is doing. We integrated on-chain analytics to cross-verify technical signals. If the AI generates a short signal based on a bearish chart pattern, but on-chain data shows that top-tier smart money wallets are aggressively accumulating long positions, the system flags a "dimensional contradiction." This adds a layer of fundamental reality to purely technical assumptions.
3. The Veto Logic in Action
When the AI_ADVISOR evaluated the XMRUSDT short signal with a baseline score of 56.1, it didn't just look at the chart. It applied mathematical penalties for the active cold streak and the on-chain smart money contradiction.
Here is the exact log of the veto logic intercepting the trade:
2026-10-26 01:09:09,237 [INFO] ai_advisor: [AI_ADVISOR] API response processed (model=deepseek-v4-flash)
2026-10-26 01:09:09,248 [INFO] ai_advisor: [AI_ADVISOR] Sub-account final ruling XMRUSDT: FINAL_RULING=VETO delta=-12 conf=0.72 reason=[Ruling: Veto] Score 56.1 below 65 threshold; on-chain smart money long (LS=2.27) and active buying (R=1.19) directly contradict short direction; Kraken confirms XMR listing retention is bullish, lacking catalyst for short; sub-account only 1 win in last 5 trades showing cold streak, no need to force marginal signals.
2026-10-26 01:09:09,248 [INFO] main: C-04 Pre-execution final ruling: XMRUSDT SHORT RULING=VETO
The result? The AI_ADVISOR successfully vetoed the XMRUSDT short trade. The marginal edge case was intercepted before execution, preserving capital. The system correctly identified that shorting an asset with strong smart money accumulation and positive exchange news (Kraken retaining the listing), while the sub-account itself was in a cold streak, was a mathematical trap.
Technical Implementation Details
For developers looking to replicate this context-aware architecture, here is a breakdown of the underlying data pipeline and decision engine mechanics:
- Execution Log Fetching: The central decision engine periodically queries internal APIs to fetch recent execution logs for each specific sub-account. We maintain a rolling window of the last $N$ trades (currently $N=5$ or $10$).
- Computing Rolling Win-Rate Streaks: We compute a rolling win-rate metric. If
wins_in_last_N < threshold(e.g., 1 win in 5 trades), theis_cold_streakboolean is triggered. This state is passed directly into the prompt context for the LLM-basedAI_ADVISORand used as a hardcoded multiplier in the deterministic scoring engine. - On-Chain Indexing Pipeline: We query on-chain indexing protocols (via GraphQL endpoints and specialized Dune Analytics APIs) to track whale wallet flows. We calculate metrics like Long/Short ratios (LS) and active buying pressure (R) for the specific asset.
- Weighted Veto Threshold: In the central decision engine, the final score is calculated as:
Final_Score = Base_Technical_Score - (Cold_Streak_Penalty * W1) - (OnChain_Contradiction_Penalty * W2). If theFinal_Scorefalls below the dynamic elastic threshold, or if a hard veto condition (like a massive on-chain contradiction) is met, theFINAL_RULINGis set toVETO.
Lessons Learned
Building this "rearview mirror" architecture taught us several crucial lessons about algorithmic trading:
- Context is King: A 56.1 score in a vacuum is just a number. A 56.1 score when you are on a losing streak and fighting on-chain whales is a disaster waiting to happen. Context transforms raw data into actionable intelligence.
- Defense Wins Championships: Preventing edge-case losses is just as important as capturing winning trades. By vetoing marginal signals during choppy conditions, we significantly reduced our maximum drawdown and preserved our capital for high-conviction setups.
- Multi-Dimensional Validation: Relying on a single dimension (like technical analysis) is a vulnerability. Cross-referencing technicals with on-chain reality and internal performance metrics creates a robust, multi-layered defense system.
Developer Resources
Building robust, context-aware trading bots requires a solid quantitative infrastructure and the right tooling. For independent developers looking to explore the underlying architecture, data pipelines, and community insights behind these systems, check out the tools and detailed breakdowns at https://kestrelquant.com. We are building in public, and you can find our open-source utilities, API documentation, and quantitative frameworks there.
⚠️ Risk Warning
Algorithmic and AI-driven crypto trading involves a substantial risk of loss and is not suitable for all investors. The mechanisms discussed in this article, including cold streak adjustments, elastic thresholds, and on-chain vetoes, are designed for risk management but do not guarantee profitability or eliminate drawdowns. Past system performance and historical veto logic are not indicative of future results. The crypto market is highly volatile, and technical or on-chain signals can fail unexpectedly. Always conduct your own rigorous research, backtest extensively, and never trade with funds you cannot afford to lose.
Tags: #algotrading #crypto #ai #buildinpublic
來源:DEV Community · dev.to