How do you algorithmise the detection of MA feed clusters? - page 6

 

Calculatethe median price on a given interval with a given number of approximations.

Hello There is an array of values.

The task is to write a function.

Input parameters:

- the array contains numbers of required elements to calculate the median - bufInBar[]

- array size -bufInBar[]- count

- number of median approximations - fokus

void medianaL0(const int &bufInBar[], int count, int fokus)

That is, there is a class

bufInBar[i] - используется для загрузки нужного элемента при расчете медианы 

BP[bufInBar[i]].CenaPerioda; - по этому значению рассчитывается медиана
BP[bufInBar[i]].Period; 

On output :

BP[bufInBar[i]].Mediana; 

Filled in ascending order e.g. from 0 to 10.

That is, iffokus=10 in the condition, then at the interval i<count the ten values

BP[bufInBar[i]].Mediana;

will be 1 to 10.

For example

BP[3256].Mediana=0;
BP[6256].Mediana=1;
BP[9256].Mediana=2;
...
 
It is not clear what the fokus is
 
In theory, the median is the value of the element in the middle of an ordered array. What is it in your case?
 
Dmitry Fedoseev:
It is not clear what fokus is
Aleksei Stepanenko:
In theory, the median is the value of the element in the middle of an ordered array. What is it in your case?

Example:

Array of 30 MA price values, look for the middle of the ordered array.

We get 15(L0) value in the middle of the array, then we get two arrays from L0 down and L0 up and find the middle of these arrays and so on until we get thefokus number(seven values for example)

                        --------------|--------------
                        -------|--------------|------
                        ---|-------|------|-------|--
fokus=7
| - значение цены
        

 
Mikhail Toptunov:

Example:

Array of 30 MA price values, look for the middle of the ordered array.

We get 15(L0) as the value in the middle of the array, then we get two arrays from L0 downwards and L0 upwards and find the middle of these arrays and so on until we get thefokus number(seven values for example)

And if there is an even number of array elements, which element will be the median, or should it be calculated as the average of two or something else?

 
Mikhail Toptunov:

Example:

Am I correct in assuming that we need to find seven percentiles: 12.5, 25, 37.5, 50, 62.5, 75, 87.5?

If so, divide the number of elements in the ordered array by 8 (7+1), and multiply by the number of percentile you want. We get the following element indices: 3, 7, 11, 15, 18, 22, 26.

int index=ArraySize(bufInBar)*percentile/(fokus+1);

//где percentile - номер нужного перцентиля от 1 до fokus 

double value=bufInBar[index];

Right, or am I going the wrong way? If so, the most important thing here is to create a parsimonious mechanism for maintaining an ordered array.

 
Why can'tMathQuantile() be used?
 
Dmitry Fedoseev:

And if the array has an even number of elements, which element is the median, or should it be calculated as the average of two or something?

I think it's easier to take an even integer value.

If there are 15 elements, then the median is 8.

 
Aleksei Stepanenko:

Do I understand correctly that we need to find seven percentiles: 12.5, 25, 37.5, 50, 62.5, 75, 87.5?

If so, divide the number of elements in the ordered array by 8 (7+1), and multiply by the number of the required percentile. We get the following element indices: 3, 7, 11, 15, 18, 22, 26.

Right, or am I going the wrong way? If so, the most important thing here is to create a parsimonious mechanism for maintaining an ordered array.

From the array of MA values you need to find the median of the whole array, then the medians of the arrays obtained above/below the first median, etc.

 

It seems right then, the median of the first part of the array is a quarter of the total array, and it is 25 percentile. And the median of the second part is 75 percentile.

This:

                        --------------|---------------
                        -------|--------------|-------
                        ---|-------|------|-------|---

equals this:

                        ---|---|---|---|---|---|---|---