Rotating text at an arbitrary angle

Objects of text types — label OBJ_TEXT (in quotation coordinates) and panel OBJ_LABEL (in screen coordinates) — allow you to rotate the text label at an arbitrary angle. For this purpose, there is the OBJPROP_ANGLE property of type double. It contains the angle in degrees relative to the object's normal position. Positive values rotate the object counterclockwise, and negative values rotate it clockwise.

However, it should be borne in mind that angles with a difference that is a multiple of 360 degrees are identical, that is, for example, +315 and -45 are the same. Rotation is performed around the anchor point on the object (by default, top left).

Rotate OBJ_LABEL and OBJ_TEXT objects by angles that are multiples of 45 degrees

Rotate OBJ_LABEL and OBJ_TEXT objects by angles that are multiples of 45 degrees

You can check the effect of the OBJPROP_ANGLE property on an object using the ObjectAngle.mq5 script. It creates a text label OBJ_LABEL in the center of the window, after which it begins to periodically rotate 45 degrees until the user stops the process.

void OnStart()
{
   const string name = "ObjAngle";
   ObjectCreate(0nameOBJ_LABEL000);
   const int centerX = (int)ChartGetInteger(0CHART_WIDTH_IN_PIXELS) / 2;
   const int centerY = (int)ChartGetInteger(0CHART_HEIGHT_IN_PIXELS) / 2;
   ObjectSetInteger(0nameOBJPROP_XDISTANCEcenterX);
   ObjectSetInteger(0nameOBJPROP_YDISTANCEcenterY);
   ObjectSetInteger(0nameOBJPROP_ANCHORANCHOR_CENTER);
   
   int angle = 0;
   while(!IsStopped())
   {
      ObjectSetString(0nameOBJPROP_TEXTStringFormat("Angle: %d°"angle));
      ObjectSetDouble(0nameOBJPROP_ANGLEangle);
      angle += 45;
     
      ChartRedraw();
      Sleep(1000);
   }
   ObjectDelete(0name);
}

The text displays the current value of the angle.