Hi boatman. MaxVal is actually a good example of the answer to your basic question. The 2nd of it's parameters is a single value - the length of the lookback, d. The 1st parameter is the values to be searched through for the MaxVal - i.e., a pointer to that list of values, with at least d entries in the list. When you code AO(median_price), you're passing a single value, same as when you pass d.
One solution is to create a series at least d long to store your AO values, and pass that series as the 1st parameter.
HTH.