[TOC]

A reflection on Vibe Trading: when to use AI, and when not to.
There’s a concept gaining traction lately called Vibe Trading — describe your trading intent in natural language, and let AI execute it for you. Say “conservative strategy, prioritize low-volatility assets,” and AI handles the allocation automatically. Sounds great.
But before we talk about Vibe Trading, let me share something that happened recently — it illustrates “where AI belongs” better than any theory.
On March 31st, Anthropic’s Claude Code accidentally exposed its source code during an npm update — roughly 512,000 lines of TypeScript (note: this is total bundled code including dependencies and generated files). The community’s reverse engineering kicked off immediately, with developers worldwide digging through the code for new features.
But the most surprising finding had nothing to do with AI. And it has nothing to do with trading either — but the engineering philosophy behind it should resonate with anyone in quant trading.
In a module labeled userPromptKeywords by analysts, there was a regex pattern matching profanity like shit, wtf, and fucking broken — used to quickly determine if a user was swearing.
The world’s most advanced large language model company uses regex to detect sentiment.
Not calling Claude for sentiment analysis. Not training a classifier. Just a microsecond-level string match.
Why?
This isn’t laziness. It’s a deliberate engineering decision.
Claude Code handles hundreds of thousands of user interactions daily. Each one requires a judgment: “Is the user expressing frustration?” to adjust response strategy. If every check called an LLM:
So Anthropic’s choice: use regex for fast filtering (low overhead, high speed, fully deterministic), and save LLM compute for decisions that truly need semantic understanding.
This isn’t a technical detail. It’s an architectural philosophy: not every problem deserves an AI solution.
Quant traders should feel this one deeply.
Your strategy has two types of decisions:
Anyone who’s written strategies on FMZ knows the core trading logic is often just a few lines of deterministic code:
// Moving Average Crossover Signal — FMZ JavaScript Example
var records = exchange.GetRecords(PERIOD_D1)
var ma5 = TA.MA(records, 5)
var ma20 = TA.MA(records, 20)
var idx = records.length - 1
// Golden cross — go long
if (ma5[idx] > ma20[idx] && ma5[idx-1] <= ma20[idx-1]) {
exchange.SetDirection("buy")
exchange.Buy(records[idx].Close, 1)
Log("Golden cross, opening long")
}
Clear conditions, deterministic results, no need to “understand” semantics. Written with if-else, 100% reliable, millisecond execution.
This follows a similar logic to Anthropic using regex for sentiment detection — deterministic problems call for deterministic tools. Of course, regex is string matching and moving averages are mathematical calculations — different tools, but they play similar roles in their respective systems: deterministic judgments that don’t need AI involvement.
Stop-loss with if-else is 100% reliable. Stop-loss with AI is “probably” reliable. Your account can’t afford that “probably.”
But some decisions can’t be written as if-else:
These scenarios share a common trait: the input is unstructured, the criteria are fuzzy, and it requires “understanding” rather than just “matching.”
Back to Claude Code’s architecture. Community analysis revealed a clear layering:
| Layer | Mechanism in Claude Code | Counterpart in Quant Trading |
|---|---|---|
| Fast Filtering Layer | Regex, keyword matching | MA crossover, threshold stop-loss, position limits |
| Engineering Infrastructure | Process management, messaging, permissions | Exchange API, order management, risk engine |
| Semantic Decision Layer | LLM prompts | News sentiment analysis, anomaly detection, strategy exploration |
Of course, Claude Code and quantitative trading are entirely different domains — this mapping isn’t exact. But the resonance in design philosophy is real: choose the right tool at each layer, rather than hammering every nail with the same hammer.
The open-source community is practicing similar ideas. TradingAgents is a notable multi-agent quant trading framework (built on LangGraph, with an accompanying academic paper). It simulates a real trading firm’s team structure: technical analysts handle candlestick and indicator calculations, sentiment analysts interpret news, and traders with different risk profiles synthesize all inputs for final decisions. Not one omniscient AI doing everything, but different roles each handling their specialty.
It’s worth noting that TradingAgents is a research framework — it addresses “how AI makes trading decisions.” But in live trading, you still need the other half: exchange connectivity, order management, risk execution, audit logs — engineering infrastructure work that platforms like FMZ have already built for you.
Back to Vibe Trading. The direction is right, but the layering must be clear.
Suppose BTC’s moving averages just formed a golden cross today, but the news is all about regulatory crackdowns. What do you do? Pure MA says go long; pure news says stay out. This is exactly the scenario that calls for layering.
On FMZ, a simplified layered architecture can be implemented like this (note: simplified example — please add proper contract setup and risk controls for live trading):
/*
Strategy Parameters (add in the "Parameters" section of FMZ strategy editor):
OPENROUTER_API_KEY : string, your OpenRouter API Key
AI_MODEL : string, default "google/gemini-2.5-flash", can be changed to other models
*/
// Semantic Decision Layer: call AI via OpenRouter for market sentiment
function getAISentiment() {
var prompt = "Analyze current crypto market news, give a sentiment score (-1 to 1, -1 extreme fear, 1 extreme greed), return only a number"
var response = HttpQuery("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
body: JSON.stringify({
model: AI_MODEL,
messages: [{role: "user", content: prompt}],
temperature: 0
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + OPENROUTER_API_KEY
},
timeout: 15000
})
var score = parseFloat(JSON.parse(response).choices[0].message.content)
// Fall back to neutral when AI returns unexpected output — system reliability shouldn't depend on every AI call being correct
if (isNaN(score) || score < -1 || score > 1) {
Log("AI returned unexpected format, using default 0")
score = 0
}
Log("AI sentiment score:", score)
return score
}
function main() {
var lastSignalTime = 0 // Track last signal bar time to prevent duplicate triggers on the same candle
while (true) {
var records = exchange.GetRecords(PERIOD_D1)
if (!records || records.length < 20) { Sleep(1000); continue }
var ma5 = TA.MA(records, 5)
var ma20 = TA.MA(records, 20)
var idx = records.length - 1
var curTime = records[idx].Time
var isBullCross = ma5[idx] > ma20[idx] && ma5[idx-1] <= ma20[idx-1]
var isBearCross = ma5[idx] < ma20[idx] && ma5[idx-1] >= ma20[idx-1]
// Check position status
var pos = exchange.GetPosition()
var hasPosition = pos && pos.length > 0
// Layer 1: Deterministic signal as "gate" — golden cross + no position + not yet processed on this bar, then ask AI
if (isBullCross && !hasPosition && curTime !== lastSignalTime) {
lastSignalTime = curTime
var sentiment = getAISentiment()
// Layer 2: AI sentiment as "reference" — affects sizing but doesn't independently trigger trades
if (sentiment > 0.2) {
exchange.SetDirection("buy")
exchange.Buy(records[idx].Close, 1)
Log("Golden cross + AI bullish, full position")
} else if (sentiment > -0.3) {
exchange.SetDirection("buy")
exchange.Buy(records[idx].Close, 0.5)
Log("Golden cross + AI neutral, half position")
} else {
Log("Golden cross but AI bearish, skipping signal")
}
}
// Death cross — close position: deterministic rule, no AI involved
if (isBearCross && hasPosition) {
exchange.SetDirection("closebuy")
exchange.Sell(records[idx].Close, pos[0].Amount)
Log("Death cross, closing position")
}
// Layer 3: Stop-loss is "iron law" — no AI involvement
if (hasPosition) {
var curPrice = records[idx].Close
var entryPrice = pos[0].Price
if (curPrice < entryPrice * 0.97) { // 3% below entry price
exchange.SetDirection("closebuy")
exchange.Sell(curPrice, pos[0].Amount)
Log("Stop-loss triggered, unconditional close, loss:", ((curPrice/entryPrice - 1)*100).toFixed(2), "%")
}
}
Sleep(60 * 1000)
}
}

The core logic of this code is worth unpacking:
1. The golden cross is the “gate.” Only when the deterministic signal fires does the strategy call AI. It won’t query the LLM on every candle — saving money (LLM APIs charge per token) and filtering out noise. This mirrors Anthropic’s approach: regex filters first, heavier processing only triggers on a match.
2. AI sentiment is a “reference.” It affects position sizing and whether to skip a signal, but never independently triggers a trade. Notice the error handling on AI return values — if the LLM returns unparseable content, it falls back to a neutral value of 0. System reliability should never depend on every AI call being correct.
3. Stop-loss is “iron law.” Drop 3% below entry price and the position closes unconditionally — no asking AI for its opinion. AI might say “long-term bullish,” but your account can’t wait for the long term. This uses a hard price-percentage stop — no fuzzy judgment involved.
This is the right way to do Vibe Trading: use natural language to let AI help you “sense” market atmosphere, and use deterministic code to “execute” trading actions. The boundary between the two must not be blurred.
Practical tip: In FMZ’s backtesting system, first run a pure MA strategy as a baseline, then add the AI sentiment layer and compare returns and drawdowns. If AI makes things worse — your layering is wrong, and AI may be interfering where it shouldn’t. Log every AI response with Log() so you can review each decision after the fact.
The most advanced AI company uses regex to detect sentiment — not because they can’t build something better.
It’s because they know: choosing the right tool matters more than choosing the strongest tool.
Moving average strategies aren’t sexy. Regex isn’t sophisticated. But in their respective domains, they’re more reliable than any AI.
Conversely, when you need to extract “is this report bullish or bearish on BTC” from a 5,000-word macro research note — moving averages can’t help you, and neither can regex. That’s when AI should step in.
It’s not about “whether to use AI” — it’s about “at which layer to use it.”
That unassuming regex file in Claude Code’s source answered a question we often overlook. And what FMZ gives you is a ready-made layered infrastructure — exchange connectivity, indicator calculations, live trading management, audit logs — all built for you. All you need to figure out is: which decisions go to TA.MA(), and which go to AI.
References: - Alex Kim - The Claude Code Source Leak — Regex frustration detection analysis - FMZ - Building an AI-Powered Automated Trading System — AI brain + FMZ hands architecture - TradingAgents - Multi-Agents LLM Financial Trading Framework — Open-source multi-agent quant framework - TradingAgents Paper — Academic research on multi-agent financial trading - VentureBeat - Claude Code Source Code Leak