Source code library - Expert Advisors, Indicators and Scripts

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2012.07.06 11:30

## Running Median Indicator for MT4 - indicator for MetaTrader 4

Views:
8122
Rating:

### Description:

This indicator computes the median of odd span. The median is described as the numerical value separating the higher half of a sample, or a probability distribution, from the lower half. 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.

Calculation of medians is a popular technique in summary statistics and summarizing statistical data. A very nice property of the median is that the distance between the median and the mean is bounded by one standard deviation. The median is also a non-lagging operator.

The paradox is that it is almost impossible to find the median indicator in trading softwares. Moreover, straightforward implementations rely on array sorts, which is a very slow operation that does not scale up to long timeseries.

I therefore designed this running median operator which is incremental and therefore very fast. It is under the GNU public license.

### Image:

Last comments | Go to discussion (14)
hindmost | 13 Jul 2012 at 10:37

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

willgart | 14 Jul 2012 at 01:07

I add this line in the code: (just before runmedian(limit);)

if(limit<period)limit=period;

because the indicator did not redraw on a new candle (as well as the current one)

with this I force the indicator recalculate the lastest candles and fill the working buffer, else the current and new candles will not have enough info to evaluate the median value.

hindmost | 14 Jul 2012 at 09:29
Right. Good remark. We could also correct the function itself :

for (cursor=limit;cursor>=0;cursor--) {

->

for (cursor=MathMax(limit,period);cursor>=0;cursor--) {

willgart:

I add this line in the code: (just before runmedian(limit);)

if(limit<period)limit=period;

because the indicator did not redraw on a new candle (as well as the current one)

with this I force the indicator recalculate the lastest candles and fill the working buffer, else the current and new candles will not have enough info to evaluate the median value.

mql4_comments | 19 Sep 2013 at 22:13

In metatrader 4 the median stops drawing, refresh doesn't work. The only way to let it redraw is to open the indicators list and adjust the median and press ok. Could there be an update please?

Later.....Oh sorry, I copied the text now and it worked, thank you. But the text isn't in the download yet.

mql4_comments | 3 Oct 2013 at 20:47
When I use an expert advisor generator then this indicator doesn't work, I load it as a custom indicator but it doesn't work. It doesn't give any buy and sell signals. It is too difficult for me to understand how to edit all these things. Run median seems like a very good indicator. Is there anybody that can adjust this indicator so that it can be easily implemented for expert advisors?