Designing a Multi-Account Copy-Trading System for My and Pine Strategies
Summary
The article presents a JavaScript framework for copying positions from one leader account to multiple subscriber accounts, including when the signal strategy is written in My or Pine. It uses a leader-subscriber structure: the leader polls its positions, detects additions, removals, and size changes, then notifies subscribers to place corresponding orders. Followers can scale copied trades by a fixed position ratio or by the relative account equity. The design also includes retrying failed orders and a routine to compare follower holdings with the leader’s.
The example describes a backtest setup with multiple exchange objects and random trades across several instruments to exercise the copying logic. It also discusses alternatives to polling positions, such as monitoring platform data or reacting to pushed messages, which may reduce API requests. The implementation is a starting framework rather than a complete production system: the article identifies subscription controls and richer monitoring as future extensions. Polling, order execution, and position synchronization can still fail or diverge, and the sample does not establish live trading performance.
Key ideas
- A leader-subscriber design lets one strategy distribute position changes to multiple accounts.
- The example detects added, removed, and resized positions by comparing successive leader snapshots.
- Followers can scale trades by a fixed ratio or by the accounts’ relative equity.
- Order retries and position checks are included to handle some execution failures and account drift.
- Event-driven notifications are presented as an alternative to polling that may reduce API requests.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.