# 8.7. Money Flow Indicators (Chỉ báo dòng tiền)

### 8.7.1. Multi Color Dragon Extended (MCDX)

Chỉ báo **MCDX (Multi Color Dragon Extended)** là một công cụ phân tích kỹ thuật giúp nhà đầu tư nhận diện **dòng tiền tạo lập** và **xu hướng đầu tư** trên thị trường chứng khoán. Chỉ báo này sử dụng các màu sắc khác nhau để phân biệt các nhóm nhà đầu tư: màu đỏ đại diện cho **nhà đầu tư lớn (Banker)**, màu xanh cho **nhà đầu tư nhỏ lẻ (Retailer)** và màu vàng cho **nhà đầu cơ (Hot Money)**. Nhà đầu tư có thể sử dụng MCDX để theo dõi dòng tiền và đưa ra quyết định mua bán cổ phiếu phù hợp.

```python
def mcdx_banker(close: pandas.Series, rsi_base_banker: int = 50, rsi_period_banker: int = 50, rsi_base_hot_money: int = 30, rsi_period_hot_money: int = 40, sensitivity_banker: float = 1.5, sensitivity_hot: float = 0.7, banker_ma: int = 10)
def mcdx_hot_money(close: pandas.Series, rsi_base_banker: int = 50, rsi_period_banker: int = 50, rsi_base_hot_money: int = 30, rsi_period_hot_money: int = 40, sensitivity_banker: float = 1.5, sensitivity_hot: float = 0.7, banker_ma: int = 10)
def mcdx_retail(close: pandas.Series, rsi_base_banker: int = 50, rsi_period_banker: int = 50, rsi_base_hot_money: int = 30, rsi_period_hot_money: int = 40, sensitivity_banker: float = 1.5, sensitivity_hot: float = 0.7, banker_ma: int = 10)
```

**Tham số**

| Tên tham số             | Mô tả                                                                                                                                                                               | Kiểu dữ liệu  | Giá trị mặc định |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------- |
| close                   | Cột chứa giá đóng cửa.                                                                                                                                                              | pandas.Series |                  |
| rsi\_base\_banker       | Mức ngưỡng RSI nền (base) của dòng tiền Banker (smart money). Đại diện cho mức “trung hòa” mà trên đó được coi là dòng tiền lớn đang vào.                                           | int           | 50               |
| rsi\_period\_banker     | Chu kỳ RSI dùng để tính dòng tiền Banker. Chu kỳ dài → đo động lượng dài hạn → phản ánh tích lũy/phân phối dài.                                                                     | int           | 50               |
| rsi\_base\_hot\_money   | Ngưỡng RSI nền cho dòng tiền Hot money (đầu cơ ngắn hạn, lướt sóng). Thấp hơn rsi\_base\_banker vì hot money nhạy hơn, vào sớm, rút sớm.                                            | int           | 30               |
| rsi\_period\_hot\_money | Chu kỳ RSI cho dòng tiền Hot money (ngắn hơn banker). Mặc định = 40 → phản ứng nhanh hơn, phù hợp nhịp trading ngắn hạn.                                                            | int           | 40               |
| sensitivity\_banker     | Hệ số nhạy điều chỉnh độ mạnh của dòng tiền Banker. Càng lớn → đường Banker tăng nhanh khi RSI vượt ngưỡng → dễ thấy khi dòng tiền lớn thật sự vào (thường trong khoảng 1.2 – 1.8). | float         | 1.5              |
| sensitivity\_hot        | Hệ số nhạy cho dòng tiền Hot money. Vì dòng này biến động nhanh, nên hệ số < 1 để tránh nhiễu quá mức (thường từ 0.5 – 0.8).                                                        | float         | 0.7              |
| banker\_ma              | Độ dài trung bình động (Moving Average) để làm mượt đường Banker. Giúp loại bỏ nhiễu ngắn hạn, dễ nhìn xu hướng dòng tiền lớn.                                                      | int           | 10               |

Ví dụ:

```python
fi = client.FiinIndicator()
df["banker"] = fi.mcdx_banker(df["close"], rsi_base_banker=50, rsi_period_banker=50, rsi_base_hot_money=30, rsi_period_hot_money=40, sensitivity_banker=1.5, sensitivity_hot=0.7, banker_ma=10)
df["hotmoney"] = fi.mcdx_hot_money(df["close"], rsi_base_banker=50, rsi_period_banker=50, rsi_base_hot_money=30, rsi_period_hot_money=40, sensitivity_banker=1.5, sensitivity_hot=0.7, banker_ma=10)
df["retail"] = fi.mcdx_retail(df["close"], rsi_base_banker=50, rsi_period_banker=50, rsi_base_hot_money=30, rsi_period_hot_money=40, sensitivity_banker=1.5, sensitivity_hot=0.7, banker_ma=10)
print(df)
```

Biểu đồ trực quan:

<figure><img src="/files/38OKJODSHIHmXft4I7cq" alt=""><figcaption></figcaption></figure>

Source code:

```python
import pandas as pd
import matplotlib.pyplot as plt
import mplfinance as mpf

from FiinQuantX import FiinSession

username = "REPLACE_WITH_YOUR_USERNAME"
password = "REPLACE_WITH_YOUR_PASSWORD"

client = FiinSession(username=username, password=password).login()

df = client.Fetch_Trading_Data(
    realtime=False,
    tickers=["MWG"],
    fields=["open","high","low","close"],
    adjusted=True,
    by="1d",
    from_date="2024-10-23",
    lasted=True
).get_data()

fi = client.FiinIndicator()
df["banker"] = fi.mcdx_banker(df["close"])
df["hotmoney"] = fi.mcdx_hot_money(df["close"])
df["retail"] = fi.mcdx_retail(df["close"])

df['timestamp'] = pd.to_datetime(df['timestamp'])
df.set_index('timestamp', inplace=True)

# --- Vẽ biểu đồ ---
fig = mpf.figure(style='yahoo', figsize=(12, 8))

# Biểu đồ nến (trên)
ax1 = fig.add_subplot(2, 1, 1)
mpf.plot(df, type='candle', ax=ax1)
ax1.set_title('Biểu đồ nến MWG')

# Biểu đồ MCDX (dưới)
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)

# Dùng numeric index để khớp trục với mplfinance
x = range(len(df))

# Bar chart đè nhau
width = 0.5
ax2.bar(x, df['banker'] + df['hotmoney'] + df['retail'], width=width, color='green', label='Retail')
ax2.bar(x, df['banker'] + df['hotmoney'], width=width, color='gold', label='Hot Money')
ax2.bar(x, df['banker'], width=width, color='red', label='Banker')

ax2.set_title('MCDX - Dòng tiền thông minh')
ax2.legend()
ax2.grid(True, linestyle='--', alpha=0.3)

plt.tight_layout()
plt.show()
```

### 8.7.2. Chaikin Money Flow (CMF)

**Chaikin Money Flow (CMF)** là một chỉ báo kỹ thuật đo lường **mức độ dòng tiền chảy vào (buying pressure)** hoặc **chảy ra (selling pressure)** khỏi một cổ phiếu trong một khoảng thời gian nhất định.\
Chỉ báo này kết hợp **vị trí giá đóng cửa trong biên độ dao động giá của phiên** (High–Low range) và **khối lượng giao dịch**, từ đó đánh giá xem dòng tiền “thông minh” đang **tích lũy** hay **phân phối**.

```python
def cmf(high: pd.Series, low: pd.Series, close: pd.Series, volume: pd.Series, window: int = 20) -> pd.Series: ...
```

**Tham số**

| Tên tham số | Mô tả                              | Kiểu dữ liệu  | Giá trị mặc định |
| ----------- | ---------------------------------- | ------------- | ---------------- |
| high        | Cột giá cao nhất.                  | pandas.Series |                  |
| low         | Cột giá thấp nhất.                 | pandas.Series |                  |
| close       | Giá đóng cửa.                      | pandas.Series |                  |
| volume      | Khối lượng khớp lệnh.              | pandas.Series |                  |
| window      | Số phiên tính CMF (rolling window) | int           | 20               |

Ví dụ:

```python
fi = client.FiinIndicator()
df['cmf_20'] = fi.cmf(high=df['high'], low=df['low'], close=df['close'], volume=df['volume'], window=20)
print(df)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fiinquant.vn/ham-va-cong-thuc/8.-danh-sach-chi-so-ta/8.7.-money-flow-indicators-chi-bao-dong-tien.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
