MedianPrice
MedianPrice returns the average of the high and low of a bar in ProBuilder. Use MedianPrice, or MedianPrice[N] N bars ago, as a smoothed midpoint price source.
Syntax
MedianPriceMedianPrice[N] returns the value N bars back, where N is 0 for the current bar, 1 for the previous bar, and so on. MedianPrice and MedianPrice[0] are equivalent.
How it works
MedianPrice is the average of the bar's high and low, (High + Low) / 2. It represents the geometric middle of the bar's trading range and disregards where the bar opened or closed.
The bracket offset addresses earlier bars, so MedianPrice[1] is the previous bar's midpoint. The index must stay within the loaded history.
Because it uses only the high and low, MedianPrice reacts to the extremes of each bar rather than to its settlement. It is a common input for averages and channel calculations where a stable center of the range is preferred over the more variable close. On the live bar it can move as the high or low updates.
Examples
Example 1, Smoothed midpoint average (Indicator)
// Moving average of the bar midpoints
ma = Average[20](MedianPrice)
RETURN MedianPrice AS "Median price", ma AS "MA 20"The indicator plots each bar's midpoint and a moving average built from it.
Example 2, Screening on rising midpoints (ProScreener)
// Current midpoint above its value one bar ago
rising = MedianPrice > MedianPrice[1]
SCREENER[rising] (MedianPrice AS "Median price")The screener returns instruments whose bar midpoint rose from the previous bar.
Example 3, Midpoint trend entry (ProOrder)
DEFPARAM CumulateOrders = false
fast = Average[10](MedianPrice)
slow = Average[30](MedianPrice)
IF fast CROSSES OVER slow THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF fast CROSSES UNDER slow THEN
SELL AT MARKET
ENDIFBoth averages use MedianPrice, so the crossover reflects movement in bar midpoints rather than closes.
Common errors and gotchas
- Ignores open and close.
MedianPricedepends only on the high and low, so two bars with the same range but very different closes share the same value. - Live bar moves. On the current bar the high or low can extend, shifting
MedianPriceuntil the bar completes. - Offset out of range.
MedianPrice[N]fails when N points before the first loaded bar. Guard long lookbacks or load more history.
Related instructions
TypicalPrice, the average of high, low, and close.WeightedClose, a close-weighted average of high, low, and close.TotalPrice, the average of open, high, low, and close.CustomClose, the user-selectable price source.High, the highest price of a bar.Low, the lowest price of a bar.Close, the closing price of a bar.Range, the high minus low of a bar.
