//--- descripción
#property description "El script crea el objeto \"Gráfico\"."
//--- 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="Chart"; // Nombre del objeto
input string InpSymbol="EURUSD"; // Símbolo
input ENUM_TIMEFRAMES InpPeriod=PERIOD_H1; // Período
input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // Esquina para el enlace
input int InpScale=2; // Escala
input bool InpDateScale=true; // Visualización de la escala del tiempo
input bool InpPriceScale=true; // Visualización de la escala del precio
input color InpColor=clrRed; // Color del borde durante la selección
input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Estilo de la línea durante la selección
input int InpPointWidth=1; // Tamaño del punto para los movimientos
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 el objeto "Gráfico" |
//+------------------------------------------------------------------+
bool ObjectChartCreate(const long chart_ID=0, // ID del gráfico
const string name="Chart", // nombre del objeto
const int sub_window=0, // número de subventana
const string symbol="EURUSD", // símbolo
const ENUM_TIMEFRAMES period=PERIOD_H1, // período
const int x=0, // coordenada por el eje X
const int y=0, // coordenada por el eje Y
const int width=300, // ancho
const int height=200, // alto
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // esquina para el enlace
const int scale=2, // escala
const bool date_scale=true, // visualización de la escala del tiempo
const bool price_scale=true, // isualización de la escala del precio
const color clr=clrRed, // color del borde durante la selección
const ENUM_LINE_STYLE style=STYLE_SOLID, // estilo de la línea durante la selección
const int point_width=1, // tamaño del punto de desplazamiento
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 el objeto "Gráfico"
if(!ObjectCreate(chart_ID,name,OBJ_CHART,sub_window,0,0))
{
Print(__FUNCTION__,
": ¡Fallo al crear el objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
//--- establecemos las coordenadas del objeto
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- establecemos el tamaño del objeto
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- 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 símbolo
ObjectSetString(chart_ID,name,OBJPROP_SYMBOL,symbol);
//--- ponemos el período
ObjectSetInteger(chart_ID,name,OBJPROP_PERIOD,period);
//--- establecemos la escala
ObjectSetInteger(chart_ID,name,OBJPROP_CHART_SCALE,scale);
//--- mostramos (true) u ocultamos (false) la escala del tiempo
ObjectSetInteger(chart_ID,name,OBJPROP_DATE_SCALE,date_scale);
//--- mostramos (true) u ocultamos (false) la escala del precio
ObjectSetInteger(chart_ID,name,OBJPROP_PRICE_SCALE,price_scale);
//--- establecemos el color del contorno durante el modo de selección del objeto activado
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- establecemos el estilo del contorno durante el modo de selección del objeto activado
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- establecemos el tamaño del punto de enlace con el que se puede mover el objeto
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,point_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);
}
//+------------------------------------------------------------------+
//| Establece el símbolo y el período del objeto "Gráfico" |
//+------------------------------------------------------------------+
bool ObjectChartSetSymbolAndPeriod(const long chart_ID=0, // ID del gráfico (no objeto)
const string name="Chart", // nombre del objeto
const string symbol="EURUSD", // símbolo
const ENUM_TIMEFRAMES period=PERIOD_H1) // período de tiempo
{
//--- anulamos el valor del error
ResetLastError();
//--- establecemos el símbolo y el período del objeto "Gráfico"
if(!ObjectSetString(chart_ID,name,OBJPROP_SYMBOL,symbol))
{
Print(__FUNCTION__,
": ¡Fallo al establecer el símbolo para el objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_PERIOD,period))
{
Print(__FUNCTION__,
": ¡Fallo al establecer el período para el objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
//--- ejecución con éxito
return(true);
}
//+------------------------------------------------------------------+
//| Mueve el objeto "Gráfico" |
//+------------------------------------------------------------------+
bool ObjectChartMove(const long chart_ID=0, // ID del gráfico (no objeto)
const string name="Chart", // nombre del objeto
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 el objeto
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x))
{
Print(__FUNCTION__,
": ¡Fallo al mover la coordenada X del objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
{
Print(__FUNCTION__,
": ¡Fallo al mover la coordenada Y del objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
//--- ejecución con éxito
return(true);
}
//+------------------------------------------------------------------+
//| Cambia el tamaño del objeto "Gráfico" |
//+------------------------------------------------------------------+
bool ObjectChartChangeSize(const long chart_ID=0, // ID del gráfico (no objeto)
const string name="Chart", // nombre del objeto
const int width=300, // ancho
const int height=200) // alto
{
//--- anulamos el valor del error
ResetLastError();
//--- cambiamos las dimensiones del objeto
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width))
{
Print(__FUNCTION__,
": ¡Fallo al cambiar el ancho del objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
{
Print(__FUNCTION__,
": ¡Fallo al cambiar el alto del objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
//--- ejecución con éxito
return(true);
}
//+------------------------------------------------------------------+
//| Devuelve ID del objeto "Gráfico" |
//+------------------------------------------------------------------+
long ObjectChartGetID(const long chart_ID=0, // ID del gráfico (no objeto)
const string name="Chart") // nombre del objeto
{
//--- preparamos la variable para recibir ID del objeto "Gráfico"
long id=-1;
//--- anulamos el valor del error
ResetLastError();
//--- recibimos ID
if(!ObjectGetInteger(chart_ID,name,OBJPROP_CHART_ID,0,id))
{
Print(__FUNCTION__,
": ¡Fallo al recibir ID del objeto \"Gráfico\"! Código del error = ",GetLastError());
}
//--- devolución del resultado
return(id);
}
//+------------------------------------------------------------------+
//| Elimina el objeto "Gráfico" |
//+------------------------------------------------------------------+
bool ObjectChartDelete(const long chart_ID=0, // ID del gráfico (no objeto)
const string name="Chart") // nombre del objeto
{
//--- anulamos el valor del error
ResetLastError();
//--- eliminamos el botón
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": ¡Fallo al eliminar el objeto \"Gráfico\"! Código del error = ",GetLastError());
return(false);
}
//--- ejecución con éxito
return(true);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- obtenemos el número de símbolos en la ventana "Observación del mercado"
int symbols=SymbolsTotal(true);
//--- comprobamos si hay el símbolo con el nombre especificado en la lista de los símbolos
bool exist=false;
for(int i=0;i<symbols;i++)
if(InpSymbol==SymbolName(i,true))
{
exist=true;
break;
}
if(!exist)
{
Print("¡Error. Este símbolo ",InpSymbol," no está en la ventana \"Observación del Mercado\"!");
return;
}
//--- comprobando si los parámetros de entrada son correctos
if(InpScale<0 || InpScale>5)
{
Print("¡Error. Los parámetros de entrada no son correctos!");
return;
}
//--- 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;
}
//--- establecemos las coordenadas del objeto "Gráfico" y su tamaño
int x=(int)x_distance/16;
int y=(int)y_distance/16;
int x_size=(int)x_distance*7/16;
int y_size=(int)y_distance*7/16;
//--- creamos el objeto "Gráfico"
if(!ObjectChartCreate(0,InpName,0,InpSymbol,InpPeriod,x,y,x_size,y_size,InpCorner,InpScale,InpDateScale,
InpPriceScale,InpColor,InpStyle,InpPointWidth,InpBack,InpSelection,InpHidden,InpZOrder))
{
return;
}
//--- redibujamos el gráfico y esperamos 1 segundo
ChartRedraw();
Sleep(1000);
//--- extendemos el objeto "Gráfico"
int steps=(int)MathMin(x_distance*7/16,y_distance*7/16);
for(int i=0;i<steps;i++)
{
//--- cambiamos el tamaño
x_size+=1;
y_size+=1;
if(!ObjectChartChangeSize(0,InpName,x_size,y_size))
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 medio segundo
Sleep(500);
//--- cambiamos el período del gráfico
if(!ObjectChartSetSymbolAndPeriod(0,InpName,InpSymbol,PERIOD_M1))
return;
ChartRedraw();
//--- retardo de tres segundos
Sleep(3000);
//--- eliminamos el objeto
ObjectChartDelete(0,InpName);
ChartRedraw();
//--- esperamos 1 segundo
Sleep(1000);
//---
}
|