Skip to content

Monitoring and Health

How to verify the system is running correctly, handle errors, and track scan performance.


Health Checks

Three conditions must be true for the strategy layer to produce valid scans:

1. TradingView Desktop Connected

The MCP server must have an active CDP connection to TradingView Desktop.

# Verify connection via MCP
tv_health_check

Expected: { connected: true, host: "localhost", port: 9222 }.

If disconnected: Verify TradingView Desktop is running with --remote-debugging-port=9222. Check that no other process is using port 9222.

2. All Four Indicators Loaded

All four indicators must be present on the active chart. The strategy layer checks for each indicator using study_filter substring matching.

Indicator Verified By
Bias AI data_get_pine_tables with study_filter: "Bias AI" returns non-empty
Session Hunt AI data_get_pine_lines with study_filter: "Session Hunt AI" returns non-empty
OB AI data_get_pine_boxes with study_filter: "OB AI" returns non-empty
SMT Divergences data_get_pine_labels with study_filter: "SMT" returns non-empty

If missing: The strategy warns and skips the missing indicator's data. The scan will still run but with incomplete flags. An OB AI or Bias AI absence will likely cause setup_valid: false on every scan because core conditions cannot be evaluated.

3. MCP Server Responding

The MCP server must accept and return tool calls within a reasonable time.

If unresponsive: Restart the MCP server process. Check for port conflicts or TradingView Desktop crashes.


Error Handling

Missing Indicator

Behavior: Warn and skip. The scan continues with whatever indicators are available.

Log output:

{
  "level": "warn",
  "message": "Indicator not found on chart",
  "indicator": "OB AI",
  "study_filter": "OB AI",
  "impact": "structure.order_blocks will be empty"
}

Impact by indicator:

Missing Indicator Effect on StrategyFlags
Bias AI bias.daily and bias.weekly default to "neutral". Every scan is a no-trade (neutral_bias).
Session Hunt AI session.hunt defaults to null side. Every scan is a no-trade (no hunt state).
OB AI structure.order_blocks empty for both sides. Every scan is a no-trade (no_ob_in_path).
SMT Divergences smt.bullish_active and smt.bearish_active default to false. Setups lose the smt_confirms confluence factor (weight 2) but can still be valid if other factors meet MIN_CONFLUENCE.

Stale Data

Detection: The strategy compares the timestamp of the last successful scan against the current time. If the gap exceeds POLL_INTERVAL * 3, the data is flagged as stale.

Behavior: Log a warning. The stale flag is included in the scan output but does not block the scan.

{
  "level": "warn",
  "message": "Stale data detected",
  "last_scan": "2026-04-14T14:00:00.000Z",
  "current_time": "2026-04-14T14:00:45.000Z",
  "gap_ms": 45000,
  "threshold_ms": 30000
}

Common causes: TradingView Desktop minimized or tab backgrounded (Chrome throttles backgrounded tabs), MCP server overloaded, network issues.

Connection Drops

Detection: MCP tool calls return connection errors or timeouts.

Behavior: Retry with exponential backoff.

Attempt Delay Max Attempts
1 1 second
2 2 seconds
3 4 seconds
4 8 seconds
5 16 seconds 5 (then halt)

After max attempts, the poll loop halts and logs an error. Manual restart is required.


Logging

Scan Results

Every scan cycle logs the full StrategyFlags output as JSON:

{
  "level": "info",
  "message": "Scan complete",
  "scan_number": 42,
  "duration_ms": 1250,
  "setup_valid": true,
  "confluence_score": 7,
  "direction": "long"
}

Delta Detection

When running in poll mode, only changes between consecutive scans are highlighted:

{
  "level": "info",
  "message": "Delta detected",
  "changes": [
    { "path": "session.hunt.lo_swept", "from": false, "to": true },
    { "path": "session.hunt.side", "from": null, "to": "HUNT_LOW" },
    { "path": "decision.setup_valid", "from": false, "to": true }
  ]
}

Delta detection reduces log noise during quiet periods. If no fields changed between scans, only a heartbeat line is logged.

Error Context

Errors include full context for debugging:

{
  "level": "error",
  "message": "MCP tool call failed",
  "tool": "data_get_pine_boxes",
  "study_filter": "OB AI",
  "error": "Connection refused",
  "retry_attempt": 3,
  "scan_number": 42
}

Future: Grafana Dashboard

A Grafana dashboard is planned for Phase 3+ to visualize:

  • Scan metrics: scans per minute, average scan duration, error rate
  • Alert latency: time between indicator state change and strategy detection
  • Setup frequency: setups per session, grouped by type (hunt_long_ob_fvg, etc.)
  • Confluence distribution: histogram of confluence scores across scans
  • No-trade breakdown: pie chart of no_trade_reasons frequency

The dashboard will consume scan logs via a structured log shipper (e.g., Loki, Elasticsearch). The log format described above is designed to be directly parseable by these systems.