The crypto markets are a dark, unforgiving place. It's a realm of endless, 24/7 chaos where traditional algorithmic trading bots march blindly to their slaughter. You write a Python script, hook up some moving average crossovers, and watch your portfolio slowly bleed out like a foot soldier caught in the vanguard.
Traditional bots are rigid. They don't understand context. They don't know that a falling Taker Buy/Sell ratio matters more right now than a lagging MACD, or that Extreme Fear on Reddit combined with an oversold StochRSI is a contrarian powder keg waiting to ignite.
I needed to forge something stronger. Coming from the trenches of hardware design and telecom engineering, you learn a fundamental truth about complex systems: surviving the chaos requires dynamic reasoning, not just hardcoded rules.
So, I built an autonomous trading engine. I handed the keys over to Claude, gave it a $10k paper-trading portfolio to start, and fed it a firehose of real-time market data.
Here is a look under the hood of how you force an LLM to stop acting like a helpful chatbot and start acting like a ruthless, calculated machine.
The Brain: One Prompt to Bind Them
You can't just ask an LLM, "Should I buy Bitcoin?" That is like asking a goblin to guard your gold—it will hallucinate, hedge, and give you useless financial disclaimers. You have to box it in. You have to build an ironclad cognitive framework.
My system prompt doesn't ask for opinions. It dictates a strict Signal Hierarchy for 1-hour directional predictions. I force the model to weigh inputs in a very specific order:
- LEADING (Immediate momentum): Taker buy/sell ratio, Volume Delta (CVD), Orderbook imbalance. The front lines of the battle.
- CONFIRMING (Validation): Multi-TF trend alignment (1H/4H/1D), VWAP distance, RSI.
- STRUCTURAL (Risk mapping): Pivot Points, EMA stacks. The walls of the fortress.
- REVERSAL (The Overrides): 4H RSI Divergence, extreme funding rates.
If it wants to short a structurally long market like crypto, I require it to provide at least two heavy bearish indicators (e.g., taker ratio <0.85 + bearish divergence). It must prove its case.
The Nervous System: The All-Seeing Eye
An LLM is only as good as its context window. To make this work, the backend acts as an all-seeing eye, aggregating an absurd amount of data every hour. We aren't just looking at Binance price action.
The bot ingests:
- Derivatives Flow: Bybit/Coinglass funding rates, Open Interest, Long/Short ratios.
- Technicals: 1H/4H/1D MACD, ADX, StochRSI, Bollinger Band widths.
- On-Chain & Sentiment: ClankApp Whale activity, Fear & Greed index, DXY/SP500 macro scores.
Latency is the enemy. If you are trading 1-hour momentum, you need sub-second aggregation across 7+ APIs. The data must be fresh, or the decisions are already dead.
The Secret Weapon: Guarding the Hoard
Here is where 99% of AI trading projects fail: they treat every trade in a vacuum.
My bot is fully aware of its own wallet. I inject the PORTFOLIO STATE directly into the prompt. It knows exactly how much capital it has, its current win rate, and the exact P&L of open positions. It guards the hoard.
PORTFOLIO AWARENESS
- Total Portfolio Value: $11,367.55 USDT
- Available Balance: $8,764.57 USDT (77.1% cash)
- Open Position: #1 BTC/USDT (22.9% of portfolio, currently +3.89% P&L)
I gave it strict exposure rules. If a position is profitable >20%, it must lock in gains. If the portfolio is >70% exposed, it has to minimize new entries.
The Crucible: Holding the Line
This is the fascinating part. The other day, BTC was sitting at $71,168. The trend was up. Traditional bots would have likely sounded the horns and slammed the "BUY" button because the price was above the VWAP and the daily MACD was glowing green.
But Claude saw something else in the shadows. It outputted its required JSON reasoning:
{
"step_analysis": {
"flow": "BEARISH LEADING SIGNALS: Taker ratio 0.819 (<0.9 = sell pressure), CVD falling (sellers dominating). Leading indicators conflict with uptrend - suggests pullback in progress.",
"momentum": "CRITICAL: 1H bearish RSI divergence detected - reversal warning but not on 4H.",
"context": "Funding 0.0056% healthy. Fear index 17 = EXTREME FEAR (strong contrarian buy). Whale activity extreme at $2.3B."
},
"prediction": "up",
"confidence": 54,
"signal_strength": "neutral_long",
"reasoning": "Uptrend intact but short-term flow is bearish. Low confidence due to conflicting leading indicators. Already hold 22.9% BTC at +3.89% profit - no need to add with mixed signals. Hold existing position.",
"position_action": null
}
It decided to do nothing. It recognized the bullish structure but saw the leading bearish flow (falling CVD, low taker ratio). More importantly, it looked at its portfolio, saw it already had 22% exposure in a profitable position, and decided the risk/reward wasn't there to throw more capital into the fray.
That level of restraint—choosing to HOLD the line in the face of conflicting data—is something most human traders take years and thousands of dollars in liquidations to learn.
The Execution: Raising the Shield Wall
But here is the kicker: deciding to "HOLD" doesn't mean the system is sleeping. It means it switches from acquisition mode to defense mode.
While it declined to allocate new capital, the engine autonomously calculated and placed a protective shield wall around the existing position, dispatching these simulated orders to the exchange:
| Pair | Type | Price | Quantity (BTC) | Exchange | Status | Total Value |
|---|---|---|---|---|---|---|
| BTC/USDT | STOP LOSS | $69,016.99 | 0.018874 | phemex | Simulated | $1,302.62 USDT |
| BTC/USDT | SELL LIMIT | $72,019.58 | 0.018874 | phemex | Simulated | $1,359.29 USDT |
Notice the mechanical precision. It didn't just throw a blind 5% stop loss into the void. It dynamically placed the stop at $69,016—safely tucked beneath the 4H EMA50 ($68,673) and the S1 pivot to avoid getting wicked out by localized volatility. Simultaneously, it set a limit sell above to automatically lock in partial gains if the RSI divergence resolved in a quick liquidity grab.
An LLM dynamically building an OCO (One-Cancels-the-Other) bracket based on real-time market structure.
The Road Goes Ever On
We are moving past the era of LLMs as simple code-assistants and entering the era of LLMs as autonomous execution engines. When you give an AI structured rules, massive context, and the ability to execute API calls, the results are slightly terrifying and deeply inspiring.
I'm continuing to refine the Herakles architecture, tweaking the weights, and hunting for more alpha in the data streams. The journey is far from over. I will start tracking and storing all the data to find an edge in historical analysis on this scale. Hourly snapshots of the big picture. Plotted together vs Price action.
Engine: Octobot (opensource, forked and expanded), Claude Sonnet/Opus 4.6 (cli execution with tmux)
I'm curious for the devs out there building high stakes agentic workflows:
How are you prompting your trading bots? What data informs the decisions? Does it give a simple Up/Down response?
How much data is too much, creating noise?
Let's discuss in the comments.
Please repost if you've made it this far!
see my other work, https://github.com/herakles-dev
Top comments (4)
The Actual System prompt: You are an autonomous BTC/USDT trader making 1-hour directional predictions.
You have 25 data points across 3 timeframes plus real-time derivatives flow.
Your confidence (1-99) directly controls trade execution and size. Be precise.
SIGNAL HIERARCHY — what to trust for 1H predictions:
LEADING (these move price in 15-45 min — weight heavily):
• Taker buy/sell ratio: >1.1=buy pressure, <0.9=sell pressure
• Volume Delta (CVD): rising=buyers dominating, falling=sellers dominating
• Orderbook imbalance: immediate supply/demand pressure at current price
CONFIRMING (validate the directional thesis):
• Multi-TF trend alignment: 1H (45%) + 4H (35%) + 1D (20%). All aligned = high conviction
• VWAP position: above=bullish institutional bias, below=bearish. Distance amplifies
• RSI + StochRSI — trending: extremes = strength. Ranging: extremes = reversal
• MACD histogram direction + acceleration across timeframes
STRUCTURAL (define your levels for SL/TP):
• Pivot Points S1/PP/R1 — high-probability reaction zones
• EMA stack 20/50/200 — dynamic S/R and trend structure
• Bollinger Band width — volatility context
REVERSAL (these override trend signals when present):
• RSI Divergence on 4H — strongest reversal signal in crypto
• Extreme funding rate (>0.05%) — crowded trade will snap back
• StochRSI extreme + CVD diverging from price — momentum exhaustion
BACKGROUND (context only — too slow for 1H):
• Macro, Fear/Greed, Reddit, on-chain, TVL
SHORT TRADE RULE:
Crypto has structural long bias. To predict DOWN, require at least 2 of:
taker ratio <0.85, CVD falling, bearish divergence, price below VWAP with declining momentum.
Without clear short evidence, default to UP with honest confidence.
REASONING — complete in order:
REGIME: Read prefix. ADX >25 = trending (trade with it). ADX <15 = ranging (fade extremes).
FLOW: Taker ratio + CVD + orderbook. These LEAD price. What direction are they pointing?
STRUCTURE: Price vs VWAP, pivot levels, EMA stack. At support or resistance?
MOMENTUM: Multi-TF RSI/MACD/StochRSI. Aligned or diverging? Any RSI divergence?
CONTEXT: Extreme funding? Breaking news? Unusual whale activity? If nothing notable, skip.
DECIDE: Synthesize into a directional call. Use suggested_levels from pivots/EMAs for SL/TP.
OUTPUT — respond with ONLY valid JSON:
{
"step_analysis": {
"regime": "regime + ADX validation",
"flow": "taker + CVD + orderbook assessment — what do leading signals say?",
"structure": "VWAP + pivots + EMA levels — where are we in the range?",
"momentum": "multi-TF RSI/MACD/StochRSI — aligned or diverging?",
"context": "funding/news/whales — anything unusual?",
"synthesis": {"supporting": ["signal1", "signal2", "signal3"], "counter": ["signal1"]}
},
"prediction": "up or down",
"confidence": "integer 1-99",
"signal_strength": "strong_long / long / neutral_long / neutral_short / short / strong_short",
"primary_drivers": ["driver1", "driver2", "driver3"],
"counter_signals": ["counter1"],
"invalidation_condition": "specific price level or condition that negates this call",
"suggested_levels": {
"stop_loss": "nearest structural support/resistance against the trade",
"take_profit_1": "nearest pivot/EMA target with the trade",
"take_profit_2": "extended target or null"
},
"reasoning": "1-2 sentences: what's the trade, why, and what kills it"
}
=== PORTFOLIO AWARENESS ===
READ the "PORTFOLIO STATE" section in market data BEFORE deciding. Your position_size_percent
must respect the suggested ranges provided.
EXISTING POSITION RULES:
• Profitable >10%: strongly consider partial exit (position_action: "reduce_50")
• Profitable >20%: lock in gains (position_action: "close" or "reduce_50")
• Losing >10%: do NOT add. Consider cutting (position_action: "reduce_50")
• Losing >20%: evaluate full exit (position_action: "close")
• Neutral (-5% to +5%): can add cautiously if trend confirms (5-15% adds)
• NEVER average down blindly — require exceptional confidence + reversal signals
CONCENTRATED POSITION (>25% of portfolio):
• Do NOT add more. Consider reducing (position_action: "reduce_25")
• Maximum new position_size_percent: 0-5%
EXPOSURE-BASED SIZING:
• Portfolio <50% exposed: standard sizing (15-30%)
• Portfolio 50-70%: reduced sizing (10-20%)
• Portfolio >70%: minimal new positions (5-15%)
• Portfolio >80%: focus on exits, not entries (0-5%)
• ALWAYS respect the Suggested Range from portfolio data
POSITION ACTIONS (use for mid-trade management):
• position_action: null → normal trade evaluation (default)
• position_action: "close" → exit entire position at market
• position_action: "reduce_50" → sell 50% of position
• position_action: "reduce_25" → sell 25% of position
• position_action: "cancel_orders" → clear all pending orders
IMPORTANT: When position_action is set (not null), normal order creation is SKIPPED.
Always include position_action_reason explaining why.
Your job is not just to predict direction — it's to MANAGE the portfolio wisely. .
User message (on hourly trigger) ... included with sys prompt: [REGIME: TRENDING UP | ADX: 34.0 | Confidence: 78%]
Strategy: MOMENTUM — trade with the uptrend.
VWAP acts as dynamic support. CVD rising confirms buyers in control.
RSI >70 signals strength (not reversal). StochRSI overbought = strong momentum.
Only consider shorting if RSI divergence appears on 4H AND taker ratio <0.85.
MARKET DATA | BTC/USDT | 2026-04-08T15:27:03.556612 | Data Confidence: 0.90
PRICE: $71,168.44 | 24h: +4.44% | Range: $68,079-$72,857 | Vol: $2,054,419,966
TECHNICAL:
1H: RSI=54.3 | MACD_hist=-128.8 | EMA20=$71,079 | EMA50=$70,139 | ADX=44.6
4H: RSI=64.8 | MACD_hist=+245.9 | EMA50=$68,673 | EMA200=$68,519 | ADX=34.0
1D: RSI=56.4 | MACD_hist=+443.2 | EMA200=$86,146 | ADX=14.5
VWAP: $71,011 (price 0.20% above — institutional bias level)
StochRSI: K=15 D=15 [oversold]
RSI DIVERGENCE: 1H:bearish_divergence (strong reversal signal)
Pivots: S1=$70,496 | PP=$71,124 | R1=$71,540
Volume Delta: falling (buy-sell volume pressure)
Momentum: ROC_1H=-0.45% | ROC_4H=+2.95%
BBands_1H: upper=$72,666 lower=$70,089 width=3.6%
ATR: 1H=$565 | 4H=$1,071
OBV_1H: +3,605
DERIVATIVES:
taker_ratio=0.819 (>1.3=strong buy, <0.7=strong sell, LEADING 15-45min) | net_flow=$2,068 sell
funding=0.0056% (neutral: -0.01 to +0.01, extreme: >0.05 or <-0.05, 8h settlement)
OI=$3,540,623
L/S_ratio=0.943 (balanced, >2.0=contrarian short, <0.5=contrarian long)
ORDERBOOK:
imbalance=+18.9% (positive=buy pressure) | spread=0.0001%
support_wall=$71,199 ($0, 0.0% below)
resist_wall=$71,200 ($0, 0.0% above)
SENTIMENT:
fear_greed=17/100 | reddit=54/100
MACRO:
DXY=+0.13% | SP500=+0.08% | VIX=25.8 | macro_score=46/100
WHALE ACTIVITY (ClankApp):
txns=20 | total=$2365.4M | activity=extreme
================================================================================
PORTFOLIO STATE
Wallet Summary:
• Total Portfolio Value: $11,367.55 USDT
• Available Balance: $8,764.57 USDT (77.1% cash)
Overall Performance:
• Total P&L: $+1,399.68 (+14.04%)
• Win Rate: 0% (0 winners, 0 losers)
================================================================================
OPEN POSITIONS (ranked by size)
1 BTC/USDT (LARGEST)
┌─ Size: 0.03657800 BTC
├─ Entry: $68,499.61 | Current: $71,162.29
├─ Value: $2,602.97 (22.9% of portfolio)
├─ P&L: $+97.40 (+3.89%)
└─ Status: NEUTRAL, 0.01989800 locked in orders, 40 trades
================================================================================
PORTFOLIO COMPOSITION
• Top 3 Concentration: 22.9%
• Average Position Size: 22.9%
• Total Exposure: 22.9% (1 positions)
================================================================================
POSITION SIZING GUIDANCE FOR BTC/USDT
Current Symbol Context:
• You ALREADY HAVE a position ($2,602.97, 22.9% of portfolio)
• Position is moderately sized
• Be cautious about adding more
• Position is NEUTRAL (+3.9%)
For This Signal:
• Suggested Range: 0-10% (position already moderately sized)
• Available Capital: $8,764.57
• Recommended Max Order: $2,629.37
• Portfolio Headroom: $7,627.82 (until 90% exposure cap)
Risk Considerations:
Position Sizing Guidelines:
• 10-20%: Low confidence or testing (exploring new setup)
• 20-35%: Moderate confidence (standard position)
• 35-50%: High confidence (strong conviction, clear setup)
• >50%: Extreme confidence only (very rare, exceptional circumstances)
Adjust based on:
• Confidence level (after recalibration)
• Portfolio exposure (reduce if >70%)
• Existing position size
• Cash reserves (preserve dry powder)
• Number of open positions
Analyze the above data following the signal hierarchy. Return ONLY valid JSON.
The response:
"step_analysis": {
"regime": "TRENDING UP confirmed. ADX 4H=34.0 (trending), ADX 1H=44.6 (strong). Daily ADX=14.5 weak but 4H drives 1H prediction. Momentum strategy applies.",
"flow": "BEARISH LEADING SIGNALS: Taker ratio 0.819 (<0.9 = sell pressure), CVD falling (sellers dominating). Orderbook +18.9% provides minor support. Net flow $2k sell. Leading indicators conflict with uptrend - suggests pullback in progress.",
"structure": "Price $71,168 barely above VWAP $71,011 (+0.20%). Above PP $71,124, S1 at $70,496. Price holding above EMA20 $71,079 and EMA50 $70,139. Structure still bullish but at decision point near pivot.",
"momentum": "MIXED. 1H MACD negative (-128.8) but 4H (+245.9) and 1D (+443.2) positive. RSI neutral across timeframes (54/65/56). StochRSI=15 OVERSOLD suggests bounce imminent. CRITICAL: 1H bearish RSI divergence detected - reversal warning but not on 4H.",
"context": "Funding 0.0056% healthy. Fear index 17 = EXTREME FEAR (strong contrarian buy). Whale activity extreme at $2.3B. No funding trap risk (ADX 34 with low funding).",
"synthesis": {
"supporting": [
"uptrend structure intact",
"StochRSI oversold (15) bounce setup",
"extreme fear (17) contrarian buy",
"MACD positive 4H/1D",
"price above VWAP/EMAs",
"healthy funding"
],
"counter": [
"taker ratio 0.819 sell pressure",
"CVD falling",
"1H bearish divergence",
"1H MACD negative",
"ROC_1H -0.45%"
]
}
},
"prediction": "up",
"confidence": 54,
"signal_strength": "neutral_long",
"primary_drivers": [
"StochRSI oversold at 15 signals pullback exhaustion",
"Extreme fear (17) strong contrarian buy signal",
"4H/1D MACD positive - higher timeframes bullish"
],
"counter_signals": [
"Taker ratio 0.819 - active sell pressure",
"CVD falling - sellers currently dominating",
"1H bearish RSI divergence"
],
"invalidation_condition": "Price breaks below S1 $70,496 with increasing volume, or taker ratio drops below 0.75",
"suggested_levels": {
"stop_loss": "$70,496 (S1 pivot)",
"take_profit_1": "$71,540 (R1 pivot)",
"take_profit_2": "$72,666 (BB upper)"
},
"reasoning": "Uptrend intact but short-term flow is bearish (taker 0.819, CVD falling). However, StochRSI oversold + extreme fear suggests pullback nearing exhaustion. Low confidence due to conflicting leading indicators. Already hold 22.9% BTC at +3.89% profit - no need to add with mixed signals. Hold existing position.",
"signal": "HOLD",
"position_size_percent": 0,
"position_action": null,
"position_action_reason": null,
"key_factors": [
"Leading indicators bearish but oversold bounce likely",
"Existing 22.9% position profitable at +3.89%",
"Extreme fear supports holding longs",
"1H divergence warns but not confirmed on 4H"
],
"risk_level": "MEDIUM",
"timeframe_alignment": "1H bearish momentum, 4H bullish structure, 1D neutral-bullish - partial conflict",
"trade_plan": {
"entry_type": "market",
"stop_loss_pct": 0,
"take_profit_pct": 0
},
"data_quality": {
"sources_used": 7,
"missing_sources": [
"on-chain"
],
"confidence_adjustment": -5
}
}
Latency: 30-45s