Indicators: Running Median Indicator for MT4

 

Running Median Indicator for MT4:

This indicator computes the median of odd span. It is often considered as one of the most robust smoothing operator in the presence of outlier values, and particularly more robust than the mean.

Author: Stephane Coulondre

 

Hi,

Hindmost, i compared the code with the simple moving average. I could not find much of a difference. Also, how is that you are saying it is not Lagging? Please reply.

Regards,

 

Hi, well there is indeed a big difference in the mathematical formula : SMA is also incremental (as all "moving" operators) but that's the only property they share ! Median is not simply the sum divided by the length, but involve a data sort, and only the middle element (i.e. median) is returned. It is not lagging in the sense that any recent value in the time serie can have a immediate impact on the sort, thus on the median (such as -100 pips at once), wheras for the mean (and EMA, LWMA and so on) you have to wait a long time for it to react ...

For more information please consult wikipedia on median and more general "robust operators".

Cheers

mcxravi:

Hi,

Hindmost, i compared the code with the simple moving average. I could not find much of a difference. Also, how is that you are saying it is not Lagging? Please reply.

Regards,

 

Is it possible to make it MTF indicator?


Dilip

 
hindmost:

Hi, well there is indeed a big difference in the mathematical formula : SMA is also incremental (as all "moving" operators) but that's the only property they share ! Median is not simply the sum divided by the length, but involve a data sort, and only the middle element (i.e. median) is returned. It is not lagging in the sense that any recent value in the time serie can have a immediate impact on the sort, thus on the median (such as -100 pips at once), wheras for the mean (and EMA, LWMA and so on) you have to wait a long time for it to react ...

For more information please consult wikipedia on median and more general "robust operators".

Cheers

mcxravi:

Hi,

Hindmost, i compared the code with the simple moving average. I could not find much of a difference. Also, how is that you are saying it is not Lagging? Please reply.

Regards,




well... your indicator is repainting. we have to wait 13 periods (default value) before having a stable value. like you says, in your non lag definition, the indicator reacts quickly, but also provides false signals quickly...

(edited)

my mistake, no repaint.

but your indicator has a lag of 13 candles... which is the default value for your indicator like the moving average suffer a delay of X where X is the number of periods.

 

Yes, I will consider this as soon as possible.


dlppat:

Is it possible to make it MTF indicator?


Dilip

 

I certify it does not repaint, just look at the code to be sure !

I do not agree on the lag. Les us have a look at ths following chart (EURUSD 1H, with SMA25 in Red,and Median25 in Blue) :

- What you call the "lag" here seems to be only 13 (ie. you feel like it spends 13 bars to react) it is just the HALF of the period, not the whole period = 25 div 2 = 12. Therefore if a follow the same logic, you should admit then from 12 to 25, it is "better" than the SMA (because closer to the price) : does it therefore "unlag" :-) ?

- you mistake "lagging" with "robust" : the question of lagging does not make sense here, as the median formula does not reflect the result of a mathematical operations (such as additions, division, therefore averages and others) which by definition can only occur when all necessary data has been collected. The median indicator does NOT involve ANY math operation, but relies on sorts which are permanently up to date, in this sense the median reflects the REALITY. In the above chart, the median action makes much more sense than the SMA which points downwards and then reveals .... nothing interesting. The median, on the contrary, shows 3 potential reversal points.

- Let us consider also the following chart :

- here you would say in the morning of June 28 : "great is it not lagging it is even foreseeing the future !". That's not true either. You can only remark that is is more ROBUST that the SMA which started to raise where as the median revealed that it did not raise ENOUGH to go long. Please have a look at the definition of "robust" is statistics.

- to conclude, remember as a general remark that I have nothing to sell, I so I won't spend more time defending my indicators (especially if I intend to post more) in the future, especially against peremptory affirmations. My indics are scientifically founded.



willgart:
hindmost:

Hi, well there is indeed a big difference in the mathematical formula : SMA is also incremental (as all "moving" operators) but that's the only property they share ! Median is not simply the sum divided by the length, but involve a data sort, and only the middle element (i.e. median) is returned. It is not lagging in the sense that any recent value in the time serie can have a immediate impact on the sort, thus on the median (such as -100 pips at once), wheras for the mean (and EMA, LWMA and so on) you have to wait a long time for it to react ...

For more information please consult wikipedia on median and more general "robust operators".

Cheers

mcxravi:

Hi,

Hindmost, i compared the code with the simple moving average. I could not find much of a difference. Also, how is that you are saying it is not Lagging? Please reply.

Regards,




well... your indicator is repainting. we have to wait 13 periods (default value) before having a stable value. like you says, in your non lag definition, the indicator reacts quickly, but also provides false signals quickly...

(edited)

my mistake, no repaint.

but your indicator has a lag of 13 candles... which is the default value for your indicator like the moving average suffer a delay of X where X is the number of periods.

 

mmm...

I'm putting it with SMA13 (green), EMA13 (red) and LWMA13 (violet), the white is the median 13. all 3 moving averages moves faster than the median one. they are configured to average the median value (not the close)

but I like the idea, and I'll try a version where we got the 50% percentile value instead-of the median

 
willgart:

but I like the idea, and I'll try a version where we got the 50% percentile value instead-of the median

The median is already the 50% percentile value............

On your chart, I clearly see that the median is the only monotone indicator, i.e. robust.... That's exactly its advantage...

 


double RunMedian_4=iCustom(NULL,0,"RunMedian",MedianLength,0,0);

i get 2147483647 for this in an EA.

"You need to apply an indicator buffer value next to IndVal[] value." NOPE

For some reason this fails to paint when backtesting

 

Try this, as there are 2 arguments to RunMedian

iCustom(NULL,0,"RunMedian",MedianLength,"",0,0);

If the error is still present, I will look more thoroughly.

mrmedia:
double RunMedian_4=iCustom(NULL,0,"RunMedian",MedianLength,0,0);

i get 2147483647 for this in an EA.

"You need to apply an indicator buffer value next to IndVal[] value." NOPE

For some reason this fails to paint when backtesting

Reason: