📊 什么是均线?
均线就是”平均价格线”。
比如5日均线,就是过去5天收盘价的平均值。
为什么要均线?
- 📈 股票今天涨跌很正常,但趋势更重要
- 🔍 均线可以帮我们看清趋势方向
👨💻 用Python计算均线
import pandas as pd
# 假设这是最近10天的收盘价
prices = [100, 102, 101, 105, 103, 107, 110, 108, 112, 115]
# 转为pandas列表
df = pd.DataFrame({"收盘": prices})
# 计算5日均线
df["MA5"] = df["收盘"].rolling(window=5).mean()
print(df)
结果:
收盘 MA5 0 100 NaN 1 102 NaN 2 101 NaN 3 105 NaN 4 103 102.2 # (100+102+101+105+103)/5 5 107 103.6 6 110 105.2 7 108 106.6 8 112 108.0 9 115 110.4📈 均线的作用
1. 判断趋势