mql4 array
时间: 2023-11-23 20:44:25 浏览: 85
MQL4 is a programming language used for developing trading strategies in MetaTrader 4 platform. Arrays in MQL4 are used to store multiple values of the same type. They are declared with a specific size and can be accessed using index numbers.
Here's an example of declaring and using an array in MQL4:
```mql4
// Declare an array of integers with a size of 5
int myArray[5];
// Assign values to the array elements
myArray[0] = 10;
myArray[1] = 20;
myArray[2] = 30;
myArray[3] = 40;
myArray[4] = 50;
// Access and print array elements
Print("Element at index 0: ", myArray[0]);
Print("Element at index 2: ", myArray[2]);
// Loop through the array
for (int i = 0; i < ArraySize(myArray); i++) {
Print("Element at index ", i, ": ", myArray[i]);
}
```
In this example, we declare an array `myArray` of size 5 and assign values to its elements using index numbers. We can access and print array elements using the index number. The `ArraySize()` function is used to get the number of elements in the array. Finally, a loop is used to iterate over the array and print all its elements.
Note that arrays in MQL4 are zero-based, meaning the first element has an index of 0.
阅读全文