ObjectSetInteger

Establece el valor de la propiedad correspondiente de un objeto. La propiedad del objeto debe ser de los tipos datetime, int, color, bool o char. Existen 2 variantes de la función.

Configuración del valor de la propiedad sin modificador

bool  ObjectSetInteger(
   long                             chart_id,          // identificador del gráfico
   string                           name,              // nombre
   ENUM_OBJECT_PROPERTY_INTEGER     prop_id,           // propiedad
   long                             prop_value         // valor
   );

Configuración del valor de la propiedad indicando el modificador

bool  ObjectSetInteger(
   long                             chart_id,          // identificador del gráfico
   string                           name,              // nombre
   ENUM_OBJECT_PROPERTY_INTEGER     prop_id,           // propiedad
   int                              prop_modifier,     // modificador
   long                             prop_value         // valor
   );

Parámetros

chart_id

[in]  Identificador del gráfico. 0 significa el gráfico actual.

name

[in]  Nombre del objeto.

prop_id

[in]  Identificador de la propiedad del objeto. Su valor puede ser uno de los valores de la enumeración ENUM_OBJECT_PROPERTY_INTEGER.

prop_modifier

[in]  Modificador de la propiedad especificada. La mayoría de las propiedades no requiere el modificador.

prop_value

[in]  Valor de la propiedad.

Valor devuelto

Devuelve true sólo si el comando de modificar las propiedades de un objeto gráfico se ha enviado con éxito al gráfico. De lo contrario devuelve false. Para la información más detallada sobre el error hay que llamar a la función GetLastError().

Nota

La función usa una llamada asincrónica, esto significa que la función no espera a la ejecución del comando que se ha colocado con éxito en la cola del gráfico indicado, sino que devuelve el control de inmediato.

Para comprobar el resultado de la ejecución en un gráfico ajeno se puede usar una función que solicite la propiedad indicada del objeto. Pero, en esta caso, además, se deberá tener en cuenta que estas funciones se colocan al final de la cola de comandos del gráfico y esperan el resultado de la ejecución, es decir, pueden consumir un tiempo considerable. Hay que tener esta circunstancia en cuenta al trabajar con multitud de objetos en el gráfico.

Un ejemplo de cómo crear una tabla de colores Web

//+------------------------------------------------------------------+
//|                                               Table of Web Colors|
//|                         Copyright 2011, MetaQuotes Software Corp |
//|                                       https://www.metaquotes.net |
//+------------------------------------------------------------------+
#define X_SIZE 140      // ancho del objeto OBJ_EDIT
#define Y_SIZE 33       // ancho del objeto OBJ_EDIT
//+------------------------------------------------------------------+
//| Array de colores Web                                             |
//+------------------------------------------------------------------+
color ExtClr[140]=
  {
   clrAliceBlue,clrAntiqueWhite,clrAqua,clrAquamarine,clrAzure,clrBeige,clrBisque,clrBlack,clrBlanchedAlmond,
   clrBlue,clrBlueViolet,clrBrown,clrBurlyWood,clrCadetBlue,clrChartreuse,clrChocolate,clrCoral,clrCornflowerBlue,
   clrCornsilk,clrCrimson,clrCyan,clrDarkBlue,clrDarkCyan,clrDarkGoldenrod,clrDarkGray,clrDarkGreen,clrDarkKhaki,
   clrDarkMagenta,clrDarkOliveGreen,clrDarkOrange,clrDarkOrchid,clrDarkRed,clrDarkSalmon,clrDarkSeaGreen,
   clrDarkSlateBlue,clrDarkSlateGray,clrDarkTurquoise,clrDarkViolet,clrDeepPink,clrDeepSkyBlue,clrDimGray,
   clrDodgerBlue,clrFireBrick,clrFloralWhite,clrForestGreen,clrFuchsia,clrGainsboro,clrGhostWhite,clrGold,
   clrGoldenrod,clrGray,clrGreen,clrGreenYellow,clrHoneydew,clrHotPink,clrIndianRed,clrIndigo,clrIvory,clrKhaki,
   clrLavender,clrLavenderBlush,clrLawnGreen,clrLemonChiffon,clrLightBlue,clrLightCoral,clrLightCyan,
   clrLightGoldenrod,clrLightGreen,clrLightGray,clrLightPink,clrLightSalmon,clrLightSeaGreen,clrLightSkyBlue,
   clrLightSlateGray,clrLightSteelBlue,clrLightYellow,clrLime,clrLimeGreen,clrLinen,clrMagenta,clrMaroon,
   clrMediumAquamarine,clrMediumBlue,clrMediumOrchid,clrMediumPurple,clrMediumSeaGreen,clrMediumSlateBlue,
   clrMediumSpringGreen,clrMediumTurquoise,clrMediumVioletRed,clrMidnightBlue,clrMintCream,clrMistyRose,clrMoccasin,
   clrNavajoWhite,clrNavy,clrOldLace,clrOlive,clrOliveDrab,clrOrange,clrOrangeRed,clrOrchid,clrPaleGoldenrod,
   clrPaleGreen,clrPaleTurquoise,clrPaleVioletRed,clrPapayaWhip,clrPeachPuff,clrPeru,clrPink,clrPlum,clrPowderBlue,
   clrPurple,clrRed,clrRosyBrown,clrRoyalBlue,clrSaddleBrown,clrSalmon,clrSandyBrown,clrSeaGreen,clrSeashell,
   clrSienna,clrSilver,clrSkyBlue,clrSlateBlue,clrSlateGray,clrSnow,clrSpringGreen,clrSteelBlue,clrTan,clrTeal,
   clrThistle,clrTomato,clrTurquoise,clrViolet,clrWheat,clrWhite,clrWhiteSmoke,clrYellow,clrYellowGreen
  };
//+------------------------------------------------------------------+
//| Creación e inicialización del objeto OBJ_EDIT                    |
//+------------------------------------------------------------------+
void CreateColorBox(int x,int y,color c)
  {
//--- generaremos el nombre para nuevo objeto según el nombre del color 
   string name="ColorBox_"+(string)x+"_"+(string)y;
//--- crearemos nuevo objeto OBJ_EDIT
   if(!ObjectCreate(0,name,OBJ_EDIT,0,0,0))
     {
      Print("Cannot create: '",name,"'");
      return;
     }
//--- fijaremos las coordinadas del punto de enlace, ancho y alto en píxeles
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x*X_SIZE);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y*Y_SIZE);
   ObjectSetInteger(0,name,OBJPROP_XSIZE,X_SIZE);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,Y_SIZE);
//--- estableceremos el color del texto del objeto 
   if(clrBlack==c) ObjectSetInteger(0,name,OBJPROP_COLOR,clrWhite);
   else            ObjectSetInteger(0,name,OBJPROP_COLOR,clrBlack);
//--- estableceremos el color del fondo
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,c);
//--- estableceremos el texto del objeto OBJ_EDIT correspondiente al color del fondo
   ObjectSetString(0,name,OBJPROP_TEXT,(string)c);
  }
//+------------------------------------------------------------------+
//| Función del inicio del script                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- crearemos una tabla de los bloques coloreados 7x20
   for(uint i=0;i<140;i++)
      CreateColorBox(i%7,i/7,ExtClr[i]);
  }

Véase también

Tipos de objetos, Propiedades de objetos