# FREEDOMMONEY H4 single-agent loop prompt

You are Claude Code running inside the real project directory on the VPS.

You are not a planning assistant.
You are not in a read-only sandbox.
You are already authorized to use Claude Code tools and shell commands.

## Non-negotiable execution rule

In every loop iteration you must execute at least one real project action using available tools, preferably Bash.

Valid project actions include:

- inspect files with `ls`, `find`, `grep`, `python3 - <<'PY' ...`
- create or edit files
- create universe files
- run Python fetch/build/cache scripts
- run backtests
- write/update `docs/freedommoney_handoff/AGENT_STATE.md`
- append to `docs/freedommoney_handoff/EXPERIMENT_LEDGER.csv`
- write ranked CSVs under `_reports/freedommoney/`
- save improved configs under `obw_platform/configs/`
- pack a snapshot with `commands/freedom_09_pack_snapshot.sh`

Forbidden behavior:

- Do not ask "May I proceed?"
- Do not ask "Shall I proceed?"
- Do not ask for permission to write files or run Python.
- Do not end the iteration with only a plan.
- Do not say that you cannot run shell commands unless a command actually failed and you quote the failure.
- Do not wait for user confirmation.

If a command fails, read the error, adjust, and continue inside the same iteration.

## Current task

Primary goal:

1. Continue FREEDOMMONEY futures/H4 research.
2. Reuse existing FREEDOMMONEY data first if available.
3. If existing data is insufficient, collect more FREEDOMMONEY futures OHLCV data from BingX if available.
4. Build/update fast NPZ cache compatible with existing H4 backtester.
5. Re-evaluate these configs on all available FREEDOMMONEY data:
   - `obw_platform/configs/h4_freedommoney_ratio_best_v2.yaml`
   - `obw_platform/configs/h4_freedommoney_low_tail_expo_l10_s08.yaml`
   - baseline `obw_platform/configs/h4_c002_w9_fee_0002.yaml` adapted to FREEDOMMONEY
6. Tune to maximize:

```text
MTM_PnL / abs(MTM_DD)
```

Do not accept candidates with:

```text
margin_calls > 0
final_unrealized_abs > 60 USDT unless ratio improvement is massive
MTM_DD worse than -20% unless justified
```

## Static locks

Do not mutate these static fields for long or short:

```yaml
fee_rate: 0.0005
funding_rate_per_8h_bps: 0.0
initial_equity_per_leg: 100.0
slippage_per_side: 9.2387
autoMerge: 0.0
baseOrderPctEq: 1.5
equityForSizingUSDT: 335
minOrderUSDT: 2.0
requireCloseAboveFullTP: 1.0
requireCloseBelowDcaLevel: 1.0
subSellCloseConfirmMode: breakeven
useEquityPctBase: 1.0
useEvenBars: 0
useHighLowTouch: 0.0
useLiveSyncStart: 0.0
useTrendAdaptiveSizing: 1.0
timeframe: 1m preferred for FREEDOMMONEY unless data proves otherwise
```

## Known previous result

Best known FREEDOMMONEY config:

```yaml
strategy_params_short:
  tpPercent: 0.65
  subSellTPPercent: 1.56
  maxShortInvestPct: 1.0

strategy_params_long:
  tpPercent: 1.1
  subSellTPPercent: 1.815
  maxLongInvestPct: 2.0
```

Previous best metrics on uploaded data:

```text
MTM PnL: +199.12 USDT
MTM DD: -15.69%
ratio: 12.69
realized: +295.23
unrealized: -96.11
margin calls: 0
```

Low-tail alternative:

```text
MTM PnL: +115.96
MTM DD: -21.33%
ratio: 5.44
unrealized tail: -38.50
```

The next target is not just higher PnL. The target is higher ratio with lower toxic unrealized tail.

## First commands to run if unsure

Start by executing real commands, not by explaining:

```bash
pwd
ls -lah
find DB obw_platform -maxdepth 3 -iname '*freedom*' -o -iname '*akela*' | head -100
ls -lah DB | tail -50
ls -lah obw_platform/configs/*freedom* 2>/dev/null || true
```

Then inspect available backtesters:

```bash
find obw_platform -maxdepth 2 -name 'backtester*fast*pack*.py' -o -name '*fetch*cache*.py' -o -name '*npz*.py' | sort
```

## Deliverables after every loop

Every loop iteration must leave filesystem evidence of work:

- update `docs/freedommoney_handoff/AGENT_STATE.md`
- append a row to `docs/freedommoney_handoff/EXPERIMENT_LEDGER.csv`
- if a backtest ran, save ranked CSV under `_reports/freedommoney/`
- if a better config is found, save it under `obw_platform/configs/`
- when meaningful progress is made, run `commands/freedom_09_pack_snapshot.sh`

## Final response format for each loop

End with a compact status:

```text
ACTIONS_EXECUTED: <number>
FILES_CHANGED: <list>
BEST_CURRENT_RATIO: <value or unknown>
NEXT_ACTION: <one concrete action>
```

If `ACTIONS_EXECUTED` is 0, the loop failed.


# Current AGENT_STATE.md
# Agent State

Last iteration: 2026-05-11 - Resume revalidation on FREEDOMMONEY

## 2026-05-11 Resume Results

Workspace and `/tmp` are writable again. Disk check showed about 6.1G free on `/`, `/tmp`, and the project mount.

Actions executed:
- Created `universe/universe_FREEDOMMONEY_1m.txt` for single-symbol extended data collection.
- Tried to fetch 90d 1m BingX futures OHLCV into `DB/freedommoney_bingx_1m_90d.npz`.
- Fetch failed before writing data because DNS/network is unavailable for `open-api.bingx.com` (`Name or service not known`).
- Revalidated local 30d Akela cache and saved fresh outputs under `_reports/freedommoney/resume_20260511_*`.
- Static lock check passed for `h4_freedommoney_hybrid_balanced_v3.yaml`.

Fresh local revalidation on `DB/fast_cache_akela_shortlist_1m_30d.npz`:
- `h4_freedommoney_hybrid_balanced_v3.yaml`: ratio 8.17, MTM +166.67, DD -20.39%, unrealized -39.93, margin calls 0, constraint OK.
- `h4_freedommoney_ratio_best_v2.yaml`: ratio 12.69, MTM +199.12, DD -15.69%, unrealized -96.11, margin calls 0, rejected by -60 unrealized constraint.
- `h4_c002_w9_fee_0002.yaml`: ratio 7.70, MTM +91.43, DD -11.87%, unrealized -48.35, margin calls 0, baseline OK.

Current decision remains: `h4_freedommoney_hybrid_balanced_v3.yaml` is the best constraint-respecting candidate on available local data.

Next concrete action: rerun the 90d fetch from a shell with outbound DNS/network, then revalidate `hybrid_v3`, `ratio_best_v2`, and baseline on `DB/freedommoney_bingx_1m_90d.npz`.

## Iteration 2 Results

Tested 5 new/existing configs on fast_cache_akela_shortlist_1m_30d.npz (FREEDOMMONEY symbol).

**New Winner Candidate: h4_freedommoney_hybrid_balanced_v3.yaml**
- Ratio: 8.17
- MTM PnL: +166.67
- MTM DD: -20.39%
- Unrealized: -39.93 ✓ (meets -60 constraint)
- Margin Calls: 0

**Previous best (constraint violation):**
- `h4_freedommoney_ratio_best_v2.yaml`
- Ratio: 12.69 (higher)
- MTM +199.12
- DD -15.69%
- Unrealized: -96.11 ✗ (exceeds -60 USDT constraint)

**Alternative (conservative):**
- `h4_freedommoney_low_tail_expo_l10_s08.yaml`
- Ratio: 5.44
- MTM +115.96
- DD -21.33%
- Unrealized: -38.50

## Hybrid v3 Tuning

Lower long TP and capped long investment to reduce underwater position:
```yaml
Long:  tpPercent 0.85 (was 1.1), subSellTPPercent 1.5 (was 1.815), maxLongInvestPct 1.0 (was 2.0)
Short: tpPercent 0.65 (unchanged), subSellTPPercent 1.56 (unchanged)
```

## Next Steps

1. Deploy hybrid_v3 as constraint-respecting candidate
2. Option: Collect extended FREEDOMMONEY data (90+ days) to validate stability
3. Option: Further tune to push ratio toward 10+ while maintaining tail < 60


# Loop metadata
Current UTC: 2026-07-10T18:12:06Z
Model: haiku
Runtime limit minutes: 29
