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

 
Mikhail Sobolev:

Hello. I'm writing a function - I can't pass an array as a parameter along with any other parameters. Examples:

From there, my imagination runs out.
A function must somehow look through an array - and for this, I believe, it must be passed this array. Or is it not?
Thank you in advance.

Vitaly above has already written the order of passing arguments to a function.

I should add: if you've specified a default value for one of the arguments in the function parameters, then all subsequent arguments must also have default values.

 
Artyom Trishkin:

Vitaly above has already written the order in which the arguments are passed to the function.

I should add: if you have a default value assigned to one of the arguments in the function parameters, then all subsequent arguments must also have default values.

Right, as usual I missed something obvious. And I have read about it more than once.

Thank you, Vitaly.

 

I want to write an indicator linked to ATR, except that sometimes abnormally large candles appear on the chart, as was the case on January 3.

This is not a broker's fiction, but they break all the calculations, what is the best way to exclude them from the calculations?


And the second question: advise me on what period is optimal to calculate the ATR for the daily and hourly chart, are there such values?

 
psyman:

I want to write an indicator linked to ATR, except that sometimes abnormally large candles appear on the chart, as was the case on January 3.

This is not a broker's fiction, but they break all the calculations, what is the best way to exclude them from the calculations?


And the second question: advise me on what period is optimal to calculate the ATR for the daily and hourly chart, are there such values?

First of all we need to answer the question "What is ATR, what does this indicator show? Then you may get an understanding of optimality and whether something should be excluded from the calculations.

 

I have an idea to write a function that will take and shift an array. The question is how to make this function so that it itself determines what type of array is one-dimensional or 2-dimensional, so that I don't have to specify in the arguments every time that the array is 2-dimensional or regular. At the same time, I want to apply a template, so that I don't have to specify the type of the array.

template<typename T>
void MoveArray(T &array1[][])в скобках указано что массив 2 ух мерный.
{
тело
}

How can I make it so that I don't have to specify what type of array?

 
Alexey Viktorov:

First we have to answer the question "What is ATR, what does this indicator show?


The indicator should compare the High-Low of the current candle with some average value for the period, which seems to be the easiest task.

 
psyman:

And the second question: advise on what period is optimal to calculate the ATR for the daily and hourly, are there such values?

period 3, shift 1 - work on the ATR at the beginning of the period.

 
Aleksey Vyazmikin:

period 3, shift 1 - work on the ATR at the beginning of the period.

I don't understand, why do you need a shift?

I asked about different periods for different timeframes because during the night the movements are usually very sluggish, and we should either ignore them or increase the period to smooth out the readings.

 
psyman:


The indicator should compare the High-Low of the current candle with some average value for the period, a seemingly simple task.

This is the answer to a completely different question. As I understand it is your wish, and understanding what the ATR indicator shows is not evident.

The Average True Range (ATR) technical indicator isa measure of market volatility.


Calculation

The True Range is the greater of the following three values:

  • difference between the current high and low;
  • difference between the previous close price and the current maximum;
  • the difference between the previous closing price and the current minimum.

The Average True Range ( ATR) is a moving average of the true range values.

Therefore, if you exclude any indicator from the calculation, it will not be ATR, but something and something...

And the second answer: Everything depends on the target. If you work intraday on H1, in my opinion, it is more reasonable to take the average value for several days. I.e., we can consider that the expected price change of the current day is xxx points. Respectively, if the strategy implies holding an open position +/-1 hour, then the ATR should be looked at over several bars of H1 period.

 
psyman:

I don't understand, why do you need a shift?

I asked about different periods for different TFs because during the night the movements are usually very sluggish and either they should be ignored or the period should be increased to smooth out the readings.

The shift should be done so that from each new extremum on the estimated TF the ATR would not change.

The movements fade gradually, therefore ATR(3) will do fine.

However I don't use unnecessary increments, I only use the delta from the opening to the extremum.

Reason: