NinjaScript > Language Reference > Data >


Print this Topic Previous pageReturn to chapter overviewNext page

Returns the median value of the specified series over the specified look back period. This method will sort the values of the specified look back period in ascending order and return the middle value. If an even number is passed in, the average of the two middle values in the sorted values will be returned.

NOTE: This method should NOT be confused with Median prices defined as (High + Low) / 2. This method returns the statistical median of a series.


Method Return Value

A double value representing the median value of the series.


GetMedian(IDataSeries series, int lookBackPeriod)




Number of bars back to include in the calculation


Any DataSeries type object such as an indicator, Close, High, Low, etc...




// Print the median price of the last 10 open prices (current open price + look back period's 9 open prices before that)
if (GetMedian(Open, 9))
    Print("The median of the last 10 open prices is: " + GetMedian(Open, 9).ToString());