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:
π API Key & AuthenticationΒΆ
Connecting to MetaRPC production endpoints (mt4.mrpc.pro:443) requires an API key:
- Sign Up: Create an account for free at https://mrpc.pro/signup.
- 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.
- 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
GetIdmanually. The SDK automatically derives your deterministic account ID from your credentials upon initialization and attaches both theidandAPIKeyheaders 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:
- π Your First Project - Build and run a working project in 10 minutes.
- πΊοΈ Project Map - Understand the 3 architectural layers and interaction flow.
- π Glossary - Essential MetaTrader 4 and algorithmic trading terminology.
- π£ MT4 for Beginners - Step-by-step terminal setup and demo account guide.
- π‘ gRPC Streaming - Subscribe to ticks, trades, DOM, and position updates.
- π Return Codes - Complete reference of broker and gateway return codes.