# Measures of Central Tendency - AFL Amibroker

Once every few months, I want to be able to:

1. Get an array of the closing prices for the past 30 days e.g. on 1st July 2024, I want to get the array of the closing prices for June 1 to June 30.
2. Then (nothing complicated), just want a simple array operation (nothing to complex) to get maximum closing price, minimum closing price in the array,, mode (most frequently occurring), and calculate the average closing price for the period (is there an average function like Average in Excel) and median?
I want to display these in the Guru Chart commentary window.

What I have done so far

1. I have seen there is a median function but I dont know how to use it with the array containing the closing price of the specified 30 days.
2. I have looked here AFL Function Reference (amibroker.com) but have not seen any function that gets an array of closing prices for a specified date for processing. I also did not see a simple average function similar to Average function in Microsoft Excel.
3. In the link above the min() and max functions usage isnt clear; I am not sure how to use it in this scenario.

NB: I dont want to use the price/ volume distribution formula as it is not necessary. Just want a basic array operaton to get the measures of central tendency specified above.

I currently export to Excel to do this but I want to do it in Amibroker. In Excel, I select the cell range and use median(), mode() and average(), min() and max() and the job is done but I am working on several symbols and exporting to Excel is not ideal.

Mode is the maximum value of frequency distribution.
First calculate distribution using PriceVolDistribution then calculate maximum.
See:

The other method is to use Sort() and then just count adjacent same values to find which one is most frequent.

As to average close, yes it is basic MA function

YourAverage = MA( Close, 30 );
YourMin = LLV( Close, 30 );
YourMax = HHV( Close, 30 );
YourMedian = Median( Close, 30 );