MachGold Portfolio Aggregator — Multi-Asset Backtest Simulation Tool
Jul 2026 – Jul 2026What Was Built
MachGold Portfolio Aggregator is a custom cTrader plugin and analytical simulation engine engineered in C# to model true, shared-capital performance across multi-asset algorithmic strategies. The platform ingests raw JSON backtest exports from cAlgo-based cBots and reconstructs trade entries, execution events, and position closes into a single unified timeline. Features include a priority-ordered event queue that processes account state transitions in strict chronological order, shared margin and capital allocation tracking, dynamic account depletion logic that excludes trades occurring after simulated capital exhaustion, and comparative reporting that presents isolated asset performance alongside true portfolio-level drawdown and equity curves.
Why Was It Built
Standard retail backtesting environments, including native cTrader and MetaTrader terminals, evaluate strategy performance on an isolated, asset-by-asset basis. Simply summing individual profit factors and drawdowns across multiple currency pairs or indices creates a misleading representation of portfolio health because it ignores margin overlap, simultaneous exposure spikes, and total shared-account risk. MachGold Portfolio Aggregator was built to solve this analytical blind spot by simulating how multiple strategy instances consume a single, shared capital pool in real time, allowing quantitative traders to accurately evaluate maximum portfolio drawdown, margin strain, and account blow-up risks prior to live capital deployment.
How It Works
The application functions as an event-driven backtest processor. First, the user exports raw trade history JSON files generated by cAlgo strategies across various financial instruments. The engine parses these exports, extracts trade open timestamps, position sizes, stop-loss triggers, and close events, and pushes them into a global, timestamp-sorted priority queue. As the simulation steps through time, it maintains a single dynamic account balance. When a trade entry event triggers, the engine verifies whether sufficient unallocated margin exists in the shared account pool. If capital is available, the trade is marked active and margin is locked; if the account has suffered total depletion from concurrent losing positions, subsequent trades are flagged as rejected due to capital exhaustion. When position close events fire, capital and realized gains or losses are returned to the shared pool, accurately updating portfolio drawdown metrics and equity curves.
What Broke and How Did I Fix It
Developing an event-driven multi-asset aggregator introduced several algorithmic and data alignment challenges. Initial simulation runs produced inaccurate drawdown figures because trade execution timestamps exported from different chart timeframes exhibited slight millisecond clock skew and out-of-order array structures. This was fixed by implementing a custom timeline sorting algorithm utilizing a min-heap priority queue, ensuring every trade open and close event was evaluated in absolute chronological order regardless of export source. Additionally, early versions caused memory bottlenecks when parsing large historical tick and trade logs across a dozen assets, which was resolved by refactoring the JSON ingestion pipeline to stream records iteratively using `System.Text.Json` instead of loading entire datasets into memory. Finally, edge-case discrepancies occurred when handling simultaneous close-and-open events on the same timestamp, which was corrected by prioritizing position close events over new position entries to reflect immediate balance availability accurately.