MQL4|Integer Type (int)

※記事内に広告を含む場合があります。

Purpose

The integer type (int) is used to represent integer values. Integers are positive or negative numbers that do not include decimal points. In a program, they are used for various purposes such as loop counters, indexes, flags, and calculations.

Size

The size of an integer type is 4 bytes, which means it occupies 32 bits of memory space.

Value Range

The value range for integer types is from -2147483648 to 2147483647. This wide range allows efficient handling of many calculations and operations.

Example of Usage

Below is an example of using the integer type. In this example, an integer type is used as a loop counter to output messages based on specific conditions.

void OnTick() {
int count = 0;
double sum = 0.0;
int periods = 10;

// Sum the prices of the last 10 bars
for (int i = 0; i < periods; i++) {
sum += Close[i];
count++;
}

// Calculate the average price
double average = sum / count;

Print("The average price of the last " + count + " bars is " + average + ".");
}

In this code, the integer type is used as follows:

  1. Declare and initialize int count and int periods.
  2. Use a for loop to sum the prices of the last 10 bars.
  3. Increment count with each iteration of the loop.
  4. Calculate the average price by dividing the sum by the number of bars.
  5. Output the result with the Print function.

In this way, the integer type is used in various parts of the program to perform calculations and loop processing efficiently. Understanding and appropriately using the integer type can improve the performance and readability of the program.

※記事内に広告を含む場合があります。
ベアちゃん@東京シストレ: One of Japan's oldest MetaTrader FX automated trading developers 🔧. With over 15 years of professional experience, he boasts achievements such as winning first place in the Tradency Tournament '15 🥇 and being the runner-up in the 3rd EA-1 Grand Prix 🥈. He has also appeared on Radio Nikkei and is currently active as an executive of Trilogy Corporation (a registered investment advisory and agency business) [Registration number: 372, Director of the Kinki Finance Bureau, Ministry of Finance]. To join the board of Trilogy Corporation, he underwent a rigorous personal examination by the Kinki Finance Bureau, and his name is now registered with the Kinki Finance Bureau. Becoming an executive officer of a registered investment advisory and agency business requires passing this stringent personal examination. Utilizing his extensive knowledge as a former senior design engineer, he provides insights into the development of high-performance Expert Advisors (EAs), the latest trading technologies, and market analysis. He delivers professional strategies and tips to traders aiming to optimize their FX trading and maximize profits.

This website uses cookies.