Self-regressive Median Coefficient - page 7

 
Mladen Rakic:

The code of the complete indicator :

It draws this :


The code used in this indicator is different (different, faster,  way of preparing and passing array elements but the results are the same)  The 2 lines of code that need optimization remain the same (as it is obvious, since, practically, it is all that remains in the function calculation code)

Fixed:

double  QuantRegCoeff=(coeffSize%2==1) ?(CoeffBuffer[(coeffSize-1)/2]) : (0.5*(CoeffBuffer[coeffSize/2]+CoeffBuffer[coeffSize/2-1]));

But as Alain pointed, size * (size-1) is always even.

Files:
 
Alain Verleyen:

So at my surprise, I didn't succeed. The main optimization idea I had was to reduce the number of division operations needed :

As this operation is done in a loop for every candle i, there are a lot of repetitions of the exact same operation. So the idea was to do all the operations once and to memorize them (see attached how I did). However it doesn't improve this speed, even while the numbers of operations was reduced by a factor 16 !

From 64 millions to 4 millions division operations, but no change in execution time. I didn't expect that. That means double arithmetic CPU is very efficient and cached very well all the results.

Also, though this imbricated loop with division operations is time consuming, the main bottleneck in the ArraySort(), the speed impact is more than 3 times the one of the loops. So even if the "division" optimization had worked that global impact would have been low (~20% max).

That was an interesting exercise, even if it failed.

Attached the code (as we are on week-end I didn't pay attention to "live" update).

This makes more sense to me:

double  QuantRegCoeff=0.5*(CoeffBuffer[coeffSize/2]+CoeffBuffer[coeffSize/2-1]);
Files:
275327_AV.mq5  10 kb
 

https://storage.tusur.ru/files/43224/2012_4.pdf

Done in SAS.

CPP:

http://www.aronaldg.org/webfiles/compecon/src/libscl_float.15-11-16/src/quantreg.cpp

Is it feasible in MQL5? Does anyone know? I cannot try it because I am offshore and cannot use MQL5... :(

 

Using a sine wave model, I calculated the error for a moving average and a moving median:

Applied Price Average Median
Open 943,7% 943,8%
High 744,8% 744,8%
Low 744,8% 744,8%
Close 545,8% 545,9%
hl2 0,0% 0,0%
hlc3 44,3% 44,3%
ohlc4 0,0% 0,0%
hlcc4 102,9% 102,9%
(Open+Close)/2 0,0% 0,0%


After much thought, I added the "weird" (?) applied price OC2. In my short experience, I already suspected that (High+Low)/2 was a wise choice. If High/Low (Ask/Bid) is not available or reliable, using OC2 as alternative has proved as an excellent choice.

I will investigate further with complex wave functions and post results.

Best regards.

 

For some reason I discovered that I was doing the following:

https://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator

(I lack formal maths education)

 

Median Function

We shall not forget. :)
Reason: