0% found this document useful (0 votes)
137 views1 page

MQL4 Exercises Functions

The document discusses exercises involving built-in functions in MQL4/5. It covers void functions like TerminalClose and Sleep, as well as functions that return values like AccountNumber, TimeCurrent, and MathRand. The exercises demonstrate using built-in functions to close terminals, play sounds, get the current time, and generate random numbers.

Uploaded by

rayoldigital
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views1 page

MQL4 Exercises Functions

The document discusses exercises involving built-in functions in MQL4/5. It covers void functions like TerminalClose and Sleep, as well as functions that return values like AccountNumber, TimeCurrent, and MathRand. The exercises demonstrate using built-in functions to close terminals, play sounds, get the current time, and generate random numbers.

Uploaded by

rayoldigital
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercises

Void Functions

1. TerminalClose() is a built-in function that sets a flag for the exit of the trading platform. This
function takes a single integer argument. Create a script that makes a single call to this
function, with an argument value of 0.

2. Create a script that is similar to the Hello World script. However, this time, rather than using
the Print() function, Use the Comment() built-in function instead.

Recommended: Observe what happens when the script is loaded on a chart.

3. Create a new version of the script described in the 1 st exercise in this section. This time,
however, modify the script so it would only call the TerminalClose() function after 10 seconds.
Use the Sleep() built-in function to accomplish this.

Hint: The Sleep() function takes a single argument of type integer, expressed in milliseconds.

4. Create a new version of the script described in the 3 rd exercise in this section. This time,
however, the statements within the OnStart() function should be moved to a user-defined
function. Give the function a name of "terminal_close" (without quotes). Then, make a single
call of the function within the OnStart() handler.

5. Create a new version of the script described in the 4 th exercise in this section, but this time,
as an expert advisor. Make a function call to the user-defined function terminal_close within
the OnDeinit() handler.

Recommended: Observe what happens after removing the expert advisor from the chart.

Functions that Return a Value

1. Create a new script. Within the OnStart() function, declare a integer variable named
account_number. Initialize this variable to the return value of the AccountNumber() built-in
function. Then, print the account number using the Print() function.

2. Create a new version of the Hello World script. Replace the Print function with PlaySound,
another built-in function. Rather than using the argument "Hello world!", replace it with
"alert.wav". Store the output of the PlaySound() function in a boolean variable named
"play_sound" (without the double quotes).

Recommended: Observe what happens when the script is executed.

3. Create a new script. Declare a datetime variable named "current_time" (without the quotes)
and initialize it to the return value of the TimeCurrent() function. Print the value of the
variable.

4. Create a new expert advisor. Within the OnTick() function, declare an integer named
"random" (without quotes). Initialize this integer variable with the return value of the
MathRand() built-in function. On the next statement, print the value of the variable.

Recommended: See whether or not the expert advisor is printing random numbers every tick.

Note: You may wonder where all the built-in functions come from. These are all described in
the documentation. We will start using it once we go to more advanced lessons.

Copyright © 2010. Enrico Lambino. All Rights Reserved.

You might also like