Questions from Beginners MQL5 MT5 MetaTrader 5 - page 374

 
Vitalii Ananev:
Then you just need to take the value of iHigh(Symbol(),PERIOD_D1,0), after a certain period of time. This only makes sense for the current day candle, which is not yet completely formed. But if you take the values of past days, they will be the same at any time.
That's the problem, I need to look at it retrospectively....
 
-Aleks-:
That's the trouble, I need to look at it retrospectively....

I see. You need to fix all intraday price extremes. I cannot think fast enough how to do that on historical data.

The first thing that comes to mind is to analyze the fractals formed on intraday timeframes.

 

I do not know how to put it more clearly, in general, how to set the name of the array as a variable?

For example, there are 2 arrays Mass1 and Mass2, you need to make it run the same function, but by condition with two different arrays:

if(условие==true)

	И мя_массива=Mass1

else 

	 Имя_массива=Mass2

and type of function:

A=Имя_массива[123];
 
VANDER:

I do not know how to put it more clearly, in general, how to set the name of the array as a variable?

For example, there are 2 arrays Mass1 and Mass2, you need to make it run the same function, but by condition with two different arrays:

and type of function:

And just declare two arrays, what beliefs are preventing?
 
VANDER:

I do not know how to put it more clearly, in general, how to set the name of the array as a variable?

For example, there are 2 arrays Mass1 and Mass2, you need to make it run the same function, but by condition with two different arrays:

Well and type function:

No way. Becausean array is a numbered set of variables.

 
VANDER:

I do not know how to put it more clearly, in general, how to set the name of the array as a variable?

For example, there are 2 arrays Mass1 and Mass2, you need to make it run the same function, but by condition with two different arrays:

Well and type a function:

Make a function inside which you perform operations on the array. And by condition, pass different arrays to the function:

//+------------------------------------------------------------------+
double massive_a[];
int a, massive_b[];
//+------------------------------------------------------------------+
void OnTick() {
   if(a==1) WorkWithMassive(massive_a);
   else WorkWithMassive(massive_b);
}
//+------------------------------------------------------------------+
void WorkWithMassive(double &massive[]) {
   // работаем с массивом а
   }
//+------------------------------------------------------------------+
void WorkWithMassive(int &massive[]) {
   // работаем с массивом b
   }
//+------------------------------------------------------------------+
 
Vitalie Postolache:
And simply declaring two arrays prevents what beliefs?
they are both declared, it's just that the function is large and the same for all arrays so there is a need to choose
 
Artyom Trishkin:

Make a function inside which you perform operations on an array. And pass different arrays into the function by condition:

oops, but inside theWorkWithMassive function,how do you refer to this array?
 
VANDER:
oops, but inside theWorkWithMassive function,how do you refer to this array?

An array is passed by reference and you are referring to the exact array you pass to the function via the input parameters. For example (purely hypothetical)

//+------------------------------------------------------------------+
void WorkWithMassive(double &massive[]) {
   int a=20;
   ArrayResize(massive,a);
   for(int i=a-1; i>=0; i--) {
      massive[i]=iOpen(Symbol(),Period(),a);
      }
   }
//+------------------------------------------------------------------+

It is better, of course, to pass all the necessary parameters to the function:

//+------------------------------------------------------------------+
void WorkWithMassive(string symbol, int timeframe, double &massive[]) {
   int a=20;
   ArrayResize(massive,a);
   for(int i=a; i>=0; i--) {
      massive[i]=iOpen(symbol,timeframe,a);
      }
   }
//+------------------------------------------------------------------+

well and you can use function overloading - a function with the same name does different things depending on the input parameters and type:

//+------------------------------------------------------------------+
void WorkWithMassive(string symbol, int timeframe, double &massive[]) {
   int a=20;
   ArrayResize(massive,a);
   for(int i=a; i>=0; i--) massive[i]=iOpen(symbol,timeframe,a);
   }
//+------------------------------------------------------------------+
int WorkWithMassive(int inp_value, int array_size, int &massive[]) {
   ArrayResize(massive,array_size);
   massive[array_size-1]=inp_value*2;
   return(massive[array_size-1]+massive[0]);
   }
//+------------------------------------------------------------------+
 
-Aleks-:
Right.

1. Determine the opening time of the daily candle;

Determine the number of bars num on the TF you want (if you want to check the extremum of the day every 15 minutes - M15 bars);

3. Receive the data high for num bars;

3. In the loop, compare all the values of high bars with the variable dayHigh for the desired day candle (initially dayHigh = 0);

4. If high > dayHigh, you store the new value in the variable dayHigh;

Reason: