Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1481

 
ANDREY:

Thank you for the valuable information.

Please advise, how to store in a variable which expression happens to be true? To be more precise - what is the minimum calculated in the function with respect to a candle of what timeframe? How to save the identifier of this timeframe in a variable?
Thank you

Just declare bool variables

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:

Just declare bool variables

Thank you for the useful information.

Could you please tell me how to save a 5 digit value in yellow variable if the test is done on a minute chart

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 = (ЛОУ из выражения, которое оказалось истинным);
}
}

Thank you.

 
Good afternoon! Can you tell me how to bind text to a line in mql4, so that when the latter is moved, the inscription is also shifted, like in the screenshots. I know that there are two ways to bind an object: in pixels to the corner of the screen and in time/price coordinates. In the first case, I get a static text, and in the second, it's not quite what I want. With the price coordinate (vertical binding) is clear - I take the line price and add a _Point pair to it, so the text would be a bit higher than the line. But what about time? I do not want to bind to the last bar because different shift of the chart will pull the text to the right - to the left. Here I would like to make a rigid horizontal binding to the right edge of the screen, but I do not understand how.
 
Oleksandr Nozemtsev:
Good afternoon! Can you tell me how to bind text to a line in mql4, so that when the latter is moved, the inscription is also shifted, like in the screenshots. I know that there are two ways to bind an object : in pixels to the corner of the screen and in time/price coordinates. In the first case, I get a static text, and in the second case, it's not quite what I want. With the price coordinate (vertical binding) is clear - I take the line price and add a _Point pair to it, so the text would be a bit higher than the line. But what about time? I do not want to bind to the last bar because different shift of the chart will pull the text to the right - to the left. Here I would like to make a rigid horizontal binding to the right edge of the screen, but I do not understand how.
Do you draw the lines yourself or the indicator?
 
MakarFX:
Do you draw the lines yourself or the indicator?

The line is created by the indicator when it is loaded. The text is needed to show information about this level directly above the line, rather than displaying it in Alert (Alert works).

 
Oleksandr Nozemtsev:

The line is created by the indicator when it is loaded. Text is needed to show information about this level directly above the line, rather than displaying it in Alert (Alert works).

Post the line creation code
 
MakarFX:
Post the line creation code

int OnInit()

{

//Create line "name_line" if it does not exist yet

if(ObjectFind(0, name_line) == -1)

{

//If price is not specified, set it to the current Ask price

if(!price_line)

price_line = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

//reset error value

ResetLastError();

//create a line

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

Print("Line Line. Error ", GetLastError());

//

ObjectSet(name_line, OBJPROP_COLOR, color_line); //Line colour

ObjectSet(name_line, OBJPROP_STYLE, style_line); //Line style

ObjectSet(name_line, OBJPROP_WIDTH, width_line); //line thickness

ObjectSet(name_line, OBJPROP_BACK, back_line); //Front/back

ObjectSet(name_line, OBJPROP_SELECTABLE, selection_line);//The object can be clicked with the mouse.

ObjectSet(name_line, OBJPROP_SELECTED, selection_line); //The object is selected. O is not selected at creation

}

return(INIT_SUCCEEDED);

}

 
Oleksandr Nozemtsev:

Catch

//+------------------------------------------------------------------+
//|                                                    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:

Catch

Wow, that's a lot! I thought it was just a couple of lines of code. Thank you! (laughs)

 
Alexey Viktorov:

Just declare bool variables

Could you please also tell me how to save a 5 digit blue value in a yellow variable if the test takes place on a 1 minute chart

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 = (ЛОУ из выражения, которое оказалось истинным);
}
}
Thank you
Reason: