Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 1481

 
ANDREY:

Gracias por la valiosa información.

Por favor, aconséjeme cómo almacenar en una variable la expresión que resulta ser verdadera. Para ser más precisos - ¿cuál es el mínimo calculado en la función con respecto a una vela de qué marco de tiempo? ¿Cómo guardar el identificador de este plazo en una variable?
Gracias

Sólo hay que declarar las variables bool

bool variant_H4 = Bid-iLow( NULL ,PERIOD_H4,1) >= 0.0030,
     variant_H1 = Bid-iLow(NULL ,PERIOD_H1,1) >= 0.0030,
     variant_M30 = Bid-iLow(NULL ,PERIOD_M30,1) >= 0.0030;
if (variant_H4 || variant_H1 || variant_M30)
 
Alexey Viktorov:

Sólo hay que declarar las variables bool

Gracias por esta información tan útil.

¿Podría decirme cómo guardar un valor de 5 dígitos en la variable amarilla si la prueba se realiza en un gráfico de minutos?

double LoU;
void OnTick()
{
if (Bid - iLow( NULL ,PERIOD_H4,1)>=0.0030||Bid - iLow( NULL ,PERIOD_H1,1)>=0.0030||Bid - iLow( NULL ,PERIOD_M30,1)>=0.0030)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0);
LoU = (ЛОУ из выражения, которое оказалось истинным);
}
}

Gracias.

 
¡Buenas tardes! Me podéis decir cómo ligar el texto a una línea en mql4, para que cuando ésta se desplace, la inscripción también se desplace, como en las capturas de pantalla. Sé que hay dos formas de vincular un objeto: en píxeles a la esquina de la pantalla y en coordenadas de tiempo/precio. En el primer caso, obtengo un texto estático, y en el segundo, no es exactamente lo que quiero. Con la coordenada del precio (encuadernación vertical) está claro - tomo el precio de la línea y le añado un par de _Puntos, para que el texto sea un poco más alto que la línea. ¿Pero qué pasa con el tiempo? No quiero enlazar con la última barra porque un desplazamiento diferente del gráfico arrastrará el texto a la derecha - a la izquierda. Aquí me gustaría hacer una unión horizontal rígida al borde derecho de la pantalla, pero no entiendo cómo.
 
Oleksandr Nozemtsev:
¡Buenas tardes! Me podéis decir cómo ligar el texto a una línea en mql4, para que cuando ésta se desplace, la inscripción también se desplace, como en las capturas de pantalla. Sé que hay dos formas de vincular un objeto : en píxeles a la esquina de la pantalla y en coordenadas de tiempo/precio. En el primer caso, obtengo un texto estático, y en el segundo, no es exactamente lo que quiero. Con la coordenada del precio (encuadernación vertical) está claro - tomo el precio de la línea y le añado un par de _Puntos, para que el texto sea un poco más alto que la línea. ¿Pero qué pasa con el tiempo? No quiero enlazar con la última barra porque un desplazamiento diferente del gráfico arrastrará el texto a la derecha - a la izquierda. Aquí me gustaría hacer una unión horizontal rígida al borde derecho de la pantalla, pero no entiendo cómo.
¿Dibuja usted las líneas o el indicador?
 
MakarFX:
¿Dibuja usted las líneas o el indicador?

La línea es creada por el indicador cuando se carga. El texto es necesario para mostrar la información sobre este nivel directamente sobre la línea, en lugar de mostrarla en Alerta (Alerta funciona).

 
Oleksandr Nozemtsev:

La línea es creada por el indicador cuando se carga. El texto es necesario para mostrar la información sobre este nivel directamente sobre la línea, en lugar de mostrarla en Alerta (Alerta funciona).

Publicar el código de creación de la línea
 
MakarFX:
Publicar el código de creación de la línea

int OnInit()

{

//Crear línea "nombre_línea" si aún no existe

if(ObjectFind(0, nombre_línea) == -1)

{

//Si no se especifica el precio, se establece el precio de venta actual

if(!línea_de_precio)

línea_de_precio = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

//restablecer el valor del error

ResetLastError();

//crear una línea

if(!ObjectCreate(0, name_line, OBJ_HLINE, 0, 0, price_line))

Print("Línea de la línea. Error ", GetLastError());

//

ObjectSet(nombre_línea, OBJPROP_COLOR, color_línea); //Color de la línea

ObjectSet(nombre_línea, OBJPROP_STYLE, estilo_línea); //Estilo de línea

ObjectSet(nombre_línea, OBJPROP_WIDTH, anchura_línea); //espesor de la línea

ObjectSet(nombre_línea, OBJPROP_BACK, línea_de_retroceso); //Frente/retroceso

ObjectSet(nombre_línea, OBJPROP_SELECTABLE, selección_línea);//El objeto puede ser pulsado con el ratón.

ObjectSet(name_line, OBJPROP_SELECTED, selection_line); //El objeto está seleccionado. O no se selecciona en la creación

}

return(INIT_SUCCEED);

}

 
Oleksandr Nozemtsev:

Captura

//+------------------------------------------------------------------+
//|                                                    Line_Text.mq4 |
//|                                           Copyright 2020 MakarFX |
//|                            https://www.mql5.com/ru/users/makarfx |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020 MakarFX"
#property link      "https://www.mql5.com/ru/users/makarfx"
#property version   "1.00"
#property strict
#property indicator_chart_window

double buy,sell;
datetime DoTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectsDeleteAll(0,"My_");
   //--- indicator buffers mapping
   if(ObjectFind(0,"My_BuyLine")!=0)
     {
      HLineCreate(0,"My_BuyLine",0,Ask+50*Point,clrTeal,2,1,false,true,false);
     }
   if(ObjectFind(0,"My_SellLine")!=0)
     {
      HLineCreate(0,"My_SellLine",0,Bid-50*Point,clrCrimson,2,1,false,true,false);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,"My_");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   DoTime = TimeCurrent()+(Period()*60*7);
   if(ObjectFind(0,"My_BuyLine")==0)
     {
      buy = NormalizeDouble(ObjectGet("My_BuyLine",OBJPROP_PRICE1),Digits);
      Create_Text(0,"My_BuyText",0,DoTime,buy+5*Point,"BuyText","Arial",10,clrTeal,0,0,false,false,false);     
     }
   if(ObjectFind(0,"My_SellLine")==0)
     {
      sell = NormalizeDouble(ObjectGet("My_SellLine",OBJPROP_PRICE1),Digits);
      Create_Text(0,"My_SellText",0,DoTime,sell-5*Point,"SellText","Arial",10,clrCrimson,0,0,false,false,false);     
     }
   if(buy!=ObjectGet("My_BuyLine",OBJPROP_PRICE1)||sell!=ObjectGet("My_SellLine",OBJPROP_PRICE1))
     {
      ObjectMove(0,"My_BuyText",0,DoTime,buy+5*Point);
      ObjectMove(0,"My_SellText",0,DoTime,sell-5*Point);
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+--------------------------------------------------------------------------------------------------------------------+
//| Создает горизонтальную линию                                                                                       | 
//+--------------------------------------------------------------------------------------------------------------------+
bool HLineCreate(const long            chart_ID=0,        // ID графика 
                 const string          name="HLine",      // имя линии 
                 const int             sub_window=0,      // номер подокна 
                 double                price=0,           // цена линии 
                 const color           clr=clrRed,        // цвет линии 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // стиль линии 
                 const int             width=1,           // толщина линии 
                 const bool            back=false,        // на заднем плане 
                 const bool            selection=true,    // выделить для перемещений 
                 const bool            hidden=true,       // скрыт в списке объектов 
                 const long            z_order=0)         // приоритет на нажатие мышью 
   { 
   //--- сбросим значение ошибки 
   ResetLastError(); 
   //--- создадим горизонтальную линию 
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) 
      { 
      Print(__FUNCTION__, ": не удалось создать горизонтальную линию! Код ошибки = ",GetLastError()); return(false); 
      } 
   //--- установим свойства линии 
   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);
   ObjectSetInteger (chart_ID, name, OBJPROP_SELECTABLE, selection);
   ObjectSetInteger (chart_ID, name, OBJPROP_SELECTED, selection);
   ObjectSetInteger (chart_ID, name, OBJPROP_HIDDEN, hidden);
   ObjectSetInteger (chart_ID, name, OBJPROP_ZORDER, z_order);
   //--- успешное выполнение 
   return(true); 
   } 
//+--------------------------------------------------------------------------------------------------------------------+
//| Создает объект "Текст"                                                                                             | 
//+--------------------------------------------------------------------------------------------------------------------+
bool Create_Text(const long              chart_ID=0,               // ID графика 
                 const string            name="Text",              // имя объекта 
                 const int               sub_window=0,             // номер подокна 
                 datetime                time=0,                   // время точки привязки 
                 double                  price=0,                  // цена точки привязки 
                 const string            text="Text",              // сам текст 
                 const string            font="Arial",             // шрифт 
                 const int               font_size=10,             // размер шрифта 
                 const color             clr=clrRed,               // цвет 
                 const double            angle=0.0,                // наклон текста 
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // способ привязки 
                 const bool              back=false,               // на заднем плане 
                 const bool              selection=false,          // выделить для перемещений 
                 const bool              hidden=true,              // скрыт в списке объектов 
                 const long              z_order=0)                // приоритет на нажатие мышью 
   { 
   //--- сбросим значение ошибки 
   ResetLastError(); 
   //--- создадим объект "Текст" 
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price)) 
      { 
      Print(__FUNCTION__,": не удалось создать объект \"Текст\"! Код ошибки = ",GetLastError()); return(false); 
      } 
   //--- установим свойства объектa "Текст" 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   //--- успешное выполнение 
   return(true); 
   } 
//+------------------------------------------------------------------+
 
MakarFX:

Captura

¡Vaya, eso es mucho! Pensaba que sólo eran un par de líneas de código. ¡Gracias!

 
Alexey Viktorov:

Sólo hay que declarar las variables bool

¿Podría decirme también cómo guardar un valor azul de 5 dígitos en una variable amarilla si la prueba tiene lugar en un gráfico de 1 minuto?

double LoU;
void OnTick()
{
if (Bid - iLow( NULL ,PERIOD_H4,1)>=0.0030||Bid - iLow( NULL ,PERIOD_H1,1)>=0.0030||Bid - iLow( NULL ,PERIOD_M30,1)>=0.0030)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0);
LoU = (ЛОУ из выражения, которое оказалось истинным);
}
}
Gracias
Razón de la queja: