✨ Building an AI Workflow for Identifying and Updating Liquidation Cascade Criteria #176
tripolskypetr
started this conversation in
Ideas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
✨ Building an AI Workflow for Identifying and Updating Liquidation Cascade Criteria
Previously I wrote about Why the Price Drops in a Single Candle. The cause of that phenomenon is a liquidation cascade.
A liquidation cascade is not random price movement. The price drops below a certain level and the exchange forcibly closes positions — via market orders, selling everything at once without discrimination. The price drops fast and deep within one or two bars, after which there is no one left to sell and the market bounces back. This pattern repeats dozens of times a year.
Yet nobody profits from it, because the parameters change every month. In one regime a cascade is a support level breakdown with continuation downward. In another it's a spike with an immediate V-bounce of 3%. Updating these criteria requires digging into the news feed: who got liquidated and why. This makes building such a system by hand impractical.
What Changed
In March 2026, Anthropic added the
/loopcommand to Claude Code — a local scheduler (crontab) that runs a prompt in the background while the session is open. This closes the loop:However, writing the command literally won't work. There are at least two reasons: your inability to articulate the requirement lets Anthropic profit from you. And second — you have no acceptance criteria to validate the strategy on historical data before deploying to production.
The Agent Skill
The critical difference is creating
CLAUDE.md. This is a system prompt that defines the agent's contract with the result. It doesn't explain how to write code. It explains how to think about the market before writing code. Here are my findings:How the Agent Handled February 2026
Task submitted to the agent:
1. Read jan_2026.pine and understand why the strategy is bad
I created the January strategy specifically as a genesis for the recursion, so the prompt would work the first time. It's a bear trend continuation strategy. It works when the market drops monotonically. Now we need to understand why February didn't produce profit.
npm start -- --dump --timeframe 15m --limit 500 --when "2026-02-28T00:00:00.000Z" --jsonl
The agent received a dump of 500 15-minute candles. Not to stare at numbers — but to see the shape of the movement: where volume spikes occurred, where price gaps formed, how pullbacks looked.
2. Search for Bitcoin February 2026 news (negative)
Before looking for a pattern in the data, the agent searches for the news context that explains the data.
CLAUDE.mdprescribes searching specifically for negative news — not "bitcoin price February" but concrete events that could have triggered forced liquidations. Three searches revealed: on February 5–6, $700 million in liquidations occurred in a single session, bitcoin dropped to $60K and bounced to $65K. The Bybit hack aftershock ($1.5B ETH) dragged on throughout the month. ETF funds recorded outflows.This isn't background noise — it's a mechanical explanation. It shows why the market produced V-bounces exactly where the January strategy was opening SHORTs and holding them down.
3. Analyze market structure and develop a strategy hypothesis
Here the agent does what an indicator cannot: it correlates the news context with actual candles and formulates why the pattern looked the way it did.
The market entered February at $67–70K after the $126K peak in October 2025 — already -45% from the top, institutional selling, ETF outflows. Inside the month there was no straight-line drop but a W-structure: a bounce from $62,510 to $70K and back. Every sharp breakdown ended with an immediate pump — because these were liquidations, not fundamental selling. After forced position closures there is no one left to sell.
The January strategy failed for exactly this reason: it waited for continuation of the drop after a minimum breach — and every time received a V-bounce of $7–8K against the open SHORT.
The hypothesis the agent formalized before writing code: RSI oversold bounce + volume spike confirmation for LONG after liquidation panic candles. TP=1.5%, SL=0.7%, no trailing — exit by condition.
This is where the workflow's value lies. Not in the fact that the agent can write Pine Script — that's straightforward. But in the fact that it arrived at this hypothesis through analysis, not iteration. The strategy explains market mechanics; it doesn't search for a random correlation in numbers.
4. Write feb_2026.pine from scratch
The agent wrote the strategy and immediately got the first results. But
CLAUDE.mddoes not allow stopping at "profitable" — at least one signal per day and an acceptable Sharpe are required.5. Run feb_2026.pine and check the result
0.54 signals per day. Sharpe 0.08. Feb 22 holds a position for 44 bars — a quiet HOLD without a strict exit condition. The problem isn't in the parameters — it's that the spike filter lets slow downtrends through alongside genuine cascades.
The agent wrote a Python script that parsed the boundaries of each position and pulled the context of two bars before entry — separately for profitable trades and separately for losers.
Good entries came after a single extreme bar (Feb 6: 62910 → 60256, -4%). Bad entries came after uniform slow declines where no bounce occurred and the price continued downward. The distinguishing feature: the previous candle's drop must be > 1.5 ATR. This separates a forced liquidation from a regular downtrend — exactly the mechanics I described in Second-Order Chaos: How Algo Trading Bots Play Against Themselves at a Loss.
6. Code review for HOLD / trailing SL
Review as a separate call — a
CLAUDE.mdrequirement. The reviewer found a stub left over from the iteration process and deleted seven lines of commented-out hacks. The check for absent infinite trailing SL passed. The strategy header is updated to preserve the findings.7. Save analytics to report/feb_2026.md
The agent saved the full analysis: market structure, news sources, explanation of why the January strategy failed, and the hypothesis with justification. Next month the agent will read this file first — it's a knowledge base that accumulates rather than resetting when the context switches.
Results
The Backtest Kit internal UI shows the lifecycle of each trade across timeframes. The higher timeframe shows price moving in a range.
28.02 +1.10%, 23.02 +1.10%, 16.02 +1.10%, 15.02 -1.20%, 10.02 +1.10%, 06.02 +1.10%.
The system sends a notification for every 10% of the path to TP, and a separate
Breakeven availableevent when the position has moved to breakeven.Total PNL 4.28%, Win Rate 83.33%, Profit Factor 4.58, Sharpe Ratio 0.84, Max Drawdown 0.00%.
Source Code
{ "name": "node-ccxt-backtest", "scripts": { "start": "node ./node_modules/@backtest-kit/cli/build/index.mjs" }, "dependencies": { "@backtest-kit/cli": "^6.0.0", "@backtest-kit/graph": "^6.0.0", "@backtest-kit/pinets": "^6.0.0", "@backtest-kit/ui": "^6.0.0", "agent-swarm-kit": "^1.3.0", "backtest-kit": "^6.0.0", "functools-kit": "^1.0.95", "garch": "^1.2.3", "get-moment-stamp": "^1.1.2", "ollama": "^0.6.3", "volume-anomaly": "^1.2.3" } }All reactions