Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 4 min read

Building TraderZen: A Multi-Modal Biometric Circuit Breaker Powered by Presage SmartSpectra

This is a submission for the Presage SmartSpectra SDK Challenge What I Built TraderZen is an autonomous, contactless biometric desktop companion and cognitive circuit breaker for financial traders, powered by

This is a submission for the Presage SmartSpectra SDK Challenge

What I Built

TraderZen is an autonomous, contactless biometric desktop companion and cognitive circuit breaker for financial traders, powered by the Presage SmartSpectra SDK.
When trading volatile markets (crypto, forex, equities, or prop firm challenges), the biggest threat to capital isn't the marketβ€”it’s "Tilt" (emotional revenge-trading, adrenaline rushes, and despair-fueled sizing). Traders ignore passive desktop notifications during fight-or-flight states.
TraderZen solves this by floating unobtrusively alongside your charting terminal (TradingView, MetaTrader, etc.), continuously analyzing your physiological and affective state using standard webcam feeds. When your biometric thresholds are breached (e.g., heart rate > 95 BPM, hyperventilation, or an acute spike in anger/fear > 70%), TraderZen triggers an Executive Tilt Circuit Breaker:

  • Full-Screen Optical Blur: It instantly frosts your entire screen in heavy 40px backdrop blur, making your order book and broker physically untouchable.
  • Audio-Guided Box Breathing: A circular breathing pacer guides you through a 4-second box-breathing cycle (Inhale β†’ Hold β†’ Exhale β†’ Hold) with soothing acoustic harmonics.
  • Autonomic Recovery Lock: Your desktop remains protected until your physiological vitals return below risk thresholds, complete with a deliberate 3-second hold-to-override safeguard so the trader always retains final agency.

Demo

*Demo Video: *

Key Screenshots:

Code

Setup Instructions

git clone https://github.com/Abhinandangithub01/Trader_Zen.git
cd Trader_Zen
npm install
npm start

How It Responds to Human Signals

TraderZen integrates 9 simultaneous Presage SmartSpectra biometric modalities in real time via the native MediaPipe C++ pipeline:

  1. Cardio Pulse Rate (MetricType.PULSE_RATE): Sub-frame rPPG facial chrominance processing computes live Heart Rate (BPM). An animated heart icon beats synchronously with physical heart contractions.
  2. Respiration Cadence (MetricType.BREATHING_RATE, CHEST_BREATHING): Monitors chest wall displacement and breathing frequency to detect rapid shallow breathing and hyperventilation during market volatility.
  3. Facial Affect & Emotion Classifier (MetricType.EXPRESSIONS): Decodes protobuf expression scores to classify 8 affective states (ANGRY, FEAR, HAPPY, NEUTRAL, SAD, SURPRISE, CONTEMPT, DISGUST). If confidence in ANGRY or FEAR exceeds 70%, it immediately trips the Emotional Rage Lock.
  4. Verbal Agitation & Outbursts (MetricType.TALKING): Monitors jaw movement and vocalization status, flagging shouted distress or heavy exasperated sighs at the screen.
  5. Eye Blink Cadence & Fatigue (MetricType.BLINKING): A 60-second rolling window monitors blink frequency. If blinks drop below 7/min, the HUD displays a DROWSY / FATIGUE alert for late-night session traders.
  6. 468-Point 3D Face Mesh & Head Posture (MetricType.FACE_LANDMARKS): Tracks 3D coordinate displacement (x, y, z) between the forehead, nose tip, and chin. It detects when a trader buries their face in their hands or slumps forward in despair.
  7. Chair Micro-Motion Restlessness (GLUTES_MICROMOTION, KNEES_MICROMOTION): Measures sub-millimeter physiological tremors and vibration in the chair, flagging impatient leg-bouncing and motor restlessness.
  8. Compound Tilt Risk Index: Aggregates all human signals into a unified 0–100 autonomic risk score:
    • Baseline Heart Rate over resting ceiling (up to 50 pts)
    • Respiration hyperventilation penalty (up to 20 pts)
    • Hostility & panic affect (Anger/Fear > 40% adds up to 30 pts)
    • Verbal agitation outburst (+15 pts)
    • Chair restlessness jitter (+10 pts) Classifies state into Optimal (Green), Elevated (Amber), or Critical Tilt (Rose/Red).

SmartSpectra SDK Integration Walkthrough

We connected Electron's renderer with the native C++ FFI bridge using sdk.useMediaStream(stream) and protobuf decoding:

  • 30.0 FPS Monotonic Timestamp Ratchet: Standard USB 2.0 webcams frequently jitter between 24 and 29 FPS under auto-exposure. We implemented an epoch timestamp anchor (timestamp.js) guaranteeing strict 33,333 Β΅s intervals, preventing graph starvation errors.
  • Automated Graceful Recovery: Replaced fatal pause states with an automated debounce recovery handler (sdk.reset() followed by in-place sdk.start()), ensuring the sensor re-arms seamlessly if video focus changes.

Prize Categories

Best Thoughtful Real-World Use

  • Real-World Need: Emotional discipline is the #1 reason 90%+ of retail traders and prop firm candidates fail. During sudden market drawdowns, the sympathetic nervous system triggers fight-or-flight adrenaline rushes, causing traders to double down, move stop-losses, or revenge-trade their accounts to zero.
  • Who It's For: Day traders, crypto scalpers, prop firm challenge participants (FTMO, Topstep), and high-stress computer knowledge workers.
  • Thoughtful Design:
    • Passive desktop notifications are consistently ignored during acute tilt; TraderZen physically locks the display behind an unclickable frosted glass barrier to force a mandatory biological cool-down.
    • It respects trader agency: a 3-second hold-to-override prevents impulsive bypasses while ensuring a user can still exit an emergency position if needed.

Most Creative or Delightful Use

  • Rather than building another passive dashboard or mock trading exchange, TraderZen turns contactless webcam signals into a proactive, physical guardian of your financial capital.
  • Features dynamic acoustic entrainment tones (Web Audio API) matched to physiological states and real-time box breathing pacers. ## Consent and Data Handling
  • Camera Consent: TraderZen accesses the webcam strictly with the user's explicit browser/OS permission prompt via navigator.mediaDevices.getUserMedia. A visible, high-definition camera viewport with alignment reticles is always shown so the user is fully aware when sensing is active.
  • 100% Local On-Device Processing: Video frames never leave the host machine. All computer vision and rPPG extraction calculations are performed entirely on-device by the native C++ smartspectra_capi engine.
  • Zero Video Storage or Transmission: Raw camera frames and facial images are discarded immediately after in-memory buffer processing; zero frames are written to disk, uploaded to the cloud, or transmitted over the network.
  • Telemetry: Remote telemetry is explicitly disabled (enableTelemetry: false). User configuration rules are stored strictly on the local machine via localStorage.
  • Non-Medical Disclaimer: TraderZen is an autonomic biofeedback performance and discipline tool for trading; it is not a medical device and makes no claims to diagnose, treat, or monitor clinical health conditions.

Agent Session

Building TraderZen with Antigravity
0 of 0 messages
πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.