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.

※記事内に広告を含む場合があります。
ベアちゃん@東京シストレ: 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.