0
# Price Transform
1
2
Functions that transform OHLC data into standardized price representations for further analysis. These transformations combine multiple price points into single representative values, providing different perspectives on price action.
3
4
## Capabilities
5
6
### Average Price
7
8
Calculates the arithmetic mean of open, high, low, and close prices, providing a balanced representation of price activity.
9
10
```python { .api }
11
def AVGPRICE(open, high, low, close):
12
"""
13
Average Price
14
15
Formula: (open + high + low + close) / 4
16
17
Parameters:
18
- open: array-like, open prices
19
- high: array-like, high prices
20
- low: array-like, low prices
21
- close: array-like, close prices
22
23
Returns:
24
numpy.ndarray: Average price values
25
"""
26
```
27
28
### Median Price
29
30
Calculates the midpoint between high and low prices, representing the middle of the trading range.
31
32
```python { .api }
33
def MEDPRICE(high, low):
34
"""
35
Median Price
36
37
Formula: (high + low) / 2
38
39
Parameters:
40
- high: array-like, high prices
41
- low: array-like, low prices
42
43
Returns:
44
numpy.ndarray: Median price values (midpoint of range)
45
"""
46
```
47
48
### Typical Price
49
50
Calculates the average of high, low, and close prices, giving equal weight to the three key price points.
51
52
```python { .api }
53
def TYPPRICE(high, low, close):
54
"""
55
Typical Price
56
57
Formula: (high + low + close) / 3
58
59
Parameters:
60
- high: array-like, high prices
61
- low: array-like, low prices
62
- close: array-like, close prices
63
64
Returns:
65
numpy.ndarray: Typical price values
66
"""
67
```
68
69
### Weighted Close Price
70
71
Calculates a weighted average emphasizing the close price, which is often considered the most important price of the period.
72
73
```python { .api }
74
def WCLPRICE(high, low, close):
75
"""
76
Weighted Close Price
77
78
Formula: (high + low + 2*close) / 4
79
80
Parameters:
81
- high: array-like, high prices
82
- low: array-like, low prices
83
- close: array-like, close prices
84
85
Returns:
86
numpy.ndarray: Weighted close price values
87
"""
88
```
89
90
## Usage Examples
91
92
```python
93
import talib
94
import numpy as np
95
96
# Sample OHLC data
97
open_prices = np.array([100.0, 101.0, 102.0, 101.5, 103.0])
98
high_prices = np.array([100.8, 102.2, 102.5, 102.0, 103.5])
99
low_prices = np.array([99.2, 100.5, 101.0, 100.8, 102.5])
100
close_prices = np.array([100.5, 101.8, 101.2, 102.2, 103.2])
101
102
# Calculate different price transforms
103
avg_price = talib.AVGPRICE(open_prices, high_prices, low_prices, close_prices)
104
med_price = talib.MEDPRICE(high_prices, low_prices)
105
typ_price = talib.TYPPRICE(high_prices, low_prices, close_prices)
106
wcl_price = talib.WCLPRICE(high_prices, low_prices, close_prices)
107
108
print("Latest prices:")
109
print(f"Average Price: {avg_price[-1]:.2f}")
110
print(f"Median Price: {med_price[-1]:.2f}")
111
print(f"Typical Price: {typ_price[-1]:.2f}")
112
print(f"Weighted Close Price: {wcl_price[-1]:.2f}")
113
114
# These transformed prices are commonly used as:
115
# - Input to other technical indicators instead of close price
116
# - Basis for pivot point calculations
117
# - Representative price for volume-weighted calculations
118
# - Smoothed price series for trend analysis
119
```
120
121
## Common Use Cases
122
123
- **Indicator Input**: Many traders use typical price or weighted close price as input to moving averages and other indicators instead of just close price
124
- **Pivot Points**: Average price and typical price are often used in pivot point calculations
125
- **Volume Analysis**: Typical price is commonly used in volume-weighted price calculations
126
- **Price Smoothing**: These transforms can help reduce noise in price data while preserving important characteristics