How shine0078/nt8bridgeclean works
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: backtest.py Backtest · strategy.py Strategy core · config.json Config · sync_nt8_params.py Sync params
Components 22
Discovery lane
Windows and NinjaTrader UI inspection scripts used only for read-only discovery and validation.
- NT8 windows · Enumerates visible NinjaTrader 8 windows for discovery-only inspection.
Scripts/discover_nt8_windows.py - UIA probe · Inspects Strategy Analyzer controls through UI Automation.
Scripts/discover_strategy_analyzer_uia.py - Win32 probe · Inspects Strategy Analyzer windows and tree structure through Win32 tooling.
Scripts/discover_strategy_analyzer_win32.py - Validate config · 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 · Loads and interprets configuration for the Python core.
nt8bridge/config.py - Market data · Normalizes and serves market series into the research pipeline.
nt8bridge/data.py - Indicators · Transforms market data into technical features and derived series.
nt8bridge/indicators.py - Signals · Combines features into actionable strategy signals.
nt8bridge/signals.py - Strategy core · Coordinates strategy logic from signals, filters, and regime context.
nt8bridge/strategy.py - Risk rules · Applies sizing, stop, timeout, and trade-eligibility constraints.
nt8bridge/risk.py - Execution · Defines order and trade-handling boundaries for the core engine.
nt8bridge/execution.py - Backtest · Runs offline evaluation of strategies against historical data.
nt8bridge/backtest.py - Optimization · Searches parameter space for candidate strategy settings.
nt8bridge/optimize.py - Reporting · Converts research and evaluation outputs into summaries and artifacts.
nt8bridge/reporting.py - Monitoring · 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 · Propagates research parameters into NT8-facing strategy inputs.
Scripts/sync_nt8_params.py - Keltner breakout · NinjaTrader 8 implementation of the breakout strategy.
Strategies/KeltnerBreakout.cs - VWAP reversion · 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 · Central configuration artifact driving mode, parameters, and safety gates.
Config/config.json - Run backtest · Batch entrypoint for offline backtesting workflows.
Scripts/run_backtest.py - Walkforward · Runs rolling evaluation over parameter and time windows.
Scripts/run_keltner_walkforward.py - Research report · Generates summaries from research outputs for published artifacts.
Scripts/report_keltner_research.py
Connections 24
- 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.