FTMO Academy
Course
20m read

Trading Programming Basics: MQL4/5, cAlgo, and Python

MetaTrader and cTrader both support embedded programming environments that let you translate a trading strategy into code, automate its execution, and test it against historical data. Trading platforms are not just charting tools.

This lesson covers the three main ecosystems: MQL for MetaTrader, cAlgo for cTrader, and Python as a general-purpose option. By the end, you will know which path applies to your setup before you start learning.

Why Traders Learn to Code

Automation solves two specific problems in manual trading: execution inconsistency and availability.

A coded strategy executes trades under exactly the same conditions every time, without hesitation or second-guessing. It runs 24 hours a day, 5 days a week, without fatigue, and backtests the same logic against years of historical price data in seconds, compressing work that would take a manual trader months.

What automation does not fix: a losing strategy runs losing trades faster and at greater scale. Programming adds precision to whatever logic you give it. The quality of the underlying trading idea remains entirely your responsibility.

Three types of programs traders build:

  • Expert Advisors / cBots are fully automated trading robots that open, manage, and close positions based on coded conditions
  • Custom indicators are visual analysis tools overlaid on charts; they calculate values from price data but do not execute trades
  • Scripts are single-run programs that perform a one-time action, such as closing all open positions or placing stop losses on existing trades
Warning

An automated system that does not account for the maximum daily loss and maximum loss limits of your account will breach them just as a manual trader would. Risk controls must be coded into the EA, not assumed. Automation grants no exemption from evaluation rules.

Your Platform Determines Your Language

The language you use is set by your platform, not by personal preference.

MQL4 only runs on MetaTrader 4. MQL5 only runs on MetaTrader 5. cAlgo is the native environment for cTrader. Python connects to MetaTrader 5 or cTrader through separate packages and application programming interfaces (APIs), which gives it cross-platform flexibility but requires more setup than platform-native languages.

PlatformLanguageProgram TypesNotes
MetaTrader 4MQL4EAs, indicators, scriptsProcedural; legacy but widely used
MetaTrader 5MQL5EAs, indicators, scripts, servicesObject-oriented; supports Python API
cTradercAlgo / C#cBots, indicators, pluginsModern syntax; full OOP
cTraderPython SDKcBots, indicatorsNewer; smaller community than C#
MT5 + externalPythonData analysis, backtesting, executionVia MetaTrader5 Python package

Choose your platform first. The programming language follows from that decision.

Your language choice depends entirely on which platform your broker supports and which one fits your trading style.

Your platform sets the language: MQL4 runs on MetaTrader 4, MQL5 on MetaTrader 5 and cAlgo / C# on cTrader, while Python connects to MetaTrader 5 or cTrader through a package or API.

MQL4 and MQL5: Programming for MetaTrader

MQL (MetaQuotes Language) is a programming language developed by MetaQuotes and embedded directly into the MetaTrader platform. You write, compile, and debug code inside MetaEditor, an integrated development environment included with every MetaTrader installation. No external tools or additional downloads are needed to start.

MQL4 uses a procedural programming model. You define functions and call them in sequence. The syntax follows familiar C conventions and is accessible without prior programming knowledge. The community library of existing Expert Advisors and custom indicators is the largest available for any retail trading platform. MT4 remains the dominant platform at many forex brokers, which means MQL4 skills are still directly applicable in 2026.

MQL5 introduced object-oriented programming: classes, inheritance, and polymorphism. Execution speed is significantly faster than MQL4. MT5 added capabilities not available in the previous version, including hedging mode, native integration with an economic calendar, support for additional order types, and a larger range of timeframes. MQL5 also supports direct integration with Python through an official external package.

Choose your version:

  • MQL4: your broker runs MT4, you want immediate access to the largest library of community EAs and indicators, or you prefer a simpler procedural starting point
  • MQL5: your broker runs MT5, you want modern language features and faster execution, or you plan to extend your workflow with Python-based analysis

Learning Curve

Prior programming experience helps but is not required. MQL syntax follows C conventions: variables, conditionals, loops, and functions. The trading-specific layer, which includes functions like OrderSend, iMA, and PositionSelect, is unique to MQL and learned separately from general programming.

A realistic timeline with consistent daily practice: a basic EA with entry and exit logic in 2–4 weeks. A production-ready EA with proper position sizing, error handling, and drawdown controls requires 3–6 months of dedicated work.

The right starting point is MetaEditor’s built-in example EAs. Read one through, modify a parameter, observe what changes. Build on working code before writing anything from scratch.

Tip

MetaEditor includes MQL5 Wizard, which generates a complete EA framework from a guided form. It handles structure, event handlers, and boilerplate code automatically. Use it to produce your first compilable EA before writing code manually.

cAlgo: Programming for cTrader

cAlgo is the automation environment built into cTrader. Unlike MQL, which is a trading-specific language, cAlgo programs are written in C#, a full, general-purpose object-oriented language used well beyond financial markets.

cTrader Automate is the built-in development environment. It supports integration with Microsoft Visual Studio for traders who prefer a professional integrated development environment (IDE), and provides access to the .NET software development kit (SDK) for more advanced development work.

Two main program types:

  • cBots are automated trading robots, the cTrader equivalent of MetaTrader’s Expert Advisors
  • Custom indicators are user-coded analysis tools displayed on charts

cTrader also supports Python through its Python SDK, though the C# path is better documented and more widely used.

When to choose cAlgo: you trade on cTrader, you have prior C# or .NET experience, or you want a modern object-oriented environment with cleaner syntax than MQL. The cTrader Store marketplace also lets you browse, buy, or rent existing cBots and indicators, which is a useful reference before you start building your own.

cBots vs Expert Advisors

The concepts are equivalent: both cBots and Expert Advisors automate trade execution based on coded conditions. The difference is syntax and platform architecture.

cBots use C# event handlers: OnStart(), OnTick(), OnBar(), and OnStop(), which fire in response to specific market events. The OnBar() handler executes once at the close of each completed candle. It is exclusive to cTrader and simplifies bar-by-bar logic compared to equivalent MQL implementations.

Backtesting is built directly into cTrader Automate. cBots can be tested against historical data in the same environment where they run live, without switching tools.

Python: The General-Purpose Path

Python is not embedded in any trading platform. It connects to them through packages and APIs, which requires more initial setup but gives access to tools and libraries unavailable in MQL or cAlgo.

Two practical use cases for traders:

MT5 Python API: MetaTrader 5 includes an official Python package (MetaTrader5) that allows data retrieval, signal calculation, and trade execution directly from Python scripts. The MetaTrader 5 terminal must remain open and connected for the script to operate.

cTrader Python SDK: cTrader supports Python-based cBots through its SDK. The C# path remains better documented, but Python support is growing.

Beyond direct platform integration, Python’s value for traders comes from its broader ecosystem: backtesting libraries such as Backtrader, data analysis with pandas and NumPy, and straightforward integration with machine learning tools for those moving into quantitative strategy development.

Python vs MQL/cAlgo

Python’s primary advantage is ecosystem breadth. It is platform-agnostic, and statistical analysis, data science, and machine learning tools integrate directly. For traders who already know Python, the MT5 Python API or the cTrader SDK is the fastest path to automation.

The practical constraint: Python is not compiled into the platform. A Python strategy running through the MT5 API depends on an active terminal connection. If the connection drops, the script stops. A compiled MQL5 EA embedded in the terminal continues running independently of any external scripts.

For traders with no programming background, MQL4/5 or cAlgo are the better starting points. The development environment, documentation, and built-in functions are all designed specifically around trading. Python’s generality becomes an advantage once trading logic is solid and the goal shifts to extending it with external tools.

Keep in mind

Python scripts connected via the MT5 API depend on the MetaTrader 5 terminal remaining active and connected. This is an architectural constraint to plan for in production deployment, not a reliability flaw. It requires a different operational setup than a native MQL EA.

Where to Start

The decision process follows three steps:

  1. Identify your trading platform
  2. Choose the language tied to that platform
  3. Start with the official development environment and its built-in examples

Starting resources by language:

  • MQL4/5: MetaEditor (included with MetaTrader, free), official documentation at mql5.com, MQL5.community forum for practical questions
  • cAlgo: cTrader Automate (built into cTrader, free), official cTrader help documentation, cTrader community forum
  • Python: Python.org documentation, MetaTrader5 Python package documentation on mql5.com, pandas and NumPy tutorials for data handling

What to build first: replicate a strategy you already trade manually. A moving average crossover or a basic Relative Strength Index (RSI) threshold entry covers the key technical requirements: entry logic, position sizing, and stop-loss placement. The scope stays manageable. Strategies that are difficult to explain in plain language will be harder to debug in code.

Test every automated strategy on a demo account before running it on an evaluation or simulated account. Verify that position sizing, stop-loss logic, and trade frequency all behave exactly as intended.

Warning

Account performance is evaluated by the same rules regardless of whether trades are placed manually or by an EA. An automated strategy that mismanages position sizing, ignores drawdown limits, or overtrades will affect your account under the same conditions as any other trading behaviour. For the framework to build a rules-based strategy, see Build Robust Trading Strategy, and Risk

Management.

Share

All information provided on this site is intended solely for educational purposes related to trading on financial markets and does not serve in any way as a specific investment recommendation, business recommendation, investment opportunity analysis or similar general recommendation regarding the trading of investment instruments. FTMO only provides services of simulated trading and educational tools for traders. The information on this site is not directed at residents in any country or jurisdiction where such distribution or use would be contrary to local laws or regulations. FTMO companies do not act as a broker and do not accept any deposits. The offered technical solution for the FTMO platforms and data feed is powered by liquidity providers.