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.