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

 
WinProject:
Thank you!) From your answer, I conclude that for each type of object I need to make a separate function. I thought that somehow it would be possible to make a separate start of functions to build objects, attached to the loop While main function to read the file. How about Switch?

I probably haven't got into it enough.

The first one, the construction of all the graphical objects, does not cause any problems or questions. But I must have misunderstood the second one. Apparently the question was not about how to organize the work with one button for many types of objects, but one button for one type of objects. In that case, I would make a structure with object parameters and several arrays of structures, one array for each type of object. So, I would bind these structure arrays to buttons of corresponding types.

Then, when you press the button, the corresponding object type will be deleted. And when the button is released, the objects will be restored by the parameters that are in the structure array.

So it will be necessary to read the file only once at startup.

 
Alexey Viktorov:

I probably haven't got into it enough.

The first one, the construction of all the graphical objects, does not cause any problems or questions. But I must have misunderstood the second one. Apparently the question was not about how to organize the work with one button for many types of objects, but one button for one type of objects. In that case, I would make a structure with object parameters and several arrays of structures, one array for each type of object. So, I would bind these structure arrays to buttons of corresponding types.

Then, when you press the button, the corresponding object type will be deleted. And when the button is released, the objects will be restored by the parameters that are in the structure array.

Thus, it will be necessary to read the file only once at startup.

Thanks a lot for the answer, I will try to do both variants, through flags as suggested by STARIJ and your variant is also interesting to try. I will try to ask less questions, it's good that they are answered!)
 
STARIJ:

Flags are variables. Or bool: false=empty, true=raised or int - then there are many flags in one number at once: 0 - all omitted, 1=lower first, 2=lower second, 3=lower first and second, 4=lower third, 5=lower third and first, 6=lower third and second, 7=lower first, second, third, 8=lower fourth.... Well that's in binary code. How do you find out?

Thanks, seemed to find a good explanation on the net, will try it out. The strange thing is that on this site neither in documentation, nor in the tutorial, probably assumed that everyone who came here already have programming skills.
 
WinProject:
Thanks a lot for the reply, I will try to do both variants, through flags as suggested by STARIJ and your variant is also interesting to try. I will try to ask less questions, it's good to have answers!)

Flags may not be bad, but it misses the point

Forum on trading, automated trading systems & strategy testing

Any questions newbies have on MQL4, help and discussion on algorithms and codes

WinProject, 2018.01.26 18:17

Good evening, once again I'm looking for help. My EA has the main Function in OnInit, which reads the file, and immediately builds different graphical objects according to different conditions. Also on the chart is a button which, when clicked, operates the function to remove these objects, such as text labels. How to make, that after the press of the button has removed text labels, at release of the button it is possible to start not all Function entirely, which will completely construct all objects, but to construct only text labels. The only thing that comes to mind is to create an analogue of the main function separately for each type of object with all the actions associated with opening and reading the file, but I want to use some clever solution, but I do not know which one and how, in the main function or in the functions of the buttons?

In that case it's easier to implement reading of the file into a separate user-defined function and call it several times, in order not to multiply the creation of one and the same code several times. But no matter how hard you try, file reading will remain when flags are used. And it makes no difference what to check when creating deleted objects - their absence or flag state by object type. After all, the type of object is determined by the button linked to a particular type, this is the flag.
 

Can you tell me how to get the value of the current hour in MQL5 ?
I created an object of MqlDateTime structure, it gives nothing

 
Roman Sharanov:

Can you tell me how to get the value of the current hour in MQL5 ?
I created an object of MqlDateTime structure, it gives nothing

The structure has to be filled with date-time.
 
Artyom Trishkin:
The structure needs to be filled with date-time.

Use TimeCurrent()? I just don't understand how.

 
Roman Sharanov:

use TimeCurrent()? just don't understand how

TimeToStruct()
 
Artyom Trishkin:
TimeToStruct()

Ah, got it, it's working, thanks!

 

https://docs.mql4.com/ru/basis/types/casting

Penultimate example,colour in RGB representation as string."Converting two structures by copying the contents" doesn't work.

#property script_show_inputs
input color          testColor=clrBlue;// задайте цвет для тестирования
//--- структура для представления цвета в RGB
struct RGB
  {
   uchar             blue;          // синяя составляющая цвета
   uchar             green;         // зеленая составляющая цвета
   uchar             red;           // красная составляющая цвета
   uchar             empty;         // этот байт не используется
   string            toString();    // функция для получения в виде строки
  };
//--- функция для вывода цвета в виде строки
string RGB::toString(void)
  {
   string out="("+(string)red+":"+(string)green+":"+(string)blue+")";
   return out;
  }
//--- структура для хранения встроенного типа color 
struct builtColor
  {
   color             c;
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- переменная для хранения в RGB
   RGB colorRGB;
//--- переменная для хранения типа color
   builtColor test;
   test.c=testColor;
//--- приведение двух структур путем копирования содержимого
   colorRGB=test;
   Print("color ",test.c," = ",colorRGB.toString());
//---
  }

The compiler generates the following error... ('=' - illegal operation use test.mq4 34 12 )

Did I copy something wrong or is there an error in the sample? Please, advise me.

Приведение типов - Типы данных - Основы языка - Справочник MQL4
Приведение типов - Типы данных - Основы языка - Справочник MQL4
  • docs.mql4.com
Часто возникает необходимость преобразовать один числовой тип в другой. Не каждый числовой тип допустимо преобразовать в другой, допустимые преобразования в MQL4 показаны на схеме: Сплошные линии со стрелками обозначают преобразования, которые выполняются без потери информации. Вместо типа char может выступать тип bool (оба занимают в памяти 1...
Reason: