[KongchangAI]
· 2 min read· 1,275 words

TradeGuard: An Open-Source Tool for Offline Analysis of 8 Account-Blowing Trading Habits

TradeGuard: An Open-Source Tool for Offline Analysis of 8 Account-Blowing Trading Habits

TradeGuard is a pure-Python offline tool that detects fatal trading habits like Martingale with traceable evidence.

TradeGuard is a fully offline, zero-dependency trading behavior audit tool written in pure Python. It analyzes exported CSV trade histories against 8 rules derived from real account blowups, with every finding citing the exact trade number, timestamp, and figures that triggered it. It covers over-leverage, Martingale doubling, revenge trading, and more — backed by a 16-assertion eval suite that guarantees no false positives, no evidence-free accusations, and no network calls.

A trader at a prop firm turned a $50,000 account into $105,000 over three weeks during a challenge. Then lost it all in a single afternoon. The platform's risk dashboard clearly recorded what happened — but only after it was all over. Looking back at the data, position sizes had quietly doubled after each loss: a textbook Martingale strategy that wiped out six weeks of gains in just five consecutive losing trades.

The dashboard saw every trade, but it couldn't say the one thing that mattered most: "This pattern of behavior is exactly how accounts die — and it started right here."

That's exactly the problem TradeGuard was built to solve.

TradeGuard source project screenshot

What Is TradeGuard

TradeGuard is a fully offline, zero-dependency trading behavior analyzer written entirely in Python's standard library. The workflow is straightforward: export your trade history and account metrics as a CSV, and the tool audits them against 8 behavioral risk rules that repeatedly destroy retail accounts — with every finding citing the exact trade number, timestamp, and specific figures that triggered it.

From the sample output, you can see its auditing style is very "prosecutorial" — rather than vaguely assigning a risk score, it puts the evidence on the table:

RISK SCORE: 100 / 100  (HIGH — account at serious risk)

[HIGH] OVER_LEVERAGE — Trade #14: notional 12.4x equity on EURUSD
[HIGH] MARTINGALE — Lot size doubled after each of 4 consecutive losses
[HIGH] REVENGE_TRADING — 6 trades within 9 minutes after a -$840 loss
[HIGH] DRAWDOWN — current drawdown 19.8% vs 10% plan limit

The author emphasizes that the point was never the 100-point score — it's the evidence chain. Every finding points to a row you can open and verify, which makes the feedback both disputable and genuinely persuasive.

The Logic Behind the 8 Rules

Each rule encodes a well-documented "account killer." These rules weren't designed arbitrarily — they're drawn from publicly documented account blowup post-mortems:

RuleBehavior DetectedWhy It's Lethal
OVER_LEVERAGENotional value > 10x equityOne bad candle triggers a margin call
MARTINGALEDoubling position size after lossesGeometric progression guarantees ruin
REVENGE_TRADINGRapid re-entry after a large lossEmotionally-driven position sizing
RISK_PER_TRADESingle trade risk > 2% equityVolatility erodes edge
DRAWDOWNExceeds planned drawdown limitProp firm disqualification trigger
LOSS_STREAKConsecutive losing tradesEarly warning of psychological breakdown
CONCENTRATIONSingle instrument > 40% of exposureDisguised correlation risk
OVERTRADINGFrequency exceeds personal baselineFee drag + fatigue-induced errors

The value of this table lies in how it breaks down abstract "trading discipline" into quantifiable thresholds. Martingale-style position doubling "geometrically guarantees ruin," while revenge trading literally writes emotion into position size — these are the real patterns behind repeated retail account failures.

Martingale strategy originated in 18th-century French casinos. The core logic is to double your bet after every loss, so that theoretically, a single win eventually recovers everything. In trading, however, it has one fatal flaw: it assumes unlimited capital and no position limits. In practice, five consecutive losses make your position 32x the original; ten losses make it 1,024x — the account is rapidly zeroed out by geometric compounding. Even more dangerous, Martingale forces traders to hold their heaviest positions at exactly the worst time: during a losing streak, when the market is clearly trending against them. Prop firm challenge rules typically include maximum drawdown limits (e.g., 10%), and Martingale-style trading almost inevitably hits the forced stop-out threshold before any profit target is reached.

Revenge trading refers to a trader immediately re-entering the market after a significant loss, driven by emotion and the urge to "make it back." Neuroscience research shows that financial losses activate the same brain regions as physical pain, triggering a fight-or-flight response that sharply degrades decision-making quality. TradeGuard identifies "6 trades within 9 minutes of a large loss" as revenge trading precisely because actions within that time window could almost never stem from rational analysis — they are direct evidence of emotional takeover.

Built-In Evaluation: The Tool Audits Itself

One of TradeGuard's rare highlights is the evaluation (eval) suite bundled with the code. Running python eval.py executes 16 assertions covering scenarios from "detects excessive leverage with citation" to "a clean trade history scores zero."

PASS  detects_martingale_doubling
PASS  detects_revenge_trading_cluster
PASS  clean_history_scores_zero
PASS  every_finding_has_evidence
PASS  no_network_access
... 16/16 assertions passed.

The author notes that two assertions matter most to him: clean_history_scores_zero (no false positives on disciplined trading) and every_finding_has_evidence (the tool can never make an accusation without evidence). Together, these ensure the tool never "cries wolf" and never makes baseless claims — both critical properties for a risk analyzer that people need to trust.

Why Offline-Only

Your complete trade history is one of the most sensitive files you own — it's essentially a map of your worst decisions. With that in mind, TradeGuard runs entirely on your local machine: pure standard library, no account registration, no data uploads, no API keys required.

The eval suite includes a dedicated no_network_access assertion that ensures the code never makes any network calls. In other words, you can fully audit your trading records on an air-gapped laptop, with data that never leaves your device. For a tool handling highly sensitive financial data, this kind of verifiable privacy commitment carries far more weight than any written policy.

Air-gapped refers to a computer being completely disconnected from the internet and any other network — the highest level of isolation used by financial institutions and military systems when handling highly sensitive data. For retail traders, a complete CSV trade history contains entry/exit times, position sizes, and profit/loss records. If leaked, it not only exposes trading strategy but can also be used for targeted social engineering attacks or account security threats. Many "free" trading analysis tools actually monetize by uploading user data to train models. TradeGuard's offline guarantee is enforced by a code-level assertion (no_network_access) rather than a privacy policy, meaning anyone can audit whether the claim is actually true — this is the essential difference between verifiable privacy and a verbal promise.

Tech Stack and Design Trade-offs

TradeGuard's technical choices reflect deliberate restraint:

  • Pure Python standard library (csv, datetime, argparse) — clone and run, no dependencies to install.
  • Deterministic rules with transparent thresholds — no black-box "AI risk scores"; every judgment is traceable and explainable.
  • HTML reports — easy to share with a mentor, prop firm reviewer, or your future self.

What's interesting is that despite being built for Deriv's "Rise of AI Agents" hackathon, the author deliberately avoided black-box AI scoring in favor of deterministic rules. This is a thought-provoking trade-off: in high-stakes domains like risk management, interpretability and verifiability often matter more than a model's "intelligence."

How to Try It

The project repository is at github.com/Zhiyilang/tradeguard, which includes a sample trade history intentionally packed with bad habits, along with the 16-assertion eval suite. You can run python eval.py first to verify the tool's behavior, then point it at your own exported trade records.

The author also poses an open question: what behavior rule would you add to the list? His own candidate is — trading within 30 minutes of a deposit, because "funding impulse" is a well-documented trigger for psychological imbalance.

As the author puts it, the most valuable risk report is the one you read before the drawdown happens, not after. TradeGuard's core philosophy is exactly that: shifting post-mortem analysis into pre-emptive warning.

#TradeGuard#trading behavior analysis#Martingale detection#revenge trading#prop firm risk management#offline trading audit#account blowup prevention#Python trading tool
Share:

Related articles