The median is the value separating the higher half of a data sample, a population, or a probability distribution, from the lower half. For a data set, it may be thought of as the “middle” value. For example, in the data set {1, 3, 3, 6, 7, 8, 9}, the median is 6, the fourth largest, and also the fourth smallest, number in the sample. For a continuous probability distribution, the median is the value such that a number is equally likely to fall above or below it. (wikipedia)
The first part of the code is the median calculation of a Close price (function created by @Despair), then this median price is averaged with a non linear time series Simple Moving Average function that smooth the information and so improve the reading of values.
Idea come from this topic in the Spanish forum: nueva media móvil con precio mediano
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
//PRC_MA of last X PriceMedian | indicator //01.05.2018 //Nicolas @ www.prorealcode.com //Sharing ProRealTime knowledge // --- settings length=5 priceMAperiod=20 // --- end of settings // median average //median calc once Median=0 if barindex>length then FOR X = 0 TO length-1 M = close[X] //this example takes the median of the last X values SmallPart = 0 LargePart = 0 FOR Y = 0 TO length-1 IF close[Y] < M THEN SmallPart = SmallPart + 1 ELSIF close[Y] > M THEN LargePart = LargePart + 1 ENDIF IF LargePart = SmallPart AND Y = length-1 THEN Median = M BREAK ENDIF NEXT NEXT endif count=0 sum=0 lastmedian=0 for i = 0 to barindex do if median[i]<>lastmedian then lastmedian=median[i] count=count+1 sum=sum+median[i] if count=priceMAperiod+1 then sum=sum-last last=median[i] break // endif endif next if last<>last[1] then avg = sum/priceMAperiod endif return avg |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
I have been trying this indicator and works perfectly on Light Crude Oil. I only have one question. What is lengh? and whaty is priceMAperiod?
I can guess the priceMAperiod is the moving average period, so it takes the last 20 prices. ( in this case) but lengh?
Thanks a lot
length is the period used to calculate the median price.
And the PriceMAPeriod? aren´t the same?
The PriceMAPeriod is the period to make the average of all the last X medianprice found.
Thanks a lot Nicolás. Have a nice day