In this article you will learn the utility of one of the most used functions in custom tools, MQL5 Print(). You will see some use cases, examples and how you can use it.
What is the MQL5 Print() Function?
The MQL5 Print() function is one of the most essential tools for debugging and tracking your program’s behavior.
If you’re just starting with MQL5, understanding how to use Print effectively can save you hours of troubleshooting.
The Print function is a built-in MQL5 function that outputs information to the MetaTrader 5 Terminal’s “Experts” tab.
It’s mainly used for debugging, tracking variable values, and checking program flow. Think of it as a way to see what’s happening inside your code in real time.
Honestly, I cannot even count the number of times I have used the function, it’s just too many and it appears in all my programs several times.
Syntax:
|
1 |
Print(argument1, argument2, ...); |
You can pass multiple arguments to the Print function, and it will automatically convert them to strings and display them.
Why is the MQL5 Print() Function Useful?
Definitely one of the most popular and useful functions in MQL5.
The main situations to use it are:
- Debugging: Quickly identify errors by checking variable values and program flow.
- Monitoring: Track the performance and behavior of your expert advisors, indicators, and scripts.
- Verification: Ensure calculations and logic are executing as expected.
- Logging: I use it a lot to log some of the actions so that they are tracked in the terminal for later analysis.
How to Use the Print Function
The use of Print() is actually very simple and there are a few ways depending on what you are trying to do.
Printing Simple Text
The simplest use of the Print function is to display a message:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//built-in function OnStart for scripts //triggers the action when a script is loaded on chart void OnStart(){ //Basic Print function will print Hello World in the Experts tab of MT5 Print("Hello World"); //Declaring and initializing variable i with value 123 int i=123; //Printing the variable value Print(i); } |


Printing Variables
The Print function can display the value of variables, which is helpful for tracking their changes:
|
1 2 3 4 |
void OnStart() { double spread = Ask - Bid; Print("Current spread: ", spread); } |
Output:
|
1 |
Current spread: 1.5 |
Combining Strings and Variables
You can easily mix text and variables in a single Print statement:
|
1 2 3 4 5 |
void OnStart() { string symbol = Symbol(); double price = Bid; Print("The current price of ", symbol, " is ", price); } |
Output:
|
1 |
The current price of EURUSD is 1.2050 |
Using Format Specifiers (StringFormat)
For more control over output formatting, combine Print with StringFormat:
|
1 2 3 4 |
void OnStart() { double balance = AccountInfoDouble(ACCOUNT_BALANCE); Print(StringFormat("Your account balance is: %.2f USD", balance)); } |
Output:
|
1 |
Your account balance is: 10000.50 USD |
Common Mistakes to Avoid when using MQL5 Print()
Although very simple there are a few errors that can happen when using the function, and you should pay attention to avoid them.
- Forgetting to include variables: Ensure all variables in
Printare defined and initialized. - Not checking the “Experts” tab: Output only appears in this section of the MetaTrader terminal.
- Using
Printexcessively: Too manyPrintcalls can slow down performance, especially in live trading.
Best Practices for Using Print
Some recommendations to use the MQL5 Print() function effectively and efficiently are:
- Use clear, descriptive messages: Help yourself understand what’s being printed.
- Combine multiple variables: Avoid multiple
Printstatements when one will do. - Clean up debugging code: Remove or comment out
Printstatements before deploying live EAs or indicators.
This last one in particular, Cleaning up, is very important to maintain a strong performance and not overutilize resources both in terms of CPU and storage capacity.
Conclusion
The Print function in MQL5 is an indispensable tool for every developer.
By using it effectively, you can debug, monitor, and refine your scripts with ease.
Whether you’re tracking variables or ensuring program logic is sound, mastering Print will make your development process far smoother.
For questions or support please Contact Us.