MQLArticles/Utils/Objectos 2D.mqh

720 lines
79 KiB
MQL5
Raw Permalink Normal View History

2025-09-22 09:08:13 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Objectos 2D.mqh |
//| Niquel y Leo |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Niquel y Leo"
#property link "https://www.mql5.com"
#property strict
#ifndef MQH_OBJECTS_2D
#define MQH_OBJECTS_2D
#include "..\\Utils\\Funciones Array.mqh"
//+------------------------------------------------------------------+
bool VLineCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre de la l<EFBFBD>nea
const int sub_window, // <EFBFBD>ndice de subventana
datetime time, // hora de la l<EFBFBD>nea
const color clr, // color de la l<EFBFBD>nea
const ENUM_LINE_STYLE style, // estilo de la l<EFBFBD>nea
const int width, // grosor de la l<EFBFBD>nea
const bool back, // al fondo
const bool selection, // seleccionar para mover
const bool ray,
const string tooltip, // continuaci<EFBFBD>n de la l<EFBFBD>nea abajo
const long z_order = 0) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos la l<EFBFBD>nea vertical
if(!ObjectCreate(chart_ID, name, OBJ_VLINE, sub_window, time, 0))
{
Print(__FUNCTION__,
": <00>Fallo al crear la l<00>nea vertical! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos el color de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el estilo de visualizaci<EFBFBD>n de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- establecemos el grosor de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, 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 l<EFBFBD>nea con rat<EFBFBD>n
//--- cuando el objeto gr<EFBFBD>fico se crea usando la funci<EFBFBD>n ObjectCreate, por defecto el objeto
//--- no se puede seleccionar y mover. Mientras que dentro de este m<EFBFBD>todo el par<EFBFBD>metro selection
//--- por defecto es igual a true, lo que permite seleccionar y mover este objeto
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
//--- activar (true) o desactivar (false) el modo de visualizaci<EFBFBD>n de la l<EFBFBD>nea en las subventanas del gr<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_RAY, ray);
//--- establecemos la prioridad para obtener el evento de cliquear sobre el gr<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, tooltip);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool TrendCreate(long chart_ID, // ID del gr<EFBFBD>fico
string name, // Nombre de la l<EFBFBD>nea
int sub_window, // <EFBFBD>ndice de subventana
datetime time1, // hora del primer punto
double price1, // precio del primer punto
datetime time2, // hora del segundo punto
double price2, // precio del segundo punto
color clr, // color de la l<EFBFBD>nea
ENUM_LINE_STYLE style, // estilo de la l<EFBFBD>nea
int width, // grosor de la l<EFBFBD>nea
bool back, // al fondo
bool selection, // seleccionar para mover
string toltip
)
{
//--- establecemos las coordenadas de los puntos de anclaje si todav<EFBFBD>a no han sido establecidas
//--- anulamos el valor del error
ResetLastError();
//--- creamos la l<EFBFBD>nea de tendencia seg<EFBFBD>n las coordenadas establecidas
if(!ObjectCreate(chart_ID, name, OBJ_TREND, sub_window, time1, price1, time2, price2))
{
Print(__FUNCTION__,
": <00>Fallo al crear la l<00>nea de tendencia! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos el color de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width);
ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, toltip);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
return(true);
}
//+------------------------------------------------------------------+
bool TrendaAngleCreate(long chart_ID, // ID del gr<EFBFBD>fico
string name, // Nombre de la l<EFBFBD>nea
int sub_window, // <EFBFBD>ndice de subventana
datetime time1, // hora del primer punto
double price1, // precio del primer punto
datetime time2, // hora del segundo punto
double price2, // precio del segundo punto
color clr, // color de la l<EFBFBD>nea
ENUM_LINE_STYLE style, // estilo de la l<EFBFBD>nea
int width, // grosor de la l<EFBFBD>nea
bool back, // al fondo
bool selection, // seleccionar para mover
string toltip
)
{
//--- establecemos las coordenadas de los puntos de anclaje si todav<EFBFBD>a no han sido establecidas
//--- anulamos el valor del error
ResetLastError();
//--- creamos la l<EFBFBD>nea de tendencia seg<EFBFBD>n las coordenadas establecidas
if(!ObjectCreate(chart_ID, name, OBJ_TRENDBYANGLE, sub_window, time1, price1, time2, price2))
{
Print(__FUNCTION__,
": <00>Fallo al crear la l<00>nea de tendencia! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos el color de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width);
ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, toltip);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
return(true);
}
//+------------------------------------------------------------------+
bool TextCreate(long chart_ID, // ID del gr<EFBFBD>fico
string name, // nombre del objeto
int sub_window, // n<EFBFBD>mero de subventana
datetime time, // hora del punto de anclaje
double price, // precio del punto de anclaje
string text, // el texto
string font, // fuente
int font_size, // tama<EFBFBD>o de la fuente
color clr, // color
double angle, // inclinaci<EFBFBD>n del texto
ENUM_ANCHOR_POINT anchor, // modo de anclaje
bool back = false, // al fondo
bool selection = false) // seleccionar para mover
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos el objeto "Texto"
if(!ObjectCreate(chart_ID, name, OBJ_TEXT, sub_window, time, price))
{
PrintFormat("Fallo al crear el texto %s, ultimo error %i", name, GetLastError());
return(false);
}
//--- ponemos el texto
ObjectSetString(chart_ID, name, OBJPROP_TEXT, text);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, text);
//--- establecemos la fuente del texto
ObjectSetString(chart_ID, name, OBJPROP_FONT, font);
//--- establecemos el tama<EFBFBD>o del texto
ObjectSetInteger(chart_ID, name, OBJPROP_FONTSIZE, font_size);
//--- establecemos el <EFBFBD>ngulo de inclinaci<EFBFBD>n del texto
ObjectSetDouble(chart_ID, name, OBJPROP_ANGLE, angle);
//--- establecemos el modo de anclaje
ObjectSetInteger(chart_ID, name, OBJPROP_ANCHOR, anchor);
//--- establecemos el color
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- 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 del texto con rat<EFBFBD>n
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
//ChartRedraw(chart_ID);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool ArrowCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre de la flecha
const int sub_window, // n<EFBFBD>mero de subventana
datetime time, // hora del punto de anclaje
double price, // precio del punto de anclaje
const uchar arrow_code, // c<EFBFBD>digo de la flecha
const ENUM_ARROW_ANCHOR anchor, // posici<EFBFBD>n del punto de anclaje
const color clr, // color de la flecha
const ENUM_LINE_STYLE style, // estilo de la l<EFBFBD>nea del contorno
const int width, // tama<EFBFBD>o de la flecha
const bool back = true, // al fondo
const bool selection = false, // seleccionar para mover
const long z_order = 0) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos la flecha
if(!ObjectCreate(chart_ID, name, OBJ_ARROW, sub_window, time, price))
{
Print(__FUNCTION__,
": <00>Fallo al crear la flecha! C<00>digo del error = ", GetLastError(), " el nombre: ", name);
return(false);
}
//--- establecemos el c<EFBFBD>digo de la flecha
ObjectSetInteger(chart_ID, name, OBJPROP_ARROWCODE, arrow_code);
//--- establecemos el modo de anclaje
ObjectSetInteger(chart_ID, name, OBJPROP_ANCHOR, anchor);
//--- establecemos el color de la flecha
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el estilo de la l<EFBFBD>nea del contorno
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- establecemos el tama<EFBFBD>o de la flecha
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, 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 flecha con rat<EFBFBD>n
//--- cuando el objeto gr<EFBFBD>fico se crea usando la funci<EFBFBD>n ObjectCreate, por defecto el objeto
//--- no se puede seleccionar y mover. Mientras que dentro de este m<EFBFBD>todo el par<EFBFBD>metro selection
//--- por defecto es igual a true, lo que permite seleccionar y mover este objeto
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
//--- establecemos la prioridad para obtener el evento de cliquear sobre el gr<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool EditCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre del objeto
const int sub_window, // n<EFBFBD>mero de subventana
const int x, // coordenada por el eje X
const int y, // coordenada por el eje Y
const int width, // ancho
const int height, // alto
const string text, // texto
const string font, // fuente
const int font_size, // tama<EFBFBD>o de la fuente
const ENUM_ALIGN_MODE align, // modo de alineaci<EFBFBD>n
const bool read_only, // posibilidad de edici<EFBFBD>n
const ENUM_BASE_CORNER corner, // esquina del gr<EFBFBD>fico para el enlace
const color clr, // color del texto
const color back_clr, // color del fondo
const color border_clr, // color del borde
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<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos el campo de edici<EFBFBD>n
if(!ObjectCreate(chart_ID, name, OBJ_EDIT, sub_window, 0, 0))
{
Print(__FUNCTION__,
": <00>Fallo al crear el objeto \"Campo de edici<EFBFBD>n\"! C<00>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<EFBFBD>o del objeto
ObjectSetInteger(chart_ID, name, OBJPROP_XSIZE, width);
ObjectSetInteger(chart_ID, name, OBJPROP_YSIZE, height);
//--- ponemos el texto
ObjectSetString(chart_ID, name, OBJPROP_TEXT, text);
//--- establecemos la fuente del texto
ObjectSetString(chart_ID, name, OBJPROP_FONT, font);
//--- establecemos el tama<EFBFBD>o del texto
ObjectSetInteger(chart_ID, name, OBJPROP_FONTSIZE, font_size);
//--- establecemos el modo de alineaci<EFBFBD>n del texto dentro del objeto
ObjectSetInteger(chart_ID, name, OBJPROP_ALIGN, align);
//--- ponemos (true) o cancelamos (false) el modo s<EFBFBD>lo para lectura
ObjectSetInteger(chart_ID, name, OBJPROP_READONLY, read_only);
//--- establecemos la esquina del gr<EFBFBD>fico respecto a la cual van a determinarse las coordenadas del objeto
ObjectSetInteger(chart_ID, name, OBJPROP_CORNER, corner);
//--- establecemos el color del texto
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el color del fondo
ObjectSetInteger(chart_ID, name, OBJPROP_BGCOLOR, back_clr);
//--- establecemos el color del borde
ObjectSetInteger(chart_ID, name, OBJPROP_BORDER_COLOR, border_clr);
//--- 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<EFBFBD>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<EFBFBD>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<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool ButtonCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre del bot<EFBFBD>n
const int sub_window, // n<EFBFBD>mero de subventana
const int x, // coordenada por el eje X
const int y, // coordenada por el eje Y
const int width, // ancho del bot<EFBFBD>n
const int height, // alto del bot<EFBFBD>n
const ENUM_BASE_CORNER corner, // esquina del gr<EFBFBD>fico para el enlace
const string text, // texto
const string font, // fuente
const int font_size, // tama<EFBFBD>o de la fuente
const color clr, // color del texto
const color back_clr, // color del fondo
const color border_clr, // color del borde
const bool state = false, // pulsado/no pulsado
const bool back = false, // al fondo
const bool selection = false, // seleccionar para mover
const bool hidden = false, // ocultar en la lista de objetos
const long z_order = 0) //prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos el bot<EFBFBD>n
if(!ObjectCreate(chart_ID, name, OBJ_BUTTON, sub_window, 0, 0))
{
Print(__FUNCTION__,
": <00>Fallo al crear el bot<00>n! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos las coordenadas del bot<EFBFBD>n
ObjectSetInteger(chart_ID, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(chart_ID, name, OBJPROP_YDISTANCE, y);
//--- establecemos el tama<EFBFBD>o del bot<EFBFBD>n
ObjectSetInteger(chart_ID, name, OBJPROP_XSIZE, width);
ObjectSetInteger(chart_ID, name, OBJPROP_YSIZE, height);
//--- establecemos la esquina del gr<EFBFBD>fico respecto a la cual van a determinarse las coordenadas del punto
ObjectSetInteger(chart_ID, name, OBJPROP_CORNER, corner);
//--- ponemos el texto
ObjectSetString(chart_ID, name, OBJPROP_TEXT, text);
//--- establecemos la fuente del texto
ObjectSetString(chart_ID, name, OBJPROP_FONT, font);
//--- establecemos el tama<EFBFBD>o del texto
ObjectSetInteger(chart_ID, name, OBJPROP_FONTSIZE, font_size);
//--- establecemos el color del texto
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el color del fondo
ObjectSetInteger(chart_ID, name, OBJPROP_BGCOLOR, back_clr);
//--- establecemos el color del borde
ObjectSetInteger(chart_ID, name, OBJPROP_BORDER_COLOR, border_clr);
//--- mostramos en el primer plano (false) o al fondo (true)
ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
//--- set button state
ObjectSetInteger(chart_ID, name, OBJPROP_STATE, state);
//--- activar (true) o desactivar (false) el modo de desplazamiento del bot<EFBFBD>n con rat<EFBFBD>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<EFBFBD>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<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool RectLabelCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre de la etiqueta
const int sub_window, // n<EFBFBD>mero de subventana
const int x, // coordenada por el eje X
const int y, // coordenada por el eje Y
const int width, // ancho
const int height, // alto
const color back_clr, // color del fondo
const ENUM_BORDER_TYPE border, // tipo del borde
const ENUM_BASE_CORNER corner, // esquina del gr<EFBFBD>fico para el enlace
const color clr, // color del contorno plano (Flat)
const ENUM_LINE_STYLE style, // estilo del contorno plano
const int line_width, // 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<EFBFBD>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__,
": <00>Fallo al crear la etiqueta rectangular! C<00>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<EFBFBD>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<EFBFBD>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<EFBFBD>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<EFBFBD>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<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool ArrowRightPriceCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre de la etiqueta de precio
const int sub_window, // n<EFBFBD>mero de subventana
datetime time, // hora del punto de anclaje
double price, // precio del punto de anclaje
const color clr, // color de la etiqueta de precio
const ENUM_LINE_STYLE style, // estilo de la l<EFBFBD>nea del contorno
const int width, // tama<EFBFBD>o de la etiqueta de precio
const bool back, // al fondo
const bool selection, // seleccionar para mover
const bool hidden, // ocultar en la lista de objetos
const long z_order) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos la etiqueta de precio
if(!ObjectCreate(chart_ID, name, OBJ_ARROW_RIGHT_PRICE, sub_window, time, price))
{
Print(__FUNCTION__,
": <00>Fallo al crear la etiqueta derecha de precio! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos el color de la etiqueta
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el estilo de la l<EFBFBD>nea del contorno
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- establecemos el tama<EFBFBD>o de la etiqueta
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, 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<EFBFBD>n
//--- cuando el objeto gr<EFBFBD>fico se crea usando la funci<EFBFBD>n ObjectCreate, por defecto el objeto
//--- no se puede seleccionar y mover. Mientras que dentro de este m<EFBFBD>todo el par<EFBFBD>metro selection
//--- por defecto es igual a true, lo que permite seleccionar y mover este objeto
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
//--- ocultamos (true) o mostramos (false) el nombre del objeto gr<EFBFBD>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<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool EventCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre del evento
const int sub_window, // n<EFBFBD>mero de subventana
const string text, // texto del evento
datetime time, // hora
const color clr, // color
const int width, // grosor del punto durante la selecci<EFBFBD>n
const bool back, // al fondo
const string tooltip,
const bool selection = false, // seleccionar para mover
const long z_order = 0) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos el objeto "Evento"
if(!ObjectCreate(chart_ID, name, OBJ_EVENT, sub_window, time, 0))
{
Print(__FUNCTION__,
": <00>Fallo al crear el objeto \"Evento\"! C<00>digo del error = ", GetLastError());
return(false);
}
//--- ponemos el texto del evento
ObjectSetString(chart_ID, name, OBJPROP_TEXT, text);
//--- establecemos el color
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el grosor del punto de anclaje si el objeto est<EFBFBD> seleccionado
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, 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 del evento con rat<EFBFBD>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<EFBFBD>fico en la lista de objetos
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, tooltip);
//--- establecemos la prioridad para obtener el evento de cliquear sobre el gr<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool RectangleCreate(long chart_ID,
string name,
const int sub_window,
datetime time1, double price1,
datetime time2, double price2,
color clr,
int width,
bool fill,
bool back,
bool select,
ENUM_LINE_STYLE style,
string tooltip
) // <EFBFBD>! 0% (totalmente opaco) a 100% (totalmente transparente)
{
ResetLastError();
// Crear objeto
if(!ObjectCreate(chart_ID, name, OBJ_RECTANGLE, sub_window, time1, price1, time2, price2))
{
Print(__FUNCTION__, ": Failed to create rectangle! Error code = ", GetLastError(), " name: ", name);
return false;
}
// Seteo de propiedades
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width);
ObjectSetInteger(chart_ID, name, OBJPROP_FILL, fill);
ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, select);
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, tooltip);
return true;
}
//+------------------------------------------------------------------+
bool FiboLevelsCreate(const long chart_ID = 0, // ID del gr<EFBFBD>fico
const string name = "FiboLevels", // nombre del objeto
const int sub_window = 0, // n<EFBFBD>mero de subventana
datetime time1 = 0, // hora del primer punto
double price1 = 0, // precio del primer punto
datetime time2 = 0, // hora del segundo punto
double price2 = 0, // precio del segundo punto
const color clr = clrRed, // color del objeto
const ENUM_LINE_STYLE style = STYLE_SOLID, // estilo de las l<EFBFBD>neas del objeto
const int width = 1, // grosor de las l<EFBFBD>neas del objeto
const bool back = false, // al fondo
const bool selection = true, // seleccionar para mover
const bool ray_left = false, // continuaci<EFBFBD>n del objeto a la izquierda
const bool ray_right = false, // continuaci<EFBFBD>n del objeto a la derecha
const long z_order = 0) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos los "Retrocesos de Fibonacci" seg<EFBFBD>n las coordenadas establecidas
if(!ObjectCreate(chart_ID, name, OBJ_FIBO, sub_window, time1, price1, time2, price2))
{
Print(__FUNCTION__,
": <00>Falo al crear los \"Retrocesos de Fibonacci\"! C<00>digo del error = ", GetLastError());
return(false);
}
//--- establecemos el color
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el estilo de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- establecemos el grosor de la l<EFBFBD>nea
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, 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 selecci<EFBFBD>n del objeto para mover
//--- cuando el objeto gr<EFBFBD>fico se crea usando la funci<EFBFBD>n ObjectCreate, por defecto el objeto
//--- no se puede seleccionar y mover. Mientras que dentro de este m<EFBFBD>todo el par<EFBFBD>metro selection
//--- por defecto es igual a true, lo que permite seleccionar y mover este objeto
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
//--- activamos (true) o desactivamos (false) el modo de continuaci<EFBFBD>n del objeto a la izquierda
ObjectSetInteger(chart_ID, name, OBJPROP_RAY_LEFT, ray_left);
//--- activamos (true) o desactivamos (false) el modo de continuaci<EFBFBD>n del objeto a la derecha
ObjectSetInteger(chart_ID, name, OBJPROP_RAY_RIGHT, ray_right);
//--- establecemos la prioridad para obtener el evento de cliquear con el rat<EFBFBD>n sobre el gr<EFBFBD>fico
ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool FiboLevelsSet(int levels, // n<EFBFBD>mero de las l<EFBFBD>neas del nivel
double &values[], // valores de las l<EFBFBD>neas del nivel
color &colors[], // color de las l<EFBFBD>neas del nivel
ENUM_LINE_STYLE &styles[], // estilo de las l<EFBFBD>neas del nivel
int &widths[], // grosor de las l<EFBFBD>neas del nivel
const long chart_ID = 0, // ID del gr<EFBFBD>fico
const string name = "FiboLevels") // nombre del objeto
{
//--- comprobamos los tama<EFBFBD>os de los arrays
if(levels != ArraySize(colors) || levels != ArraySize(styles) || levels != ArraySize(widths))
{
Print(__FUNCTION__, ": <00>Error. La longitud del array no corresponde al n<00>mero de los niveles!");
return(false);
}
//--- establecemos el n<EFBFBD>mero de los niveles
ObjectSetInteger(chart_ID, name, OBJPROP_LEVELS, levels);
//--- establecemos las propiedades de los niveles en el ciclo
for(int i = 0; i < levels; i++)
{
//--- valor del nivel
ObjectSetDouble(chart_ID, name, OBJPROP_LEVELVALUE, i, values[i]);
//--- color del nivel
ObjectSetInteger(chart_ID, name, OBJPROP_LEVELCOLOR, i, colors[i]);
//--- estilo del nivel
ObjectSetInteger(chart_ID, name, OBJPROP_LEVELSTYLE, i, styles[i]);
//--- grosor del nivel
ObjectSetInteger(chart_ID, name, OBJPROP_LEVELWIDTH, i, widths[i]);
//--- descripci<EFBFBD>n del nivel
ObjectSetString(chart_ID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1));
}
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
bool ChannelCreate(const long chart_ID, // ID del gr<EFBFBD>fico
const string name, // nombre del canal
const int sub_window, // n<EFBFBD>mero de subventana
datetime time1, // hora del primer punto
double price1, // precio del primer punto
datetime time2, // hora del segundo punto
double price2, // precio del segundo punto
datetime time3, // hora del tercer punto
double price3, // precio del tercer punto
const color clr, // color del canal
const ENUM_LINE_STYLE style, // estilo de las l<EFBFBD>neas del canal
const int width, // grosor de las l<EFBFBD>neas del canal
const bool fill, // relleno del canal con el color
const bool back, // al fondo
const bool selection, // seleccionar para mover
string tooltip
) // prioridad para el clic del rat<EFBFBD>n
{
//--- anulamos el valor del error
ResetLastError();
//--- creamos el canal seg<EFBFBD>n las coordenadas establecidas
if(!ObjectCreate(chart_ID, name, OBJ_CHANNEL, sub_window, time1, price1, time2, price2, time3, price3))
{
Print(__FUNCTION__,
": <00>Fallo al crear el canal equidistante! C<00>digo del error = ", GetLastError());
return(false);
}
//--- fijamos el color del canal
ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr);
//--- establecemos el estilo de las l<EFBFBD>neas del canal
ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style);
//--- establecemos el grosor de las l<EFBFBD>neas del canal
ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width);
//--- activar (true) o desactivar (false) el modo de relleno del canal
ObjectSetInteger(chart_ID, name, OBJPROP_FILL, fill);
//--- 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 selecci<EFBFBD>n del canal para mover
//--- cuando el objeto gr<EFBFBD>fico se crea usando la funci<EFBFBD>n ObjectCreate, por defecto el objeto
//--- no se puede seleccionar y mover. Mientras que dentro de este m<EFBFBD>todo el par<EFBFBD>metro selection
//--- por defecto es igual a true, lo que permite seleccionar y mover este objeto
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection);
ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection);
ObjectSetString(chart_ID, name, OBJPROP_TOOLTIP, tooltip);
//--- ejecuci<EFBFBD>n con <EFBFBD>xito
return(true);
}
//+------------------------------------------------------------------+
void ModifiedIntegerPropertyByPrefix(long chart_id, int subwin, string prefix, ENUM_OBJECT obj_type, ENUM_OBJECT_PROPERTY_INTEGER property, long value)
{
int objtotal = ObjectsTotal(chart_id, subwin, obj_type);
for(int i = 0; i < objtotal ; i++)
{
const string obj_name = ObjectName(chart_id, i, subwin, obj_type);
if(StringFind(obj_name, prefix, 0) >= 0)
{
ObjectSetInteger(chart_id, obj_name, property, value);
}
}
}
//+------------------------------------------------------------------+
void DrawTPSL(long chart_id, int subwin, string prefix_, double tp, double sl, double entry, datetime time_entry, datetime end_time
, color clr_tp_, color clr_sl_, bool fill_rect, int width_rect_, ENUM_LINE_STYLE style_rect)
{
string name_rect_tp = prefix_ + "tp_" + TimeToString(end_time);
string name_rect_sl = prefix_ + "sl_" + TimeToString(end_time);
RectangleCreate(chart_id, name_rect_tp, subwin, time_entry, entry, end_time, tp, clr_tp_, width_rect_, fill_rect, true, false, style_rect, "Take profit");
RectangleCreate(chart_id, name_rect_sl, subwin, time_entry, entry, end_time, sl, clr_sl_, width_rect_, fill_rect, true, false, style_rect, "Stop Loss");
}
//+------------------------------------------------------------------+
#define HIDE_OBJECT(obj_name, chart_id) ObjectSetInteger(chart_id, obj_name, OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS)
//+------------------------------------------------------------------+
#define SHOW_OBJECT(obj_name, chart_id) ObjectSetInteger(chart_id, obj_name, OBJPROP_TIMEFRAMES, OBJ_ALL_PERIODS)
//+------------------------------------------------------------------+
inline long BarrasInRange(datetime init_time, datetime end_time, ENUM_TIMEFRAMES timeframe)
{
return (init_time > end_time) ? 0 : iBarShift(_Symbol, timeframe, init_time) - iBarShift(_Symbol, timeframe, end_time);
}
#endif
//+------------------------------------------------------------------+