MQL4|Color Type (color)

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

Usage

The color type (color) is used to represent colors. Colors are specified in the RGB format (red, green, blue), with each color component ranging from 0 to 255. Colors are used for graphical elements and indicators’ drawings.

Size

The size of the color type is 4 bytes. This is because each color component is represented by 1 byte (8 bits), maintaining a total of 24 bits of color information.

Value Range

The value range of the color type is from 0x000000 to 0xFFFFFF. This hexadecimal representation is due to each RGB component ranging from 0 to 255. For example, 0xFF0000 represents red, 0x00FF00 represents green, and 0x0000FF represents blue.

Usage Example

Below is an example of using the color type. In this example, a line is drawn on the chart with the specified color.

void OnStart() {
    // Define colors
    color redColor = clrRed;
    color greenColor = clrGreen;
    color blueColor = clrBlue;

    // Draw a red horizontal line on the chart
    ObjectCreate(0, "RedLine", OBJ_HLINE, 0, 0, 1.1);
    ObjectSetInteger(0, "RedLine", OBJPROP_COLOR, redColor);

    // Draw a green vertical line on the chart
    ObjectCreate(0, "GreenLine", OBJ_VLINE, 0, TimeCurrent(), 0);
    ObjectSetInteger(0, "GreenLine", OBJPROP_COLOR, greenColor);

    // Draw a blue arrow on the chart
    ObjectCreate(0, "BlueArrow", OBJ_ARROW, 0, TimeCurrent(), 1.2);
    ObjectSetInteger(0, "BlueArrow", OBJPROP_COLOR, blueColor);
    ObjectSetInteger(0, "BlueArrow", OBJPROP_ARROWCODE, 233);
}

In this code, the following steps utilize the color type:

  1. Predefined colors clrRed, clrGreen, and clrBlue are used to set redColor, greenColor, and blueColor.
  2. The ObjectCreate function draws a red horizontal line on the chart. OBJ_HLINE indicates the horizontal line object type.
  3. The ObjectSetInteger function sets the horizontal line’s color to red.
  4. Similarly, a green vertical line (OBJ_VLINE) and a blue arrow (OBJ_ARROW) are drawn, and their colors are set.

The color type is very convenient for specifying the colors of objects and graphical elements on the chart. Using appropriate colors enhances the chart’s visibility and information transmission.

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