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

 
The Yin-Yang symbol was suggested as a model for the MA, not as an "icon" of atheism or dialectics. Convergence/divergence of prices in relation to the MA, a new extremum is formed in the price levels, but the price is closer to the MA than the previous extremum (in statistical deviations), i.e. probability of trend change is formed (MA crossing), no crossing, but conditions also exist in the symbol - the birth of element occurs in the area of the opposite value.
 
Aleksei Stepanenko:

Guys, I still don't know if it's up or down.

Right.

 
Aleksey Nikolayev:

Which quantiles should be counted, e.g:

{0.5} - median

{0.25, 0.5, 0.75} - quartiles

{0.01, 0.02, ..., 0.99} - persentiles

Can you tell me something?

If I pass an array through MathQuantile, should I sort it?

- I understood that it doesn't matter if it's sorted or not.


It turns out that the index is not traceable to the array. Quantile is counted by price, and the index of the array to which the price is linked ...

 

I understand that this mathematics with a median or quantum, does not solve the problem satisfactorily!

Something I can't...

 

An array of values of the specified quantiles is returned. The indices of these values in the unsorted array are not known. The whole question is about speed. If this function is calculated on every bar and the array of values is large, the optimization time may be delayed. I would go a different way, but it's up to you.

 
Mikhail Toptunov:

If you pass an array through MathQuantile, should it be sorted?

Any permutation (sorting, for example) should not change the result.

 
Aleksei Stepanenko:

An array of values of the specified quantiles is returned. The indices of these values in the unsorted array are not known. The whole question is about speed. If this function is calculated on every bar and the array of values is large, the optimization time may be delayed. I would take a different way but it's up to you.

Which way would you take?

Alexey, which way would solve the problem)!

 

I do not know what task you have set for yourself, but generally speaking, the less cyclic calculations, the faster the algorithm is. There is a basic cycle - it is a pass through all the bars of the history, we can't get away from it. But we should try to get rid of the rest of them. TheMathQuantile, iHighest and other functions arein fact hidden loops. To speed up, we need to process information as it arrives and store it before the next bar. In the current calculations, do not use raw historical data, but the previously prepared data.

In the case of finding medians and other quantiles, it's less expensive to maintain an ordered array as the information arrives. I wrote the code above. If you have a "sliding window" within which information is needed, you need to think about how to remove old values from the array in the same quick way. You will probably need another array to store the indexes.

 
Maxim Kuznetsov:

approximate heatmap calculation algorithm (e.g. for 100 bar):

for all Close from 1 to 100 :

Close[N]=X will add to heatmap the sum of row heatmap[Resolution(X)]+={X/N} + {X/(N+1)}+{X/(N+2)}... up to 100.
What is in curly brackets is the "components" of averages, just highlighted.
Resolution(X) - "resolution", e.g. 10 points Round((X-MinimalX)/Point/10)

obtain a vector in which local maxima you need to find.

This vector is practically a vertical price profile

Could you please help me calculate the heatmap? I've tried median, quantile does not give a good indication of MA clusters.

//Pmax - количество Скользящих Средних МА
//masPra[] - значение цены МА по текущему бару
//masPer[] - значение индексов массива цен МА, для сортировки
void medianaL0_2(const double &masPra[],const int &masPer[])
 {
  // MathQuickSort(masPra,masPer,10,Pmax-1,1); // сортируем массив цен с 10 периода, по Pmax-1
  

If you can show what needs to be done, calculation( one bar at a time).

 
Mikhail Toptunov:

Please could you help calculate the heat map? tried through median, quantile does not work to achieve normal detection of MA clusters.

If you can show what needs to be done, calculation( one bar at a time).

I'll show the results directly, without optimizations, matrixes and complicated mathematics:

1. For the current bar we calculate all the MAs separately. We get SMA[N] array where the values of maxima up to N are located.

2. we create a heatmap[M] which covers prices from minimum=1.00000, each element is responsible for (e.g.) 10 points.

3. We fill this "raw" heatmap: we take each ma value and see which cell it refers to. index=(SMA[i]-minimum)/resolution. We increase the value of this cell hetmap[index]+=1.0

You can output the result to CSV and think

4. Smooth the "raw" heatmap values: start array smooth[] and read the average smotch[i]=average value of heatmap from i-window to i+window inclusive

5. The local maxima of smootch will indicate a "cluster of feeds". I hope you know how to look for maxima :-)

points 1-5 can be mathematically decomposed and computed much faster, with minimum loops and extra arrays, but not necessarily more obvious