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

 

remove the string from the structure, it will work

or copy element by element, every variable in the structure
or replace the string with a static array uchar[16];

 
Taras Slobodyanik:

remove the string from the structure, it will work

Either you copy element by element, every variable in the structure
or replace the string with a static array uchar[16];


which string do you want to remove?

I actually went to the reference book to see an example, to understand how to copy a variable of structure type to another variable of the same structure type... And what happens to the functions that are declared in them. Copying element by element is not good... ...it makes a very long drag.

 
Aleksandr Brown:

which string to remove?

As a matter of fact, I've used the reference book to see an example, to understand how a variable of structure type can be copied into another variable of the same structure type... And what happens to the functions that are declared in them. Copying element by element is not good... ...it just turns out to be a very long drag.

Have you triedArrayCopy?

 
STARIJ:

Have you tried ArrayCopy?


We are talking about structured data. You mean a variable of the structure type to be represented as an array??? :-))) Not an option either... There are functions in the structure that if you declare them separately, there will be even more confusion.

 
Yes, ArrayCopy makes nonsense. If you need to output colour components - here
//+------------------------------------------------------------------+ 
//| Компоненты цвета                                                 | 
//+------------------------------------------------------------------+ 
#property strict
#property script_show_inputs
input     color  testColor=0x00ff00;  // задайте цвет для тестирования

//--- функция для вывода цвета в виде строки
string toString(color x)
{
 return  "("+
      (string) ( x & 0xff)           +":"+
      (string) ((x & 0xff00 ) >> 8)  +":"+
      (string) ((x & 0xff0000)>> 16) +")"   ;
}

void OnStart() 
{ 
   Alert("color ",testColor," = ",toString(testColor));  // выдает color clrLime = (0:255:0) а ведь думал это clrGreen
}

Although it is easier to use ColorToString(testColor)

If you want to use data conversion, use ServiceDesk. The error you mentioned is also present in MetaEditor in MT5

 
Aleksandr Brown:

which string to remove?

As a matter of fact, I've used the reference book to see an example, to understand how a variable of structure type can be copied into another variable of the same structure type... And what happens to the functions that are declared in them. Copying element by element is not good... ...it's a very long drag.


Yes, sorry, I misread that advice...

As far as I remember, a new union type has now been introduced and you should do something like this:

#property script_show_inputs

#define  red    colir[0]
#define  green  colir[1]
#define  blue   colir[2]

input color          testColor=clrBlue;// задайте цвет для тестирования
//--- структура для представления цвета в RGB
union RGB
  {
   color             cvet;
   uchar             colir[4];
   string            toString();    // функция для получения в виде строки
  };
//--- функция для вывода цвета в виде строки
string RGB::toString(void)
  {
   string out="("+(string)red+":"+(string)green+":"+(string)blue+")";
   return out;
  }

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- переменная для хранения в RGB
   RGB colorRGB;

   colorRGB.cvet=testColor;
   Print("color ",colorRGB.cvet," = ",colorRGB.toString());
//---
  }
 

Good afternoon. Please clarify why it does not show the correct information.


//+------------------------------------------------------------------+
//---- indicator buffers
double      AO[];                // массив для индикатора iAO
//---- handles for indicators
int         AO_handle;           // указатель на индикатор iAO
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- создание указателя на объект - индикатор iAO
   AO_handle=iAO(NULL,0);
//--- если произошла ошибка при создании объекта, то выводим сообщение
   if(AO_handle<0)
     {
      Print("Объект iAO не создан: Ошибка исполнения = ",GetLastError());
      //--- принудительное завершение программы
      return(-1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ArrayFree(AO);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//--- Достаточно ли количество баров для работы
   if(Bars(_Symbol,_Period)<10) // общее количество баров на графике меньше 10?
     {
      Alert("На графике меньше 10 баров, советник не будет работать!!");
      return;
     }

   ArraySetAsSeries(AO,true);
//--- заполнение массива AO[] текущими значениями индикатора iAO
//--- задаём порядок индексации массива как в таймсерии
//--- если произошла ошибка, то прекращаем выполнение дальнейших операций;
   if(CopyBuffer(AO_handle,0,0,100,AO)<=0)return;
   double AO_1=AO[1];
   AO_1=NormalizeDouble(AO_1,7);
   Print("AO=",AO_1);
   double AO_2=AO[2];
   AO_2=NormalizeDouble(AO_2,7);
   Print("AO2=",AO_2);
  }
//+------------------------------------------------------------------+
 
gastinets:

Hi. Could you please tell me why it does not give the right information?


Where did you see incorrect information?

And, please, insert the code correctly (I corrected in your post)

Posted in red rectangle:


 

I got it from the code, sorry - I'll take it into account in the future

negative value is displayed incorrectly. this may be due to the double type

let me clarify a question - how to make a negative value to be displayed correctly and whether it can be normalized like a positive value (which is displayed correctly)

 
gastinets:

I got it from the code, sorry - I'll take it into account in the future

The negative value is displayed incorrectly. It must be because of the double type.

I'll clarify the question - how to make a negative value be displayed correctly and whether it can be normalised like a positive value (which is displayed correctly)


When I was a kid, when I dabbled with a calculator, I used to get the same kind of E's. After I started programming I remembered my calculator and everything went back to normal.


Try converting it to a string if you want to see the number in a string.

   double AO_1=AO[1];
   AO_1=NormalizeDouble(AO_1,7);
   Print("AO=",DoubleToString(AO_1,7));
   double AO_2=AO[2];
   AO_2=NormalizeDouble(AO_2,7);
   Print("AO2=",DoubleToString(AO_2,7));
Reason: