Skip to content
Open RaamTrade

AveragePrice — Average Price

The four-point bar average: open, high, low and close weighted equally. The last of the four classic price transforms.

Signature

AveragePrice(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 open, high, low and close.

Formula

$$ \text{AP}_t = \frac{O_t + H_t + L_t + C_t}{4} $$

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

Warmup

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

Reading the value

ap.value
ap.value_at(1)

Example

class AveragePriceLine(Strategy):
"""Reference line only — reads the four-point average each bar."""
trade = Symbol()
sizing = FixedCapital()
def execute(self):
ap = AveragePrice(1, on=self.trade)
if self.trade.close > ap.value and self.trade.is_flat:
self.buy(self.trade, reason="Close above bar average")

Notes

  • Standard price transform (TA-Lib AVGPRICE).
  • The same value is what a Heikin-Ashi close would be; the other three transforms skip the open.