//--- descripción #property description "El script crea el objeto gráfico \"Etiqueta rectangular\"." //--- mostramos la ventana de los parámetros de entrada durante el arranque del script #property script_show_inputs //--- los parámetros de entrada del script input string InpName="RectLabel"; // Nombre de la etiqueta input color InpBackColor=clrSkyBlue; // Color del fondo input ENUM_BORDER_TYPE InpBorder=BORDER_FLAT; // Tipo del borde input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // Esquina del gráfico para el enlace input color InpColor=clrDarkBlue; // Color del contorno plano (Flat) input ENUM_LINE_STYLE InpStyle=STYLE_SOLID; // Estilo del contorno plano (Flat) input int InpLineWidth=3; // Grosor del contorno plano (Flat) input bool InpBack=false; // Objeto al fondo input bool InpSelection=true; // Seleccionar para mover input bool InpHidden=true; // Ocultar en la lista de objetos input long InpZOrder=0; // Prioridad para el clic del ratón //+------------------------------------------------------------------+ //| Crea la etiqueta rectangular | //+------------------------------------------------------------------+ bool RectLabelCreate(const long chart_ID=0, // ID del gráfico const string name="RectLabel", // nombre de la etiqueta const int sub_window=0, // número de subventana const int x=0, // coordenada por el eje X const int y=0, // coordenada por el eje Y const int width=50, // ancho const int height=18, // alto const color back_clr=C'236,233,216', // color del fondo const ENUM_BORDER_TYPE border=BORDER_SUNKEN, // tipo del borde const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // esquina del gráfico para el enlace const color clr=clrRed, // color del contorno plano (Flat) const ENUM_LINE_STYLE style=STYLE_SOLID, // estilo del contorno plano const int line_width=1, // grosor del contorno plano const bool back=false, // al fondo const bool selection=false, // seleccionar para mover const bool hidden=true, // ocultar en la lista de objetos const long z_order=0) // prioridad para el clic del ratón { //--- anulamos el valor del error ResetLastError(); //--- creamos la etiqueta rectangular if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0)) { Print(__FUNCTION__, ": ¡Fallo al crear la etiqueta rectangular! Código del error = ",GetLastError()); return(false); } //--- establecemos las coordenadas de la etiqueta ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); //--- establecemos las dimensiones de la etiqueta ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); //--- establecemos el color del fondo ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); //--- establecemos el tipo del borde ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border); //--- establecemos la esquina del gráfico respecto a la cual van a determinarse las coordenadas del punto ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- establecemos el color del contorno plano (en modo Flat) ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- establecemos el estilo de las líneas del contorno plano ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- establecemos el grosor del contorno plano ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_width); //--- mostramos en el primer plano (false) o al fondo (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- activar (true) o desactivar (false) el modo de desplazamiento de la etiqueta con ratón ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- ocultamos (true) o mostramos (false) el nombre del objeto gráfico en la lista de objetos ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- establecemos la prioridad para obtener el evento de cliquear sobre el gráfico ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- ejecución con éxito return(true); } //+------------------------------------------------------------------+ //| Mueve la etiqueta rectangular | //+------------------------------------------------------------------+ bool RectLabelMove(const long chart_ID=0, // ID del gráfico const string name="RectLabel", // nombre de la etiqueta const int x=0, // coordenada por el eje X const int y=0) // coordenada por el eje Y { //--- anulamos el valor del error ResetLastError(); //--- movemos la etiqueta rectangular if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x)) { Print(__FUNCTION__, ": ¡Fallo al mover la coordenada X de la etiqueta! Código del error = ",GetLastError()); return(false); } if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y)) { Print(__FUNCTION__, ": ¡Fallo al mover la coordenada Y de la etiqueta! Código del error = ",GetLastError()); return(false); } //--- ejecución con éxito return(true); } //+------------------------------------------------------------------+ //| Cambia el tamaño de la etiqueta rectangular | //+------------------------------------------------------------------+ bool RectLabelChangeSize(const long chart_ID=0, // ID del gráfico const string name="RectLabel", // nombre de la etiqueta const int width=50, // ancho de la etiqueta const int height=18) // alto de la etiqueta { //--- anulamos el valor del error ResetLastError(); //--- cambiamos las dimensiones de la etiqueta if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width)) { Print(__FUNCTION__, ": ¡Fallo al cambiar el ancho de la etiqueta! Código del error = ",GetLastError()); return(false); } if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height)) { Print(__FUNCTION__, ": ¡Fallo al cambiar el alto de la etiqueta! Código del error = ",GetLastError()); return(false); } //--- ejecución con éxito return(true); } //+------------------------------------------------------------------+ //| Cambia el tipo del borde de la etiqueta rectangular | //+------------------------------------------------------------------+ bool RectLabelChangeBorderType(const long chart_ID=0, // ID del gráfico const string name="RectLabel", // nombre de la etiqueta const ENUM_BORDER_TYPE border=BORDER_SUNKEN) // tipo del borde { //--- anulamos el valor del error ResetLastError(); //--- cambiamos el tipo del borde if(!ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border)) { Print(__FUNCTION__, ": ¡Fallo al cambiar el tipo del borde! Código del error = ",GetLastError()); return(false); } //--- ejecución con éxito return(true); } //+------------------------------------------------------------------+ //| Elimina la etiqueta rectangular | //+------------------------------------------------------------------+ bool RectLabelDelete(const long chart_ID=0, // ID del gráfico const string name="RectLabel") // nombre de la etiqueta { //--- anulamos el valor del error ResetLastError(); //--- eliminamos la etiqueta if(!ObjectDelete(chart_ID,name)) { Print(__FUNCTION__, ": ¡Fallo al eliminar la etiqueta rectangular! Código del error = ",GetLastError()); return(false); } //--- ejecución con éxito return(true); } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- tamaño de la ventana del gráfico long x_distance; long y_distance; //--- definimos las dimensiones de la ventana if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance)) { Print("¡Fallo al obtener el ancho del gráfico! Código del error = ",GetLastError()); return; } if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance)) { Print("¡Fallo al obtener el alto del gráfico! Código del error = ",GetLastError()); return; } //--- definimos las coordenadas de la etiqueta rectangular int x=(int)x_distance/4; int y=(int)y_distance/4; //--- establecemos las dimensiones de la etiqueta int width=(int)x_distance/4; int height=(int)y_distance/4; //--- creamos la etiqueta rectangular if(!RectLabelCreate(0,InpName,0,x,y,width,height,InpBackColor,InpBorder,InpCorner, InpColor,InpStyle,InpLineWidth,InpBack,InpSelection,InpHidden,InpZOrder)) { return; } //--- redibujamos el gráfico y esperamos 1 segundo ChartRedraw(); Sleep(1000); //--- cambiamos el tamaño de la etiqueta rectangular int steps=(int)MathMin(x_distance/4,y_distance/4); for(int i=0;i<steps;i++) { //--- cambiamos el tamaño width+=1; height+=1; if(!RectLabelChangeSize(0,InpName,width,height)) return; //--- comprobamos si el trabajo del script ha sido finalizado forzosamente if(IsStopped()) return; //--- redibujamos el gráfico y esperamos 0,01 segundo ChartRedraw(); Sleep(10); } //--- retardo de 1 segundo Sleep(1000); //--- cambiamos el tipo del borde if(!RectLabelChangeBorderType(0,InpName,BORDER_RAISED)) return; //--- redibujamos el gráfico y esperamos 1 segundo ChartRedraw(); Sleep(1000); //--- cambiamos el tipo del borde if(!RectLabelChangeBorderType(0,InpName,BORDER_SUNKEN)) return; //--- redibujamos el gráfico y esperamos 1 segundo ChartRedraw(); Sleep(1000); //--- eliminamos la etiqueta RectLabelDelete(0,InpName); ChartRedraw(); //--- esperamos 1 segundo Sleep(1000); //--- } |