Brokeret LogoDocs
Plugins / Copy Trade/Introduction

Introduction

An overview of the Copy Trade plugin for real-time trade replication between master and follower accounts.

What is Copy Trade?

Brokeret Copy Trade is a native C++ MT5 Server Plugin that automatically replicates trades from master accounts to follower (copier) accounts in real-time. It runs inside the MT5 Trade Server process and monitors deals via the Server API — no external dependencies or services required.

How It Works

Trade Open Flow

  1. Master account opens a position (e.g. BUY 1.0 EURUSD)
  2. MT5 server fires a deal event
  3. Plugin checks if the account matches any configured master
  4. For each follower rule, the plugin:
    • Calculates volume (multiplier or fixed)
    • Determines direction (same or reverse)
    • Sets comment to cp:<master_position_id> for tracking
    • Executes the trade on the follower account

Trade Close Flow

  1. Master closes a position
  2. Plugin queries the follower's open positions
  3. Finds the matching position by its cp: comment
  4. Closes it with the correct direction and volume

Close By Support

MT5's Close By operation (closing a BUY against a SELL) uses a separate callback. The plugin handles both normal close and Close By to ensure all follower positions are closed correctly.

Lot Sizing Modes

ModeExampleDescription
Multipliermult, 1.0Follower lot = master lot × multiplier
Multipliermult, 0.5Follower lot = half of master lot
Fixedfixed, 0.01Follower always trades 0.01 lot regardless of master

Trade Direction

DirectionDescription
sameFollower copies the same direction (BUY→BUY, SELL→SELL)
reverseFollower trades opposite direction (BUY→SELL, SELL→BUY)

Position Tracking

The plugin uses comment-based tracking to maintain master-follower position relationships:

  • On open: follower position comment is set to cp:<master_position_id>
  • On close: plugin finds the matching follower position by comment and closes it
  • Survives server restarts — no in-memory state required for position matching

A built-in recursion guard ignores deals with cp: comments to prevent infinite loops.

Multi-Follower Support

One master can copy to multiple followers simultaneously. Each follower can have independent lot sizing and direction settings.

Master 1001
    ├── Follower 2001: multiplier 1.0, same direction
    ├── Follower 2002: multiplier 0.5, same direction
    └── Follower 2003: fixed 0.01, reverse direction

Key Features

  • Real-time trade replication — Copies trades as they happen via deal events
  • Multi-follower rules — One master can copy to many followers
  • Flexible lot sizing — Multiplier or fixed lot modes
  • Reverse copy — Option to trade opposite direction
  • Comment-based tracking — Survives server restarts
  • Close By support — Handles MT5 hedge close operations
  • REST API — Manage rules remotely without MT5 Admin access
  • Rule persistence — API rules saved to file and survive restarts
  • Live config reload — Rules update without server restart

Supported Entry Types

Entry TypeHandledDescription
ENTRY_INYesNew position opened
ENTRY_OUTYesPosition fully closed
ENTRY_INOUTYesPosition reversed
ENTRY_OUT_BYYesClosed by hedge position

Next Steps