Real-time Signal Logic
Real-Time Signal Logic
Signal.Engine utilizes a "Hybrid Brain" architecture to generate trading decisions. It doesn't just predict price movement; it synthesizes technical indicators, sequence modeling (LSTM), and reinforcement learning (PPO) to produce actionable signals with human-readable rationale.
The Signal Generation Flow
The system operates on a continuous "Think" loop. This process can be triggered manually via the dashboard or automated through API polling.
- Data Ingestion: The system fetches the latest market candles for the defined universe (e.g., Nifty 500 or S&P 500).
- Inference:
- LSTM Layer: Analyzes the last 50 candles to identify time-series patterns.
- Heuristic Layer: Evaluates volatility, RSI, and MACD.
- Synthesis: The
HybridBrainmerges these inputs to produce a Decision Object. - Risk Overlay: The Simulation Engine calculates Quantitative Risk (WinRate, VaR, EV) before presenting the signal.
API Reference: Consuming Signals
The backend exposes several endpoints to interact with the signal logic.
1. Triggering a Scan
GET /api/scan
Starts the HybridBrain.think() process in a background thread. This prevents the API from locking up during complex calculations.
- Response:
{ "status": "started", "message": "Scan triggered in background." }
2. Fetching Results
GET /api/results
Retrieves the most recent decisions generated by the brain, along with the current simulation state.
- Response Schema:
| Field | Type | Description |
| :--- | :--- | :--- |
|
data|Array<Decision>| List of active stock signals. | |simulation|Object| Current portfolio balance, equity, and PnL. | |is_thinking|Boolean| Whether a background scan is currently running. | |logs|Array<String>| Recent processing steps and system events. |
The Decision Object
Every signal generated by the system follows a strict schema designed for both automated execution and user review.
{
"Ticker": "RELIANCE.NS",
"Action": "BUY",
"Confidence": 0.89,
"Rational": [
"LSTM Sequence shows bullish reversal",
"RSI Oversold (28.4)",
"High Volatility detected"
],
"QuantRisk": {
"WinRate": 0.65,
"EV": 1.25,
"VaR95": -2.4
}
}
Key Fields:
- Action: Can be
BUY,SELL, orHOLD(Neutral). - Confidence: A value from
0.0to1.0. - Rational: An array of strings explaining why the brain made this choice. This moves the system from a "Black Box" to "Explainable AI."
- QuantRisk: Metrics providing the Expected Value (EV) and Value at Risk (VaR) for the specific trade.
Real-Time Alerts & UI Integration
The frontend implementation (App.tsx) includes logic for real-time monitoring and alerting based on signal strength.
High-Confidence Notifications
The system includes a NotificationService that triggers browser alerts when the brain's confidence exceeds a specific threshold:
- Threshold:
Confidence >= 0.85 - Behavior: High-confidence signals trigger a push notification. Signals with
Confidence >= 0.90require user interaction to dismiss, highlighting high-probability setups.
Automatic Polling Loop
When the dashboard is set to Auto Mode, the frontend polls the /api/scan and /api/results endpoints every 2 seconds. This ensures the "Market Mood" and signal list stay synchronized with the latest exchange data.
// Example of the frontend polling logic
useEffect(() => {
if (isAuto) {
interval = setInterval(() => {
if (!loading) runScan(true); // silent background update
}, 2000);
}
return () => clearInterval(interval);
}, [isAuto]);
Market Regime Detection
Beyond individual stock signals, the logic derives a global Market Mood:
- VOLATILE: Triggered if >30% of signals report "High Volatility" in their rationale.
- CALM: Triggered when price action stabilizes across the scanned universe.
This regime detection influences the PPO Agent's risk appetite, allowing for tighter stop-losses during volatile periods.