A trader on a prop-firm challenge turned a $50k account into $105k in three weeks. Then he lost all of it in one afternoon. The platform's risk dashboard showed exactly what happened — but only after it was over: position size had quietly doubled after every loss, the classic martingale, and it took precisely five losing trades in a row to wipe out six weeks of gains.
The dashboard saw the trades. What it couldn't do was say "this sequence of behavior is how accounts die — here is the exact trade where it started."
That is what TradeGuard does.
What TradeGuard does
TradeGuard is an offline, zero-dependency trading behavior analyzer in pure Python standard library. You export your trade history and account metrics to CSV; it audits them against 8 behavioral risk rules that repeatedly destroy retail accounts — and every finding cites the exact trade IDs, timestamps, and numbers that prove it.
$ python -m tradeguard audit --trades examples/trades.csv --account examples/account.csv
RISK SCORE: 100 / 100 (HIGH — account at serious risk)
[HIGH] OVER_LEVERAGE — Trade #14: notional 12.4x equity on EURUSD
evidence: trades.csv:14 lots=2.5 equity=10000 price=1.0842
[HIGH] MARTINGALE — Lot size doubled after each of 4 consecutive losses
evidence: trades.csv:21-28 lots 1.0→1.2→1.6→2.4
[HIGH] REVENGE_TRADING — 6 trades within 9 minutes after a -$840 loss
evidence: trades.csv:31-36 entry timestamps cluster 14:02-14:11
[HIGH] RISK_PER_TRADE — 8 trades risked >2% of equity (max 5.1%)
evidence: trades.csv:8,12,14,19,22,27,33,41
[HIGH] DRAWDOWN — current drawdown 19.8% vs 10% plan limit
evidence: account.csv:3 balance=80200 peak=100000
[HIGH] CONCENTRATION — 55.1% of volume in a single instrument (EURUSD)
evidence: trades.csv instrument=EURUSD count=38/69
[CAUTION] LOSS_STREAK — 5 consecutive losses preceded the largest single loss
evidence: trades.csv:29-41
[CAUTION] OVERTRADING — 69 trades in 5 sessions (3.8x your own median)
RECOMMENDED: hard-cap lot size at 1.0, enforce a 2% max risk per trade,
and lock the terminal after 2 consecutive losses.
The point isn't the score — it's the evidence trail. Every claim points at a row you can open and verify, so the feedback survives arguments.
The 8 rules and why they exist
Each rule encodes a documented account-killer:
| Rule | What it catches | Why it kills accounts |
|---|---|---|
| OVER_LEVERAGE | notional > 10x equity | one bad candle = margin call |
| MARTINGALE | lot doubling after losses | geometrically guarantees ruin |
| REVENGE_TRADING | rapid re-entry after big loss | emotion-driven sizing |
| RISK_PER_TRADE | > 2% equity at risk per trade | variance eats the edge |
| DRAWDOWN | beyond plan limit | prop-firm disqualification |
| LOSS_STREAK | consecutive losses | tilt precursor |
| CONCENTRATION | > 40% single instrument | correlation risk in disguise |
| OVERTRADING | frequency vs. own baseline | fee bleed + fatigue errors |
It ships with evals
$ python eval.py
PASS detects_over_leverage_with_citation
PASS detects_martingale_doubling
PASS detects_revenge_trading_cluster
PASS risk_per_trade_uses_equity_at_entry
PASS drawdown_uses_peak_balance
PASS concentration_threshold_boundary
PASS clean_history_scores_zero
PASS every_finding_has_evidence
PASS report_html_contains_all_findings
PASS no_network_access
... 16/16 assertions passed.
Two of those assertions matter most to me: clean_history_scores_zero (no false alarms on disciplined trading) and every_finding_has_evidence (the tool can never accuse without proof).
Why offline matters
Your full trade history is the most sensitive file you own — it's a map of your worst decisions. TradeGuard runs entirely on your machine: pure standard library, no accounts, no uploads, no API keys. The eval suite asserts the code makes zero network calls. You can audit it on an air-gapped laptop.
Tech stack
- Pure Python stdlib (
csv,datetime,argparse) — clone and run, nothing to install. - Deterministic rules with transparent thresholds — no black-box "AI risk score".
- HTML report for sharing with a mentor, prop-firm reviewer, or your past self.
Try it
Repo: github.com/Zhiyilang/tradeguard with example trade history (deliberately full of bad habits) and the 16-assertion eval suite. Run python eval.py, then point it at your own export — I'd genuinely like to hear what it finds.
I built TradeGuard for the Deriv "Rise of AI Agents" hackathon, but the rules come from public post-mortems of blown accounts. The most valuable risk report is the one you read before the drawdown, not after.
What behavioral rule would you add to the list? Mine is a candidate: trading within 30 minutes of a deposit — funding urgency is a documented tilt trigger. Comments open.
Top comments (0)