MEDIAN function coding
Forums › ProRealTime English forum › ProBuilder support › MEDIAN function coding
- This topic has 12 replies, 2 voices, and was last updated 3 years ago by robertogozzi.
Tagged: median, median function
-
-
02/13/2018 at 1:46 PM #62594
Hi everyone,
I am working on an indicator trying to return the Median function instead of the classic Average one.
For example the Median value of the 5 latest price records such as : Median (Price, 5)
I haven’t seen any function of this type in ProRealTime or on the site’s topics so I tried to code it but can’t manage to get a correct result.
Any help would be greatly appreciated. Thanks !
02/13/2018 at 2:49 PM #62605Please confirm this definition for a Median:
Median : which is the middle number of a group of numbers; that is, half the numbers have values that are greater than the median, and half the numbers have values that are less than the median. For example, the median of 2, 3, 3, 5, 7, and 10 is 4.
02/13/2018 at 2:56 PM #6260802/13/2018 at 3:01 PM #6261002/13/2018 at 7:08 PM #6264302/13/2018 at 8:18 PM #6265202/13/2018 at 8:34 PM #6265602/13/2018 at 8:57 PM #62659Found it 🙂
Median Filter1234567891011121314151617181920once Median=0if barindex>length thenFOR X = 0 TO length-1M = close[X] //this example takes the median of the last 5 closesSmallPart = 0LargePart = 0FOR Y = 0 TO length-1IF close[Y] < M THENSmallPart = SmallPart + 1ELSIF close[Y] > M THENLargePart = LargePart + 1ENDIFIF LargePart = SmallPart AND Y = length-1 THENMedian = MBREAKENDIFNEXTNEXTendifReturn Median as "Median"02/13/2018 at 11:18 PM #6267007/05/2021 at 6:36 AM #173127Hi Nicolas,
Have you worked out the Median function using arrays?
Tnx in advance.
07/05/2021 at 10:22 AM #173148Actually I don’t think arrays are of much help in this case, because CLOSE is an array by itself (close[0], close[1], etc…). In any case you will have to always scan LENGTH bars (or elements) to get the MEDIAN.
07/05/2021 at 11:16 AM #173150What is the data set is not CLOSE?
07/05/2021 at 11:29 AM #173152Whatever tha data set, it is historicized (thus becoming an array).
Be it MedianPrice, TypicalPrice, xClose (Heikin-Ashi close) or any expression assigned to a variable.
-
AuthorPosts
Find exclusive trading pro-tools on