Typical Price (TP)
The Typical Price (TP) is a simple statistical measure that calculates the arithmetic average of the high, low, and closing prices for a given period. Its purpose is to provide a single, more representative price point for that period, rather than relying solely on the closing price. This value is not typically used as a standalone indicator but serves as a foundational building block for more complex indicators, most notably the Money Flow Index (MFI), which uses Typical Price to calculate raw money flow.
TP
=TP(data) Example Usage
=TP(A2:F500)
Parameters
| Parameter | Type | Description | Status |
|---|---|---|---|
data | Range | Range of columns containing the date, Open, high, Low, close, volume data. | Required |
Returns
A two-column array of dates and their corresponding TP values.
Source Code
Copy the following code into your Apps Script editor (Extensions > Apps Script) to use the TP function in your spreadsheet.
tp.js
/**
* Calculates the Typical Price (TP) for a given dataset.
* Typical Price is the average of High, Low, and Close prices: (H + L + C) / 3.
*
* @param {array} data - The input range. Must include at least 5 columns: Date, Open, High, Low, Close.
* @returns {array} A two-column array with headers "Date" and "TP".
* @customfunction
*/
function TP(data) {
const processedData = getData(data);
// --- NEW: Function-level validation ---
// After getting the data, check if it has the required structure for this specific function.
const columnCount = processedData[0].length;
if (columnCount < 5) {
throw new Error(`Invalid input for TP. The Typical Price calculation requires at least 5 columns (Date, Open, High, Low, Close), but the input data only has ${columnCount}.`);
}
// --- END of validation ---
const dates = processedData.slice(1).map(row => row[0]); // Extract dates
const highs = processedData.slice(1).map(row => row[2]); // Extract high prices
const lows = processedData.slice(1).map(row => row[3]); // Extract low prices
const closes = processedData.slice(1).map(row => row[4]); // Extract close prices
// Initialize an array for TP values with headers
const tpValues = [["Date", "TP"]];
// Calculate TP for each row
for (let i = 0; i < closes.length; i++) {
const typicalPrice = (highs[i] + lows[i] + closes[i]) / 3;
tpValues.push([dates[i], typicalPrice]);
}
return tpValues;
}