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

 
igrok333:
Is there a function that returns the type of variable?

For example, you write.

int a=10;

then you write:

functia(a);

and it says: INT!

:)
string functia(int a) { return "INT!"; } // suddenly
string functia(double a) { return "DABLE!"; } // also unexpectedly
 
igrok333:
Is there a function that returns a variable type?

For example, you write.

int a=10;

then you write:

functia(a);

and it says: INT!

:)

From the help:

void OnStart() 
  { 
//---  
   CTrade trade;    
   double d_value=M_PI; 
   int i_value=INT_MAX; 
   Print("d_value: type=",GetTypeName(d_value), ",   value=", d_value); 
   Print("i_value: type=",GetTypeName(i_value), ",   value=", i_value); 
   Print("trade: type=",GetTypeName(trade)); 
//---  
  } 
//+------------------------------------------------------------------+ 
//| Возвращает в строковом виде тип                                  | 
//+------------------------------------------------------------------+ 
template<typename T> 
string GetTypeName(const T &t) 
  { 
//--- вернем тип в виде строки 
   return(typename(T)); 
//--- 
  }
 
WinProject:

It's much simpler. Create a display button (or use one of the existing buttons). Further on pressing - all necessary objects are set visibility flag on all TFs. When the button is released, all objects are set to display property on all TFs (or necessary if needed). There is no need to delete/rearrange anything. The only thing to do is to redraw the chart after this operation.

Object property OBJPROP_TIMEFRAMES.

 

Can you tell me how to get the data from the indicator into an array? I.e. it is clear that I need to declare an array

double num_array[];

I'm not quite sure what to do next...

num_array[0] = iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i); // the array with the index [0] equals MA, but if we change the index into [1], then it turns out that num_array[1] is equal

the same data from the indicator as num_array[0]. This should not be the case. The array should be filled sequentially. All I can think of is to divide the day into 24

hours, declare a two-dimensional array and assign an index to each hour with its own string etc....

Maybe there is a simpler way or less messy?

 
Corvin85:

Can you tell me how to get the data from the indicator into an array? I.e. it is clear that I need to declare an array

double num_array[];

I'm not quite sure what to do next...

num_array[0] = iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i); // the array with the index [0] equals MA, but if we change the index into [1], then it turns out that num_array[1] is equal

the same data from the indicator as num_array[0]. This should not be the case. The array should be filled sequentially. All I can think of is to divide the day into 24

hours, declare a two-dimensional array and assign an index to each hour with its own string etc....

Maybe there is a simpler way or less messy?


I see it like this:

double num_array[];  

ArrayResize(num_array,24);

for(int i=0;i<24;i++)

{

 num_array[i] = iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);

}
 
Vladislav Andruschenko:

I see it this way:

double num_array[];  

ArrayResize(num_array,24);

for(int i=0;i<24;i++)

{

 num_array[i] = iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);

}
Ah, it turns out to set the maximum number of indexes in the array viaArrayResize and run them through a loop. Thank you very much, but then there is a question, when all indexes are filled with data from the indicator, should they be cleared throughArrayFree, or will it rewrite itself? Or after 24x all will stop at all? Sorry for the dumb question, but arrays are kind of a dark horse with unknown functions.
 
Corvin85:
Oh, I can useArrayResize to set the maximum number of indexes in the array and run them through the loop. Thank you very much, but then there is a question, when all indexes are filled with data from the indicator, should I clear them throughArrayFree, or will it rewrite itself? Or after 24th all will stop? Sorry for the blunt question, but arrays are kind of a dark horse with unknown functions.
Well, it depends on what purpose you're pursuing. I wrote the code to fill the array with mA data of the last 24 bars. It will be updated continuously.
 
Corvin85:
Oh, I can set the maximum number of indexes in the array viaArrayResize and run them through the loop. Thank you very much, but then there is a question, when all indexes are filled with data from the indicator, should I clear them throughArrayFree, or will it rewrite itself? Or after 24th all will stop? Sorry for the blunt question, but arrays are kind of a dark horse with unknown functions.

Array = a set of simple variables lined up in a row for easy reference to their index. The index is an integer variable for accessing array items by number in order to organize a loop. Index = number counter. ArrayFree = array destruction - like bulldozing over ramshackle houses. But it can be restored again with ArrayResize. Well ,ArrayResize is a fence around a residential array. Ours is here, but strangers are behind the fence, and it's forbidden to get in there. You can enter each house many times (assign a new value to an array element). An array is very simple and convenient for many purposes. And those who are afraid of arrays - those ... So, it's better to get to grips with them.

 
//+------------------------------------------------------------------+ 
//| Проверка массива                                                 | 
//+------------------------------------------------------------------+ 
#property strict
int m[10];
int n;

void OnStart() 
{ 
  ArrayInitialize(m,7);          Вывод();  // Заполнить семерками
  ArrayResize(m,7);              Вывод();  // Удалить 3 последних элемента
  ArrayResize(m,9);              Вывод();  // Увеличить размер
  m[1]=1;  m[7]=1;               Вывод();  // Изменить 2 элемента
  for(n=0; n<9; n++) m[n]=n*n;   Вывод();  // Заполнить квадратами номеров
  ArrayCopy(m,m,0,2,7);          Вывод();  // Копирование со сдвигом
  ArrayResize(m,ArraySize(m)-2); Вывод();  // Удалить 2 последних элемента
} 

void Вывод()
{
  string s="";
  for(n=0; n<ArraySize(m); n++)
  s+="  " + string(m[n]);
  Alert(ArraySize(m), ":", s);
}
Try running a script like this - and practice
 
Artyom Trishkin:

From the reference:

cp