TAG

mql5

  • November 8, 2025

Working with Parameters

Overview Input parameters in MQL5 let you configure a program without editing its source code. By declaring variables with the input keyword, you expose them in the EA/Script settings dialog and in the Strategy Tester, making your logic flexible, testable, and ready for optimization. What You Will Be Able to Do Code Example Execution Steps Key Point Use input for user-facing, configurable settings; use normal variables for internal state. Typed inputs (including enums) make your EA safer and easier to test, and they integrate seamlessly with the Strategy Tester for optimization. Next Section → Next: Reading the Log

  • November 8, 2025

Running in the Strategy Tester

Overview The Strategy Tester in MetaTrader 5 lets you run your Expert Advisors (EAs) on historical data to verify logic, performance, and risk—without using real money. You can backtest on different symbols and timeframes, review reports and logs, and even optimize input parameters to search for better settings. Mastering the tester is a crucial step before any live deployment. What You Will Be Able to Do Code Example This minimal EA uses an input parameter (fast MA period) so you can adjust it in the tester and later optimize it. Execution Steps Key Point Backtesting validates logic and reveals performance characteristics before risking capital. Use inputs to make scenarios reproducible and optimization-ready, and always confirm findings on out-of-sample data to avoid overfitting. Next Section → Next: Working with Parameters

  • November 8, 2025

Before Using OrderSend

Overview Before you call OrderSend() in MQL5, you must prepare a valid trade request and verify the trading environment. This includes checking terminal permissions, symbol settings, volume constraints, filling mode, and prices. Use OrderCheck() to validate a request and review the broker’s response before sending a live order. What You Will Be Able to Do Code Example Execution Steps Key Point Validate first, trade second. Always normalize volume, confirm symbol settings, pick a supported filling mode, and run OrderCheck(). Proper pre-trade checks prevent most rejections and improve EA reliability. Next Section → Next: Running in the Strategy Tester

  • November 8, 2025

The OnTick Function

Overview In an Expert Advisor, the OnTick() function is executed automatically every time a new market tick arrives — meaning each time the Bid or Ask price changes. This makes it the central “loop” of your EA, where decisions are evaluated and orders are executed. Every trading algorithm in MQL5 depends on how efficiently OnTick() processes incoming data. What You Will Be Able to Do Code Example Execution Steps Key Point OnTick() is event-driven — it runs automatically for each market update. It’s the heart of every Expert Advisor, where signals, calculations, and trade executions are performed. Keep OnTick() efficient and lightweight to ensure your EA runs smoothly, even on fast-moving markets. Next Section → Next: Before Using OrderSend

  • November 7, 2025

What Is an Expert Advisor

Overview An Expert Advisor (EA) in MQL5 is an automated trading system that runs inside MetaTrader 5. It monitors the market, makes trading decisions, and can execute orders automatically based on your strategy. Unlike scripts, which run once and stop, an EA operates continuously — it reacts to every market tick or event. EAs are written in the same MQL5 language used for indicators and scripts, but they rely on special event-handling functions to process data and react to market updates. What You Will Be Able to Do Code Example Execution Steps Key Point An Expert Advisor is event-driven: OnInit() runs once at startup, OnTick() executes on every market update, and OnDeinit() runs when the EA is removed. This structure makes it ideal for continuous strategy execution, order management, and monitoring. Next Section → Next: The OnTick Function

  • November 7, 2025

Reading Indicator Values

Overview In MQL5, indicator outputs are stored in buffers. You access these buffers programmatically using a handle (e.g., from iMA(), iRSI()) and the CopyBuffer() function. This lets your scripts and Expert Advisors consume analytical data directly for decisions. What You Will Be Able to Do Code Example Execution Steps Key Point Indicator outputs live in buffers. Create a handle, call CopyBuffer() for the desired buffer index and bar range, then release the handle with IndicatorRelease(). Use ArraySetAsSeries(true) when you want buf[0] to represent the most recent bar. Next Section → Next: What Is an Expert Advisor

  • November 7, 2025

What Are Indicators

Overview In MQL5, an indicator analyzes market data and visualizes results on a chart or subwindow. Unlike Scripts and Expert Advisors, indicators do not send orders; they compute values and draw them as lines, histograms, or arrows so you can interpret trends and signals. You can use built-in indicators (e.g., Moving Average, RSI) or create custom ones with MQL5. What You Will Be Able to Do Code Example Execution Steps Key Point Indicators compute and draw values; they do not trade. They are often used as inputs to Expert Advisors or for visual decision support on charts. Next Section → Next: Reading Indicator Values  

  • November 6, 2025

Getting the Symbol Name

Overview Many MQL5 programs need to know which instrument they are running on. The built-in Symbol() function returns the current chart’s symbol as a string, allowing you to print it for diagnostics or use it to request prices, trade, or load indicator data. What You Will Be Able to Do Code Example Execution Steps Key Point Symbol() is context-sensitive: it returns the symbol of the chart where the program runs. When an EA must handle multiple instruments, pass symbol names explicitly instead of relying on the current chart context. Next Section → Next: What Are Indicators

  • November 6, 2025

Understanding Print

Overview The Print() function is the simplest way to observe what your MQL5 program is doing. It writes messages to the terminal logs so you can confirm variable values, execution order, and error conditions. Outputs appear in the Experts tab (for Scripts/EAs/Indicators) and also in the terminal’s log files. Using Print() early and often is the fastest path to reliable debugging. What You Will Be Able to Do Code Example Execution Steps Key Point Print() is your primary tracing tool. Log the inputs, intermediate values, and branch decisions that matter. Keep messages short, consistent, and searchable to speed up debugging. Next Section → Next: Getting the Symbol Name

  • November 5, 2025

Your First Script

Overview In MQL5, a script is a simple program designed to perform a single action and then terminate. Unlike Expert Advisors (EAs), which run continuously with every new market tick, a script executes its code only once when launched. Scripts are ideal for quick operations such as sending a message to the log, closing all trades, or performing calculations that do not require constant updates. This section will guide you through creating and running your first MQL5 script. What You Will Be Able to Do Code Example Execution Steps Key Point Scripts always begin execution with the OnStart() function and stop automatically once the code inside it finishes. They are best suited for one-time tasks, such as modifying trade positions, exporting data, or testing short pieces of code. As you progress, you’ll find scripts useful for both learning MQL5 and performing small maintenance operations in your trading workflow. Next Section→ Next: Understanding Print