//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- declaramos los parámetros del recurso gráfico
string rc_name="Resource";
uint rc_width=100;
uint rc_height=100;
uint rc_data[];
uint rc_size=rc_width*rc_height;
ResetLastError();
//--- establecemos el tamaño del array en píxeles
if(ArrayResize(rc_data,rc_size)!=rc_size)
{
Print("ArrayResize() failed. Error code: ",GetLastError());
return;
}
//--- rellenamos la matriz de píxeles con un color transparente y creamos un recurso gráfico basado en él
ArrayInitialize(rc_data,0x00FFFFFF);
if(!ResourceCreate(rc_name,rc_data,rc_width,rc_height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE))
{
Print("ResourceCreate() failed. Error code: ",GetLastError());
return;
}
Print("Size of created recource array: ",rc_data.Size());
//--- comprobamos el recurso gráfico creado.
//--- obtenemos los datos de hora y precio de la siguiente barra
MqlTick tick={};
if(!SymbolInfoTick(Symbol(),tick))
{
Print("SymbolInfoTick() failed. Error code: ",GetLastError());
return;
}
//--- creamos un objeto "Dibujo" en las coordenadas del precio y la hora del último tick
string obj_name="Bitmap";
if(!ObjectCreate(0,obj_name,OBJ_BITMAP,0,tick.time,tick.bid))
{
Print("ObjectCreate() failed. Error code: ",GetLastError());
return;
}
//--- establecemos una anchura y una altura del objeto de dibujo creado igual a la anchura y la altura del recurso gráfico.
//--- establecemos el punto de anclaje del objeto en su centro.
ObjectSetInteger(0,obj_name,OBJPROP_XSIZE,rc_width);
ObjectSetInteger(0,obj_name,OBJPROP_YSIZE,rc_height);
ObjectSetInteger(0,obj_name,OBJPROP_ANCHOR,ANCHOR_CENTER);
//--- establecemos un recurso gráfico creado previamente como archivo de imagen para el objeto de dibujo
//--- en este caso, para especificar el nombre del recurso gráfico que se va a utilizar, debemos añadir antes de su nombre "::"
ObjectSetString(0,obj_name,OBJPROP_BMPFILE,"::"+rc_name);
//--- establecemos el color DodgerBlue con una trasparencia 200
uint clr=ColorToARGB(clrDodgerBlue,200);
//--- rellenamos todo el array de píxeles del recurso gráfico con el color establecido
ArrayInitialize(rc_data,clr);
//--- actualizamos los datos del recurso gráfico
Update(rc_name,rc_data,rc_width,rc_height,true);
//--- esperamos 3 segundos antes de leer los datos del recurso gráfico
Print("Wait 3 seconds before ResourceReadImage()");
Sleep(3000);
//--- leemos la imagen del recurso en un nuevo array de píxeles
uint rc_data_copy[];
uint w=0,h=0;
ResetLastError();
if(!ResourceReadImage("::"+rc_name,rc_data_copy,w,h))
{
Print("ResourceReadImage() failed. Error code: ",GetLastError());
return;
}
//--- establecemos el color OrangeRed con una transparencia
clr=ColorToARGB(clrOrangeRed,200);
//--- rellenamos todo el array de píxeles con el color establecido y creamos un nuevo recurso gráfico basado en él
ArrayInitialize(rc_data_copy,clr);
if(!ResourceCreate(rc_name+"Copy",rc_data_copy,rc_width,rc_height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE))
{
Print("New ResourceCreate() failed. Error code: ",GetLastError());
return;
}
Print("Size of created new recource array: ",rc_data_copy.Size());
//--- creamos un objeto "Etiqueta gráfica" en las coordenadas del precio y la hora del último tick
string obj_name2="BitmapLabel";
if(!ObjectCreate(0,obj_name2,OBJ_BITMAP_LABEL,0,0,0))
{
Print("ObjectCreate() failed. Error code: ",GetLastError());
return;
}
//--- obtenemos las coordenadas de pantalla según el precio y la hora obtenidos previamente
int x=0,y=0;
if(!ChartTimePriceToXY(0,0,tick.time,tick.bid,x,y))
{
Print("New ChartTimePriceToXY() failed. Error code: ",GetLastError());
return;
}
//--- establecemos una anchura y una altura del objeto de etiqueta gráfica creado igual a la anchura y la altura del recurso gráfico.
//--- establecemos el punto de anclaje del objeto en su centro.
ObjectSetInteger(0,obj_name2,OBJPROP_XSIZE,rc_width);
ObjectSetInteger(0,obj_name2,OBJPROP_YSIZE,rc_height);
ObjectSetInteger(0,obj_name2,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
ObjectSetInteger(0,obj_name2,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,obj_name2,OBJPROP_YDISTANCE,y);
//--- establecemos el recurso gráfico copiado como archivo de imagen para el objeto de etiqueta gráfica
//--- en este caso, para especificar el nombre del recurso gráfico que se va a utilizar, debemos añadir antes de su nombre "::"
ObjectSetString(0,obj_name2,OBJPROP_BMPFILE,"::"+rc_name+"Copy");
//--- cambiamos el color de un nuevo objeto de etiqueta gráfica
Print("Wait 3 seconds before changing color to GreenYellow");
Sleep(3000);
//--- establecemos el color GreenYellow con una transparencia 200
clr=ColorToARGB(clrGreenYellow,200);
//--- rellenamos todo el array de píxeles del recurso gráfico con el color establecido
ArrayInitialize(rc_data_copy,clr);
//--- actualizamos los datos del recurso gráfico
Update(rc_name+"Copy",rc_data_copy,rc_width,rc_height,true);
//--- esperamos tres segundos y eliminamos los recursos y ambos objetos
Print("Wait 3 seconds before deleting both objects");
Sleep(3000);
Print("Deleting Resource and all Bitmap objects");
ResourceFree("::"+rc_name);
ResourceFree("::"+rc_name+"Copy");
ObjectDelete(0,obj_name);
ObjectDelete(0,obj_name2);
}
//+------------------------------------------------------------------+
//| Actualiza los datos del recurso gráfico |
//+------------------------------------------------------------------+
void Update(const string res_name,const uint &pixel_data[],const uint width,const uint height,const bool redraw)
{
//--- si se ha transmitido un tamaño cero, salimos
if(width==0 || height==0)
return;
//--- actualizamos los datos de los recursos y redibujamos el gráfico
if(ResourceCreate(res_name,pixel_data,width,height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE) && redraw)
ChartRedraw();
}
|