Skip to content

Getting Started with CSharpMT4ΒΆ

Quick Setup & Overview - Start automating your trading with CSharpMT4 (C# for MetaTrader 4) in minutes.


🎯 What is CSharpMT4?¢

CSharpMT4 is an industrial-grade, type-safe C# client library for interacting with MetaTrader 4 terminals via high-performance gRPC. It eliminates complex C++ DLL wrappers and provides direct, reliable programmatic trading.

🌟 Key Advantages¢

  • πŸš€ High Throughput: Native gRPC streaming for sub-millisecond price ticks and trade execution.
  • πŸ›‘οΈ Three-Layer Architecture: Low-level gRPC (MT4Account), typed wrapper methods (MT4Service), and high-level convenience (MT4Sugar).
  • πŸ”„ Resilient Connection: Auto-reconnect, exponential backoff, and transparent channel healing.
  • πŸ’Ό Production Ready: Fully verified across institutional accounts, hedge fund systems, and automated retail bots.

πŸ“¦ InstallationΒΆ

Install CSharpMT4 via your standard C# package manager:

dotnet add package MetaRPC.MT4

πŸ”‘ API Key & AuthenticationΒΆ

Connecting to MetaRPC production endpoints (mt4.mrpc.pro:443) requires an API key:

  1. Sign Up: Create an account for free at https://mrpc.pro/signup.
  2. Generate API Key: In your MetaRPC Portal dashboard at https://mrpc.pro/my, go to API Keys to generate and copy your personal API token.
  3. Configure Connection: Pass your API key / token along with the server address (mt4.mrpc.pro:443) in your connection settings.


πŸ†” Automatic Account ID & AuthenticationΒΆ

MetaRPC endpoints require two credentials for all terminal operations: 1. APIKey: Your personal authentication token from https://mrpc.pro/my (obtained by registering at https://mrpc.pro/signup). Sent in the APIKey header. 2. id: A deterministic account GUID derived from your MetaTrader user (login number) and password.

πŸ’‘ Seamless Automation: You do not need to call GetId manually. The SDK automatically derives your deterministic account ID from your credentials upon initialization and attaches both the id and APIKey headers to all requests and streaming subscriptions.

πŸ”Œ Minimal Connection ExampleΒΆ

Here is how easy it is to initialize MT4Account, connect to your MetaTrader terminal, and retrieve your account balance:

var account = new MT4Account(user, password, grpcServer, null);
await account.ConnectByServerNameAsync(serverName, "EURUSD", 30);
var summary = await account.AccountSummaryAsync();
Console.WriteLine($"Balance: {summary.AccountBalance}, Equity: {summary.AccountEquity}");

πŸ—ΊοΈ Documentation Road MapΒΆ

To get the most out of CSharpMT4, follow this suggested reading order:

  1. πŸš€ Your First Project - Build and run a working project in 10 minutes.
  2. πŸ—ΊοΈ Project Map - Understand the 3 architectural layers and interaction flow.
  3. πŸ“– Glossary - Essential MetaTrader 4 and algorithmic trading terminology.
  4. 🐣 MT4 for Beginners - Step-by-step terminal setup and demo account guide.
  5. πŸ“‘ gRPC Streaming - Subscribe to ticks, trades, DOM, and position updates.
  6. πŸ“Š Return Codes - Complete reference of broker and gateway return codes.