Skip to content
Open RaamTrade

MedianPrice — Median Price

The midpoint of the bar’s range. The Awesome Oscillator and several Bill Williams tools are defined on it.

Signature

MedianPrice(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Simple-average smoothing window. 1 (the default) returns the raw transform. Bounds 1–200.
on= symbol No Source symbol. Defaults to the trade symbol. Reads high and low.

Formula

$$ \text{MP}_t = \frac{H_t + L_t}{2} $$

With period > 1, the simple average of the last period midpoints.

Warmup

period bars; the lead-in returns the average of the bars seen so far.

Reading the value

mp.value
mp.value_at(1)
mp.crossed_above(other)

Example

class MidpointTrend(Strategy):
"""Long while the close holds above the smoothed bar midpoint."""
smooth = Param(10, min=1, max=200)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
mp = MedianPrice(self.smooth, on=self.trade)
if self.trade.close > mp.value and self.trade.is_flat:
self.buy(self.trade, reason="Close above midpoint")
if self.trade.close < mp.value and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Close below midpoint")

Notes

  • Standard price transform (TA-Lib MEDPRICE).
  • Proven by an assert-via-trade run on SPY daily (matched (H+L)/2 on every bar; zero alarm trades).
  • Ignores the close entirely — a doji and a full-body bar with the same range read identically. TypicalPrice includes the close.