Trading Journal

Prompts

Record and manage futures/stock trades with standardized templates, calculate P&L, analyze performance, search entries, and export journals in Markdown or CSV.

Install

openclaw skills install trading-journal

Trading Journal — 交易日志管理

Record and analyze futures/stock trading journals. Supports structured trade logging, P&L tracking, performance analytics, and multi-format export.

Architecture

Trade Entry → [Journal] → Log → [Analysis] → Stats / Reports
                 ↑                        ↓
           Template Driven          Export (MD/CSV)

Core Workflows

Workflow 1: Log a Trade Entry

Use the standardized template to record a trade:

Template fields:

FieldDescriptionExample
dateTrade date2026-05-20
symbolContract/stock codeIF2606, 000001
directionLong or Shortlong / short
entry_priceEntry price3850.0
exit_priceExit price3900.0
quantityNumber of contracts/shares2
multiplierContract multiplier (futures)300
entry_timeEntry timestamp09:35
exit_timeExit timestamp14:20
feesCommission + slip45.60
strategyStrategy tagtrend_follow
notesFree-text notes"突破前高入场"
tagsCustom tags["股指", "日内"]

Full JSON template:

{
  "date": "2026-05-20",
  "symbol": "IF2606",
  "direction": "long",
  "entry_price": 3850.0,
  "exit_price": 3900.0,
  "quantity": 2,
  "multiplier": 300,
  "entry_time": "09:35",
  "exit_time": "14:20",
  "fees": 45.60,
  "strategy": "trend_follow",
  "notes": "突破前高入场,尾盘止盈",
  "tags": ["股指", "日内", "趋势"]
}

To log a trade:

  1. Ask user for trade details, or accept them in free-text format
  2. Map to the standard template
  3. Append to the daily journal file via the scripts/trade_logger.py script
  4. Calculate P&L and confirm with user

Workflow 2: Calculate P&L

Auto-calculated based on template fields:

Futures P&L:

P&L = (exit_price - entry_price) × quantity × multiplier × direction_sign - fees

Stock P&L:

P&L = (exit_price - entry_price) × quantity - fees

Where direction_sign = 1 for long, -1 for short.

The system handles:

  • Open trades (no exit price — show unrealized P&L using current market price)
  • Partial fills (quantity adjustments)
  • Multi-leg strategies (aggregate P&L)

Workflow 3: Performance Analysis

Run analytics on journal entries using scripts/trade_analyzer.py:

Metrics computed:

MetricFormula
Win Ratewins / total_closed × 100%
Total P&LΣ(closed_trade_P&L)
Avg WinΣ(win_P&L) / wins
Avg LossΣ(loss_P&L) / losses
Profit FactorΣ(gross_profit) / Σ(gross_loss)
Sharpe Ratioavg_return / std_return × √252
Max DrawdownMax peak-to-trough decline
Best/Worst TradeMax/min single trade P&L
Daily AverageTotal P&L / trading_days

Analysis frequency:

  • Daily: Quick summary of today's trades
  • Weekly: Performance trends, strategy comparison
  • Monthly: Full analytics report
  • Custom: Any date range specified by user

Workflow 4: Archive & Search

Journal files are organized by date:

journals/
├── 2026/
│   ├── 2026-05/
│   │   ├── 2026-05-18.json    # Day trades
│   │   ├── 2026-05-19.json
│   │   └── 2026-05-20.json
│   └── 2026-06/
│       └── 2026-06-01.json
└── archive/
    └── 2025-journal.jsonl

Search across journals by:

  • Date range (YYYY-MM-DD to YYYY-MM-DD)
  • Symbol (e.g., IF, IC, CU)
  • Direction (long/short)
  • Strategy tag
  • P&L range
  • Custom text search in notes

Workflow 5: Export

Export journals to preferred format:

FormatUse CaseCommand
MarkdownHuman-readable report, docspython journal_export.py --format md --output report.md
CSVSpreadsheet analysis, importpython journal_export.py --format csv --output trades.csv
JSONData interchange, backuppython journal_export.py --format json --output trades.json

Usage Guide

A) Recording a New Trade

When user says "记一笔交易" or provides trade details:

  1. Parse trade info from user's natural language
  2. Confirm parsed fields with user
  3. Run: python scripts/trade_logger.py add <json_string>
  4. Show calculated P&L and confirmation

Example interaction:

User: 今天IF2606做多2手,3850进场,3900平仓
Agent: 📓 记录交易:
  IF2606 | LONG | 3850 → 3900 | 2手
  P&L: (3900-3850)×2×300 - 费用 = ¥29,954.40
  确认记录?(是/否)

B) Checking Performance

When user asks "看看收益" / "我的交易怎么样":

  1. Determine time range (today/this week/this month/custom)
  2. Run analyzer: python scripts/trade_analyzer.py --range 2026-05-01 2026-05-20
  3. Present formatted results

Example output:

📊 交易绩效报告 (2026-05-01 ~ 2026-05-20)
━━━━━━━━━━━━━━━━━━━━━━━━━━━
  总交易数:  24
  胜率:      70.83% (17/24) 🟢
  总盈亏:    +¥186,520.00 🟢
  平均盈利:  +¥16,250.00
  平均亏损:  -¥4,830.00
  盈亏比:    3.36
  最大回撤:  -¥12,400.00
  最佳交易:  +¥45,000.00 (IF2606, 05-08)
  最差交易:  -¥8,200.00 (IC2609, 05-12)

C) Exporting Data

When user asks to export:

  1. Confirm format and date range
  2. Run export script with appropriate parameters
  3. Show export path and summary

Scripts

scripts/trade_logger.py

Core trade logging — add, edit, delete, and list journal entries.

scripts/trade_analyzer.py

Performance analysis — compute metrics, generate reports for any date range.

scripts/journal_export.py

Multi-format export — output journals to Markdown, CSV, or JSON.

Special Notes

  • Journal files are stored in journals/ directory within this skill folder
  • Each day gets one JSON file; multiple trades append to the same file
  • P&L is calculated on entry, not just on display
  • Open positions are tracked with exit_price: null and open: true
  • All monetary values are in CNY (¥)
  • Fees should include commission + slippage + stamp duty where applicable
  • Journal data is local-only — no external API calls