# shine0078/nt8bridgeclean architecture

> Architecture diagram of the GitHub repository shine0078/nt8bridgeclean, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shine0078/nt8bridgeclean
- Repository: https://github.com/shine0078/nt8bridgeclean

## Overview

1. **Repository purpose and boundary**
   - This repo is a dual-purpose scaffold: a **safe NinjaTrader 8 discovery layer** on Windows and a **broker-agnostic Python research/trading core** under `nt8bridge/`.
   - The current operating boundary is explicit: the README says this phase is **discovery-only** and must not automate live trading, click trading controls, or run backtests/optimizations interactively.

2. **Top-level subsystem split**
   - `Scripts/` contains operational entrypoints for UI discovery, validation, sync, reporting, and research workflows.
   - `nt8bridge/` is the reusable Python library with strategy, risk, execution, backtest, and reporting primitives.
   - `Strategies/` holds NinjaTrader 8 C# strategy implementations that likely map to the Python research logic.
   - `Tests/` provides broad coverage across the library and workflow boundaries.
   - `Config/`, `Logs/`, `Results/`, and `Reports/` are the configuration and artifact/output areas.

3. **NinjaTrader UI discovery lane**
   - The discovery scripts (`discover_nt8_windows.py`, `discover_strategy_analyzer_uia.py`, `discover_strategy_analyzer_win32.py`) use Windows UI inspection tooling to enumerate visible NT8 windows and controls.
   - The README’s setup requirements (`pywinauto`, `pywin32`, `comtypes`) indicate this lane depends on Windows automation/inspection APIs, not trading APIs.
   - This lane is intentionally read-only: it verifies Strategy Analyzer visibility and tree dumps, then logs findings to `Logs/`.

4. **Python core architecture**
   - The `nt8bridge` package is organized as a layered trading-research engine rather than a monolith.
   - Core domains include market data handling, indicators, signals, filters, regime detection, risk control, execution/paper trading, backtesting, portfolio construction, and reporting.
   - The module names suggest the package is designed to compose strategies from reusable primitives instead of hardcoding strategy logic in one place.

5. **Data and market structure layer**
   - `data.py`, `data_provider.py`, `resample.py`, `datetime_utils.py`, `multitimeframe.py`, and `market_context.py` form the data-preparation boundary.
   - These modules likely normalize bar/tick series, manage timeframe alignment, and provide contextual features used by downstream signal and risk modules.
   - `indicators.py`, `filters.py`, `correlation.py`, and `regime.py` appear to transform raw market data into features and market-state classifications.

6. **Strategy decision layer**
   - `signals.py`, `strategy.py`, `strategy_concepts.py`, `keltner_engine.py`, `adaptive.py`, `ensemble.py`, and `regime_filter.py` suggest the system supports modular signal generation and strategy composition.
   - `position_sizing.py`, `stop_management.py`, `position_timeout.py`, and `cost_gate.py` act as decision constraints around entries, exits, and trade eligibility.
   - `online.py` and `scheduler.py` indicate the framework can run in a time-aware, incremental mode, not only in batch backtests.

7. **Execution and trade-management boundary**
   - `execution.py`, `executor.py`, `paper.py`, and `portfolio.py` form the boundary between strategy intent and order/state handling.
   - The README emphasizes paper/backtest defaults and explicit live-mode protection, so this layer is designed to fail closed unless live trading is intentionally enabled.
   - `models.py`, `monitoring.py`, and `attribution.py` support state tracking, observability, and post-trade analysis.

8. **Research, optimization, and validation lane**
   - `backtest.py`, `optimize.py`, `bayesian_optimization.py`, `monte_carlo.py`, `parameter_stability.py`, `stress.py`, and `statistics.py` indicate a substantial offline research workflow.
   - `reporting.py` and `symbol_performance.py` consume evaluation results and produce summaries suitable for `Reports/`.
   - `Scripts/run_backtest.py`, `run_keltner_walkforward.py`, `run_keltner_walkforward_parallel.py`, `report_keltner_research.py`, and `scrape_results.py` suggest batch research automation, even though the README says those actions are not part of the current safe phase.

9. **NinjaTrader strategy integration**
   - `Strategies/KeltnerBreakout.cs` and `Strategies/VWAPMeanReversion.cs` are the NT8-facing strategy implementations.
   - These are the likely bridge point where researched logic is translated into NinjaTrader-compatible strategy code and properties.
   - `Scripts/sync_nt8_params.py` and `Config/PARAMETERS.md` imply configuration/parameter synchronization between Python research settings and NT8 strategy inputs.

10. **Configuration and validation flow**
   - `Config/config.json` is the central configuration artifact, with `Scripts/validate_config.py` enforcing correctness.
   - The tests and scripts imply that config drives strategy parameters, mode selection, and safety gates such as live-trading enablement.
   - This is an important boundary for the architecture diagram because it separates static settings from runtime behavior.

11. **Artifacts and operational outputs**
   - `Logs/`, `Results/`, and `Reports/` are the main output sinks.
   - Logs capture UI discovery and validation outcomes; results likely store backtest/optimization outputs; reports aggregate research findings.
   - The presence of `.gitkeep` files shows these directories are intended as persistent runtime destinations even when empty in source control.

12. **Testing and quality envelope**
   - The `Tests/` suite is large and cross-cuts almost every subsystem: config, data, execution, risk, filters, regime, reporting, monitoring, scheduler, strategy, integration, and system-level behavior.
   - Test names like `test_executor_real_market_gates`, `test_paper_realistic`, `test_strategy_runner_regression`, and `test_system_integration` suggest emphasis on safety, gating, and regression prevention.
   - This makes the test suite a key architectural boundary: it validates that research, execution, and safety rules stay aligned.

13. **Overall diagram shape**
   - The clearest architecture diagram is a three-lane model:
     - **Windows/NT8 discovery lane**: scripts inspect visible UI state and write logs.
     - **Python research/trading core**: data → indicators/signals → risk/execution/backtest → metrics/reporting.
     - **NT8 strategy integration lane**: C# strategies and parameter sync connect the research core to NinjaTrader-compatible artifacts.
   - The system is intentionally safety-first, with the UI layer constrained to discovery and the trading core defaulting to paper/backtest behavior.

Main entry points: [`nt8bridge/backtest.py`](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/backtest.py) (Backtest), [`nt8bridge/strategy.py`](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/strategy.py) (Strategy core), [`Config/config.json`](https://github.com/shine0078/nt8bridgeclean/blob/master/Config/config.json) (Config), [`Scripts/sync_nt8_params.py`](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/sync_nt8_params.py) (Sync params)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Discovery lane"]
  node_scripts_discover_nt8_windows["NT8 windows<br/>discovery script"]
  node_scripts_discover_strategy_analyzer_uia["UIA probe<br/>discovery script"]
  node_scripts_discover_strategy_analyzer_win32["Win32 probe<br/>discovery script"]
  node_scripts_validate_config["Validate config<br/>validation script<br/>[validate_config.py]"]
end

subgraph group_core["Python core"]
  node_nt8bridge_config["Runtime config<br/>config module<br/>[config.py]"]
  node_nt8bridge_data["Market data<br/>data layer<br/>[data.py]"]
  node_nt8bridge_indicators["Indicators<br/>feature layer<br/>[indicators.py]"]
  node_nt8bridge_signals["Signals<br/>decision layer<br/>[signals.py]"]
  node_nt8bridge_strategy["Strategy core<br/>composition layer<br/>[strategy.py]"]
  node_nt8bridge_risk["Risk rules<br/>risk layer<br/>[risk.py]"]
  node_nt8bridge_execution["Execution<br/>[execution.py]"]
  node_nt8bridge_backtest["Backtest<br/>research engine<br/>[backtest.py]"]
  node_nt8bridge_optimize["Optimization<br/>research engine<br/>[optimize.py]"]
  node_nt8bridge_reporting["Reporting<br/>analytics layer<br/>[reporting.py]"]
  node_nt8bridge_monitoring["Monitoring<br/>observability layer<br/>[monitoring.py]"]
end

subgraph group_nt8["NT8 integration"]
  node_scripts_sync_nt8_params["Sync params<br/>sync script<br/>[sync_nt8_params.py]"]
  node_strategies_keltner_breakout["Keltner breakout<br/>NT8 strategy<br/>[KeltnerBreakout.cs]"]
  node_strategies_vwap_mean_reversion["VWAP reversion<br/>NT8 strategy"]
end

subgraph group_ops["Configuration and artifacts"]
  node_config_json["Config<br/>settings<br/>[config.json]"]
  node_scripts_run_backtest["Run backtest<br/>research script<br/>[run_backtest.py]"]
  node_scripts_run_walkforward["Walkforward<br/>research script"]
  node_scripts_report_research["Research report<br/>report script"]
end

node_config_json -->|"loaded by"| node_nt8bridge_config
node_scripts_validate_config -->|"checks"| node_config_json
node_scripts_discover_nt8_windows -.->|"complements"| node_scripts_discover_strategy_analyzer_uia
node_scripts_discover_strategy_analyzer_uia -.->|"cross-checks"| node_scripts_discover_strategy_analyzer_win32
node_scripts_discover_strategy_analyzer_uia -->|"supports"| node_scripts_validate_config
node_nt8bridge_config -->|"drives"| node_nt8bridge_data
node_nt8bridge_data -->|"feeds"| node_nt8bridge_indicators
node_nt8bridge_indicators -->|"feeds"| node_nt8bridge_signals
node_nt8bridge_signals -->|"drives"| node_nt8bridge_strategy
node_nt8bridge_strategy -->|"constrained by"| node_nt8bridge_risk
node_nt8bridge_risk -->|"authorizes"| node_nt8bridge_execution
node_nt8bridge_execution -->|"simulated by"| node_nt8bridge_backtest
node_nt8bridge_backtest -->|"evaluated by"| node_nt8bridge_optimize
node_nt8bridge_backtest -->|"summarized by"| node_nt8bridge_reporting
node_nt8bridge_execution -->|"observed by"| node_nt8bridge_monitoring
node_scripts_run_backtest -->|"orchestrates"| node_nt8bridge_backtest
node_scripts_run_walkforward -->|"orchestrates"| node_nt8bridge_backtest
node_scripts_report_research -->|"orchestrates"| node_nt8bridge_reporting
node_scripts_sync_nt8_params -->|"syncs"| node_strategies_keltner_breakout
node_scripts_sync_nt8_params -->|"syncs"| node_strategies_vwap_mean_reversion
node_nt8bridge_strategy -.->|"maps to"| node_strategies_keltner_breakout
node_nt8bridge_strategy -.->|"maps to"| node_strategies_vwap_mean_reversion
node_scripts_run_backtest -->|"reads"| node_config_json
node_scripts_sync_nt8_params -->|"reads"| node_config_json

click node_scripts_discover_nt8_windows "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_nt8_windows.py"
click node_scripts_discover_strategy_analyzer_uia "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_strategy_analyzer_uia.py"
click node_scripts_discover_strategy_analyzer_win32 "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_strategy_analyzer_win32.py"
click node_scripts_validate_config "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/validate_config.py"
click node_config_json "https://github.com/shine0078/nt8bridgeclean/blob/master/Config/config.json"
click node_nt8bridge_config "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/config.py"
click node_nt8bridge_data "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/data.py"
click node_nt8bridge_indicators "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/indicators.py"
click node_nt8bridge_signals "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/signals.py"
click node_nt8bridge_strategy "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/strategy.py"
click node_nt8bridge_risk "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/risk.py"
click node_nt8bridge_execution "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/execution.py"
click node_nt8bridge_backtest "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/backtest.py"
click node_nt8bridge_optimize "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/optimize.py"
click node_nt8bridge_reporting "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/reporting.py"
click node_nt8bridge_monitoring "https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/monitoring.py"
click node_scripts_sync_nt8_params "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/sync_nt8_params.py"
click node_strategies_keltner_breakout "https://github.com/shine0078/nt8bridgeclean/blob/master/Strategies/KeltnerBreakout.cs"
click node_strategies_vwap_mean_reversion "https://github.com/shine0078/nt8bridgeclean/blob/master/Strategies/VWAPMeanReversion.cs"
click node_scripts_run_backtest "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/run_backtest.py"
click node_scripts_run_walkforward "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/run_keltner_walkforward.py"
click node_scripts_report_research "https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/report_keltner_research.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_scripts_discover_nt8_windows,node_scripts_discover_strategy_analyzer_uia,node_scripts_discover_strategy_analyzer_win32,node_scripts_validate_config toneBlue
class node_nt8bridge_config,node_nt8bridge_data,node_nt8bridge_indicators,node_nt8bridge_signals,node_nt8bridge_strategy,node_nt8bridge_risk,node_nt8bridge_execution,node_nt8bridge_backtest,node_nt8bridge_optimize,node_nt8bridge_reporting,node_nt8bridge_monitoring toneAmber
class node_scripts_sync_nt8_params,node_strategies_keltner_breakout,node_strategies_vwap_mean_reversion toneMint
class node_config_json,node_scripts_run_backtest,node_scripts_run_walkforward,node_scripts_report_research toneRose
```

## Components

### Discovery lane

Windows and NinjaTrader UI inspection scripts used only for read-only discovery and validation.

- [NT8 windows](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_nt8_windows.py): discovery script · Enumerates visible NinjaTrader 8 windows for discovery-only inspection. · `Scripts/discover_nt8_windows.py`
- [UIA probe](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_strategy_analyzer_uia.py): discovery script · Inspects Strategy Analyzer controls through UI Automation. · `Scripts/discover_strategy_analyzer_uia.py`
- [Win32 probe](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/discover_strategy_analyzer_win32.py): discovery script · Inspects Strategy Analyzer windows and tree structure through Win32 tooling. · `Scripts/discover_strategy_analyzer_win32.py`
- [Validate config](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/validate_config.py): validation script · Checks repository configuration and safety-related settings. · `Scripts/validate_config.py`

### Python core

Reusable research and trading engine for data prep, signals, risk, execution, backtesting, and reporting.

- [Runtime config](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/config.py): config module · Loads and interprets configuration for the Python core. · `nt8bridge/config.py`
- [Market data](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/data.py): data layer · Normalizes and serves market series into the research pipeline. · `nt8bridge/data.py`
- [Indicators](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/indicators.py): feature layer · Transforms market data into technical features and derived series. · `nt8bridge/indicators.py`
- [Signals](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/signals.py): decision layer · Combines features into actionable strategy signals. · `nt8bridge/signals.py`
- [Strategy core](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/strategy.py): composition layer · Coordinates strategy logic from signals, filters, and regime context. · `nt8bridge/strategy.py`
- [Risk rules](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/risk.py): risk layer · Applies sizing, stop, timeout, and trade-eligibility constraints. · `nt8bridge/risk.py`
- [Execution](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/execution.py): execution layer · Defines order and trade-handling boundaries for the core engine. · `nt8bridge/execution.py`
- [Backtest](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/backtest.py): research engine · Runs offline evaluation of strategies against historical data. · `nt8bridge/backtest.py`
- [Optimization](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/optimize.py): research engine · Searches parameter space for candidate strategy settings. · `nt8bridge/optimize.py`
- [Reporting](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/reporting.py): analytics layer · Converts research and evaluation outputs into summaries and artifacts. · `nt8bridge/reporting.py`
- [Monitoring](https://github.com/shine0078/nt8bridgeclean/blob/master/nt8bridge/monitoring.py): observability layer · Tracks runtime state and operational signals for the core engine. · `nt8bridge/monitoring.py`

### NT8 integration

NinjaTrader 8 strategy implementations and parameter synchronization boundary.

- [Sync params](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/sync_nt8_params.py): sync script · Propagates research parameters into NT8-facing strategy inputs. · `Scripts/sync_nt8_params.py`
- [Keltner breakout](https://github.com/shine0078/nt8bridgeclean/blob/master/Strategies/KeltnerBreakout.cs): NT8 strategy · NinjaTrader 8 implementation of the breakout strategy. · `Strategies/KeltnerBreakout.cs`
- [VWAP reversion](https://github.com/shine0078/nt8bridgeclean/blob/master/Strategies/VWAPMeanReversion.cs): NT8 strategy · NinjaTrader 8 implementation of the mean-reversion strategy. · `Strategies/VWAPMeanReversion.cs`

### Configuration and artifacts

Central config and runtime output locations for logs, results, and reports.

- [Config](https://github.com/shine0078/nt8bridgeclean/blob/master/Config/config.json): settings · Central configuration artifact driving mode, parameters, and safety gates. · `Config/config.json`
- [Run backtest](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/run_backtest.py): research script · Batch entrypoint for offline backtesting workflows. · `Scripts/run_backtest.py`
- [Walkforward](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/run_keltner_walkforward.py): research script · Runs rolling evaluation over parameter and time windows. · `Scripts/run_keltner_walkforward.py`
- [Research report](https://github.com/shine0078/nt8bridgeclean/blob/master/Scripts/report_keltner_research.py): report script · Generates summaries from research outputs for published artifacts. · `Scripts/report_keltner_research.py`

## Connections

- Config → Runtime config: loaded by · Central settings are consumed by the Python runtime.
- Validate config → Config: checks · Validation enforces config correctness and safety gates.
- NT8 windows → UIA probe: complements · Two inspection paths cover UI discovery from different APIs.
- UIA probe → Win32 probe: cross-checks · UI Automation and Win32 discovery corroborate visible controls.
- UIA probe → Validate config: supports · Discovery results are validated against expected safe operation.
- Runtime config → Market data: drives · Runtime settings shape data preparation and ingestion.
- Market data → Indicators: feeds · Prepared market series flow into feature computation.
- Indicators → Signals: feeds · Indicators are composed into signal logic.
- Signals → Strategy core: drives · Signals are assembled into higher-level strategy behavior.
- Strategy core → Risk rules: constrained by · Strategy intent is filtered through risk and trade-eligibility rules.
- Risk rules → Execution: authorizes · Risk decisions gate order and position handling.
- Execution → Backtest: simulated by · Execution semantics are exercised in offline evaluation.
- Backtest → Optimization: evaluated by · Backtest outputs feed parameter search workflows.
- Backtest → Reporting: summarized by · Evaluation results are turned into research reports.
- Execution → Monitoring: observed by · Runtime state and safety signals are tracked for observability.
- Run backtest → Backtest: orchestrates · Script entrypoint launches offline research runs.
- Walkforward → Backtest: orchestrates · Walkforward workflows use the backtesting engine.
- Research report → Reporting: orchestrates · Batch reporting consumes research outputs.
- Sync params → Keltner breakout: syncs · Research parameters are mapped into the NT8 strategy.
- Sync params → VWAP reversion: syncs · Research parameters are mapped into the NT8 strategy.
- Strategy core → Keltner breakout: maps to · Core strategy logic has an NT8 counterpart.
- Strategy core → VWAP reversion: maps to · Core strategy logic has an NT8 counterpart.
- Run backtest → Config: reads · Research entrypoints are configured from the central settings.
- Sync params → Config: reads · Parameter sync relies on the central configuration.
