MQL4|Real Number Type (double)

Usage
The real number type (double) is used to represent real numerical values that include decimals. The precision of real values is very high, making them especially useful in scenarios requiring precise numerical values, such as financial calculations. For example, they are used in price calculations, moving averages, and risk management calculations.

Size
The size of a real number type is 8 bytes. This allows handling a very wide range of numerical values with high precision.

Range of Values
The range of real number type values is from -1.7×10^-308 to 1.7×10^308. This extensive range allows for precise handling of very large and very small numbers.

Example Usage
Below is an example of using the real number type. In this example, two moving averages are calculated, and their difference is output.

void OnTick() {
    // Calculate the 14-period Simple Moving Average (SMA)
    double ma_short = iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, 0);

    // Calculate the 50-period Simple Moving Average (SMA)
    double ma_long = iMA(NULL, 0, 50, 0, MODE_SMA, PRICE_CLOSE, 0);

    // Calculate the difference between the moving averages
    double ma_difference = ma_short - ma_long;

    // Output the result
    Print("The difference between the short-term and long-term moving averages is " + ma_difference + ".");
}

In this code, the real number type is used in the following steps:

  1. The iMA function is used to calculate the 14-period Simple Moving Average (SMA), which is stored in ma_short.
  2. The iMA function is also used to calculate the 50-period Simple Moving Average (SMA), which is stored in ma_long.
  3. The difference between the short-term and long-term moving averages is calculated and stored in ma_difference.
  4. The Print function is used to output the calculation result.

Thus, the real number type is essential for performing high-precision calculations. In financial trading, using the real number type for calculations such as prices and moving averages allows for accurate trading decisions.