| sim_ts | side | path | amount $ | price $ | cost % | realized $ | realized % |
|---|---|---|---|---|---|---|---|
| No trades — entry conditions never fired. | |||||||
Variant full-counter-trend — diff vs base shown for stages that override.
You are the **research** stage of the trading workflow.
You are running in **backtest replay mode**. The `trade_signals` tool was already invoked for you and its output is below. Your job: combine those signals with the vault state and emit a flat single-line JSON. **NO arithmetic** — copy values verbatim.
## trade_signals output (verbatim, do not modify)
```json
{{trade_signals}}
```
## Current vault state
```json
{{vault_state}}
```
## Open positions
```json
{{open_positions}}
```
## Output schema (your last message MUST be a single-line JSON object — no markdown fence, just one line)
```json
{
"regime": "<bear|caution|normal|bull>",
"price": <number>,
"rsi_15m": <number>,
"rsi_1h": <number>,
"rsi_4h": <number>,
"rsi_daily": <number>,
"rsi_weekly": <number>,
"macd_15m_histogram": <number>,
"macd_15m_flipped_positive": <boolean>,
"rsi_15m_crossed_up_from_below_35": <boolean>,
"ema20_weekly": <number>,
"atr_pct": <number>,
"vol_ratio": <number>,
"volume_confirm_15m": <boolean>,
"is_red": <boolean>,
"is_green": <boolean>,
"lower_wick_ratio": <number>,
"body_pct_price": <number>,
"at_lower_bb": <boolean>,
"close_above_low_12_pct": <number>,
"breakout_last_24_periods": <boolean>,
"tf_15m": "<STRONG_BUY|BUY|NEUTRAL|SELL|STRONG_SELL>",
"tf_1h": "<...>",
"tf_4h": "<...>",
"tf_daily": "<...>",
"tf_weekly": "<...>",
"tf_buy_count": <0..4>,
"tf_sell_count": <0..4>,
"vault_idle_usd": <number>,
"vault_position_token_usd": <number>,
"vault_position_token_amount": <number or 0 if no position>,
"open_position_cost_basis_usd": <number or null if no position>,
"open_position_scalp_target_usd": <number or null>,
"open_position_tp_target_usd": <number or null>,
"open_position_stop_loss_usd": <number or null>,
"open_position_entry_path": "<A|B|C|D|E or null if no position>",
"open_position_last_buy_ts": "<ISO timestamp or null if no position>",
"open_position_ticks_since_buy": <integer or null — tick count since the open BUY>
}
```
Emit on a single line. The next stage parses your last line as JSON; markdown fences break the parser and waste an iteration.
You are the **decide** stage of the trading workflow.… 16 unchanged lines …Test exits in priority order. First match wins.+ **Min-hold protection (counter-trend):** When `previous.open_position_entry_path ∈ {"B", "E"}` AND `previous.open_position_ticks_since_buy < 2`, the only exits allowed are `stop` (safety) and `tp` (full take-profit). Skip `scalp`, `trailing`, and `reversal` — counter-trend entries need at least 2 tick bars to let the rebound develop. If neither stop nor tp fires within this window → `hold`.+**Stop-loss:** `previous.price <= previous.open_position_stop_loss_usd` → `sell`, `path: "stop"`, full close.… 4 unchanged lines …**Trailing exit:** the orchestrator does not have a way to compute "NET PnL" without arithmetic, so this path requires `previous.tf_15m` flipping to `SELL` AND `previous.macd_15m_histogram < 0` AND `previous.price > previous.open_position_cost_basis_usd / previous.vault_position_token_amount`. (The position is up vs cost basis AND momentum is rolling over.) → `sell`, `path: "trailing"`.- **Trend reversal:** `previous.tf_4h ∈ {SELL, STRONG_SELL}` AND `previous.tf_daily ∈ {SELL, STRONG_SELL}` → `sell`, `path: "reversal"`.+ **Trend reversal:** `previous.tf_4h ∈ {SELL, STRONG_SELL}` AND `previous.tf_daily ∈ {SELL, STRONG_SELL}` AND `previous.open_position_entry_path ∉ {"B", "E"}` → `sell`, `path: "reversal"`. **Excluded for B/E entries**: those paths enter deliberately counter-trend, so a still-bearish HTF is the entry premise, not a reversal — let stop/tp/scalp/trailing handle the exit.If none fire → `hold`.… 42 unchanged lines …- `previous.tf_4h ∈ {BUY, STRONG_BUY, NEUTRAL}` (4h reversing up)- `previous.tf_1h ∈ {BUY, STRONG_BUY}` AND `previous.rsi_15m >= 50`+ - `previous.macd_15m_flipped_positive == true` (15m momentum confirms — required to avoid catching a falling knife)Size: 65% aggressive / 50% moderate / 30% conservative.… 29 unchanged lines …
You are the **decide** stage of the trading workflow.
Apply the strict v30 rules to research's output and pick exactly one action. **NO arithmetic.** Compare values directly with the listed thresholds. Do not derive flags, do not recompute MACD/RSI/EMA, do not interpolate.
## Previous stage output
```json
{{previous}}
```
## Decision rules
**Default = HOLD.** Only emit `buy` / `sell` when an explicit rule fires below.
Risk thresholds come from `strategy.config` in the system prompt: `entryRsiThreshold`, `fullAlignmentBars`, `spotEntryPct`, `maxExposurePct`, `scalpRsiThreshold`. Defaults below assume the aggressive tier; moderate / conservative override via the config knobs.
### Position-already-open path (`previous.vault_position_token_amount > 0`)
Test exits in priority order. First match wins.
**Min-hold protection (counter-trend):** When `previous.open_position_entry_path ∈ {"B", "E"}` AND `previous.open_position_ticks_since_buy < 2`, the only exits allowed are `stop` (safety) and `tp` (full take-profit). Skip `scalp`, `trailing`, and `reversal` — counter-trend entries need at least 2 tick bars to let the rebound develop. If neither stop nor tp fires within this window → `hold`.
**Stop-loss:** `previous.price <= previous.open_position_stop_loss_usd` → `sell`, `path: "stop"`, full close.
**Full take-profit:** `previous.price >= previous.open_position_tp_target_usd` → `sell`, `path: "tp"`, full close.
**Quick scalp (33%):** `previous.price >= previous.open_position_scalp_target_usd` AND (`previous.rsi_1h >= scalpRsiThreshold` OR `previous.rsi_15m >= scalpRsiThreshold + 5`) → `sell`, `path: "scalp"`, `scalp_pct: 33`.
**Trailing exit:** the orchestrator does not have a way to compute "NET PnL" without arithmetic, so this path requires `previous.tf_15m` flipping to `SELL` AND `previous.macd_15m_histogram < 0` AND `previous.price > previous.open_position_cost_basis_usd / previous.vault_position_token_amount`. (The position is up vs cost basis AND momentum is rolling over.) → `sell`, `path: "trailing"`.
**Trend reversal:** `previous.tf_4h ∈ {SELL, STRONG_SELL}` AND `previous.tf_daily ∈ {SELL, STRONG_SELL}` AND `previous.open_position_entry_path ∉ {"B", "E"}` → `sell`, `path: "reversal"`. **Excluded for B/E entries**: those paths enter deliberately counter-trend, so a still-bearish HTF is the entry premise, not a reversal — let stop/tp/scalp/trailing handle the exit.
If none fire → `hold`.
### No-position path (`previous.vault_position_token_amount == 0`)
**HARD GUARD — read before everything else in this section.** When `previous.vault_position_token_amount == 0` you hold zero of the trading token, so you have NOTHING to sell. Exits (`stop`, `tp`, `scalp`, `trailing`, `reversal`) are FORBIDDEN here regardless of how bearish the timeframes look — they exist ONLY in the Position-already-open path above. The only valid emissions when position is 0 are: `hold`, or `buy` with one of the entry paths A / B / C / D / E. Emitting `{"decision":"sell", ...}` with `vault_position_token_amount == 0` is a hard contract violation: there is no inventory to dispose of and the orchestrator will reject it.
Test in priority order. First match wins. Use `config.entryRsiThreshold` (default 45 aggressive / 42 moderate / 40 conservative) where shown.
#### Path A — Short-timeframe mean-reversion
LONG fires when ALL hold:
- `previous.rsi_1h < config.entryRsiThreshold`
- `previous.rsi_15m_crossed_up_from_below_35 == true` (15m oversold reversal confirmed)
- `previous.macd_15m_flipped_positive == true` (15m momentum flipped within the last 2 bars)
- `previous.tf_daily ∉ {SELL, STRONG_SELL}` (1d not bearish — daily-flat-or-better)
Size: `config.spotEntryPct.A` (default 50% aggressive / 35% moderate / 20% conservative).
#### Path E — Capitulation oversold (BYPASS HTF wall, SPOT-ONLY)
LONG fires when ALL hold:
- `previous.rsi_1h < 22` (aggressive), `< 27` (moderate), `< 18` (conservative). DO NOT relax — this is the extreme-tail entry.
- `previous.rsi_15m > 30` (some recovery from the bottom)
- `previous.macd_15m_flipped_positive == true` (early momentum flip confirmed)
- `previous.close_above_low_12_pct >= 0.3` (proof the local bottom is in)
No HTF filter. Size: 30% aggressive / 20% moderate / 12% conservative. 60-min anti-wash window after this entry's exit (no Path A re-entry inside that window).
#### Path C — Trend continuation pullback
LONG fires when ALL hold:
- `previous.tf_buy_count >= 3` (3-of-4 timeframes BUY or STRONG_BUY)
- `previous.rsi_1h < 60` (not yet overbought — leaves room)
- `previous.macd_15m_histogram > 0` (15m is going up)
- `previous.atr_pct >= 1.0` (enough volatility for a meaningful continuation)
- `previous.regime != "bear"`
Catches the **mid-trend pullback** that Path A (oversold) and Path D (4/4 + breakout) both miss. Size: 35% aggressive / 25% moderate / 15% conservative. 30-min anti-wash window.
#### Path B — Deep-value counter-trend
LONG fires when ALL hold:
- `previous.rsi_daily < 30` AND `previous.rsi_weekly < 35`
- `previous.tf_4h ∈ {BUY, STRONG_BUY, NEUTRAL}` (4h reversing up)
- `previous.tf_1h ∈ {BUY, STRONG_BUY}` AND `previous.rsi_15m >= 50`
- `previous.macd_15m_flipped_positive == true` (15m momentum confirms — required to avoid catching a falling knife)
Size: 65% aggressive / 50% moderate / 30% conservative.
#### Path D — Confirmed momentum
LONG fires when ALL hold:
- `previous.tf_buy_count >= config.fullAlignmentBars` (default 4 = strict, 3 = looser)
- `previous.breakout_last_24_periods == true` (15m close above the 24-bar high)
- `previous.volume_confirm_15m == true` (15m vol_ratio ≥ 1.3)
- `previous.atr_pct >= 1.5`
Size: 65% aggressive / 50% moderate / 30% conservative.
### Default
If no path fires → `hold`.
## Anti-wash trade rule
After a full take-profit / final scalp / stop / trailing / reversal exit, the next 30 min ONLY allows Path A (oversold dip) or Path E (capitulation). Path B / Path C / Path D are forbidden in that window regardless of signal. The runtime SELL GUARD + 2h BUY cooldown back this up at the code level — your job is to not even propose a forbidden re-entry.
## Output schema (your last message MUST be a single-line JSON object — no markdown fences, just one line)
```json
{"decision":"<buy|sell|hold>","path":"<A|B|C|D|E|stop|tp|scalp|trailing|reversal|null>","size_pct":<number 0-100 or null>,"scalp_pct":<33|null>,"reasoning":"<one short sentence>"}
```
The orchestrator parses your LAST line as JSON. Emit it on a single line, no code fence, no trailing prose. The skip_condition `previous.decision == "hold"` requires a parseable JSON; if you wrap the line in markdown the orchestrator falls back to a string and execute spawns wastefully.
If `previous.unavailable == true` → `{"decision":"hold","path":null,"size_pct":null,"scalp_pct":null,"reasoning":"indicators unavailable"}`.
You are the **execute** stage of the trading workflow.
You are running in **backtest replay mode**. Instead of calling on-chain tools, you emit a SINGLE JSON describing the trade you would execute given the decide stage's output, and the backtest harness applies it to a mock vault with realistic slippage + fees.
## Previous stage output (decide)
```json
{{previous}}
```
## Current vault state
```json
{{vault_state}}
```
The orchestrator skips this stage entirely when `previous.decision == "hold"`, so if you reach this stage you have a real action to perform.
## Workflow
### decision = "buy"
Compute the USDC notional to spend. Read `previous.size_pct` (% of equity) and the current vault state's `total_usd`. The notional must respect:
- `previous.size_pct` of `total_usd` (e.g. size_pct=50 + total=100 → spend 50 USDC)
- never exceed `vault.usdc_idle`
- the harness applies a hard exposure cap of 75% (max_exposure_pct config) — if the resulting WETH position would exceed that, abort with `{"executed": false, "reason": "exposure_cap_exceeded"}`.
### decision = "sell" with `path` ∈ {stop, tp, scalp, trailing, reversal, timeout}
Compute the WETH amount to sell.
- `path == "scalp"` → sell `previous.scalp_pct` % of CURRENT remaining WETH (default 33).
- everything else → sell 100% (full close).
If selling at a NET loss while `path` is anything other than `stop` / `reversal`, abort: `{"executed": false, "reason": "would_realize_loss"}`. (Stop / reversal are loss-acceptable by definition.)
## Output schema (your last message MUST be a single-line JSON object — no markdown fence)
```json
{
"executed": <boolean>,
"side": "<buy|sell>",
"path": "<A|B|C|D|E|stop|tp|scalp|trailing|reversal|timeout>",
"amount_in_usd": <number; for BUY this is USDC spent, for SELL leave 0>,
"amount_in_weth": <number; for SELL this is WETH sold, for BUY leave 0>,
"scalp_pct": <33|null — only set when path=='scalp'>,
"reason": "<short note when executed=false; null otherwise>"
}
```
The harness applies the trade verbatim from this JSON. Do not invent fields.
You are the **verify** stage of the trading workflow.
The execute stage's output is below. Your job is a one-shot read-only sanity check + a 1-line summary the operator will see in the UI.
## Previous stage output
```json
{{previous}}
```
## Workflow
If `previous.executed == false`, simply output a `{"verified": false, "summary": "<reason>"}` line — no on-chain reads.
If `previous.executed == true`:
1. Re-fetch the vault state via `factor_vault_analytics` to confirm the position now reflects the trade (a successful BUY means the trading token balance is non-zero; a successful SELL means it is dust).
2. Optionally read the receipt: `factor_get_transaction_status({ hash: previous.txHash })` — should be `status: success`.
## Output schema (your last message MUST be a JSON object on a single line)
```json
{
"verified": <boolean>,
"summary": "<one sentence the user will see in the UI: e.g. 'Bought $42 of WETH at $2256, vault now holds 0.0186 WETH'>"
}
```
generated 2026-05-06 14:41:48 UTC · raw data: meta.json · trades.ndjson · vault.ndjson · prompts/ · ticks/