Technical Analysis คืออะไรและทำไมต้องอ่านหนังสือ
Technical Analysis คือการวิเคราะห์ราคาหลักทรัพย์โดยใช้ข้อมูลในอดีตเช่น ราคา ปริมาณการซื้อขาย และ chart patterns เพื่อคาดการณ์ทิศทางราคาในอนาคต แตกต่างจาก Fundamental Analysis ที่ดูข้อมูลทางการเงินของบริษัทเช่นงบกำไรขาดทุนและอัตราส่วนทางการเงิน
หลักการพื้นฐานของ Technical Analysis มี 3 ข้อคือ ราคาสะท้อนทุกอย่างแล้ว (price discounts everything) ราคาเคลื่อนที่เป็นแนวโน้ม (price moves in trends) และ ประวัติศาสตร์มักซ้ำรอยเดิม (history tends to repeat itself)
การอ่านหนังสือมีความสำคัญเพราะ Technical Analysis มีทฤษฎีและเครื่องมือจำนวนมากที่ต้องเข้าใจอย่างลึกซึ้ง การดูแค่วิดีโอหรือบทความสั้นๆอาจทำให้เข้าใจผิดหรือใช้เครื่องมือไม่ถูกวิธี หนังสือให้ context ที่ครบถ้วนกว่าและมีตัวอย่างที่ละเอียดกว่า
เครื่องมือหลักของ Technical Analysis ได้แก่ Chart Patterns เช่น Head and Shoulders, Double Top/Bottom, Candlestick Patterns เช่น Doji, Hammer, Engulfing, Indicators เช่น Moving Average, RSI, MACD, Bollinger Bands และ Volume Analysis เช่น OBV, Volume Profile
หนังสือ Technical Analysis ที่ดีที่สุด 10 เล่ม
รายชื่อหนังสือที่แนะนำสำหรับทั้งผู้เริ่มต้นและผู้มีประสบการณ์
# หนังสือ Technical Analysis แนะนำ (เรียงตามระดับ)
#
# === ระดับเริ่มต้น ===
#
# 1. "Technical Analysis of the Financial Markets" — John J. Murphy
# - หนังสือ classic ที่ครอบคลุมที่สุด
# - ครอบคลุม chart patterns, indicators, intermarket analysis
# - เหมาะเป็นเล่มแรกสำหรับทุกู้คืน
# - ISBN: 978-0735200661
#
# 2. "Japanese Candlestick Charting Techniques" — Steve Nison
# - ผู้นำ Candlestick charts มาเผยแพร่ในตะวันตก
# - อธิบาย candlestick patterns ครบทุกรูปแบบ
# - ISBN: 978-0735201811
#
# 3. "Getting Started in Technical Analysis" — Jack Schwager
# - เขียนง่ายเข้าใจง่าย เหมาะสำหรับผู้เริ่มต้น
# - มีตัวอย่างจริงจากตลาด
# - ISBN: 978-0471295426
#
# === ระดับกลาง ===
#
# 4. "Technical Analysis Explained" — Martin Pring
# - ลงลึกเรื่อง momentum indicators และ market cycles
# - อธิบาย intermarket relationships
# - ISBN: 978-0071825177
#
# 5. "Encyclopedia of Chart Patterns" — Thomas Bulkowski
# - รวบรวม chart patterns กว่า 60 รูปแบบ
# - มีสถิติ success rate ของแต่ละ pattern
# - ISBN: 978-1119739685
#
# 6. "Trading for a Living" — Dr. Alexander Elder
# - รวม psychology, trading method, money management
# - เน้นเรื่อง discipline และ risk management
# - ISBN: 978-0471592242
#
# === ระดับสูง ===
#
# 7. "Evidence-Based Technical Analysis" — David Aronson
# - ใช้วิธีทาง statistical สำหรับทดสอบ TA
# - ท้าทาย myths ใน Technical Analysis
# - ISBN: 978-0470008744
#
# 8. "Advances in Financial Machine Learning" — Marcos Lopez de Prado
# - ใช้ ML สำหรับ financial analysis
# - เน้น feature engineering จาก market data
# - ISBN: 978-1119482086
#
# 9. "Quantitative Trading" — Ernest Chan
# - สร้าง automated trading systems
# - backtesting, risk management, execution
# - ISBN: 978-1119800064
#
# 10. "Market Wizards" — Jack Schwager
# - สัมภาษณ์ traders ระดับโลก
# - เรียนรู้จากประสบการณ์จริง
# - ISBN: 978-1118273050
เครื่องมือ Technical Analysis ที่ต้องรู้
สรุปเครื่องมือหลักที่ใช้ใน Technical Analysis พร้อมสูตรคำนวณ
# Technical Indicators สูตรคำนวณ
# 1. Simple Moving Average (SMA)
# SMA(n) = (P1 + P2 + ... + Pn) / n
# ใช้หาแนวโน้มเฉลี่ย เช่น SMA(50), SMA(200)
# 2. Exponential Moving Average (EMA)
# EMA(t) = Price(t) * k + EMA(t-1) * (1-k)
# k = 2 / (n + 1)
# ให้น้ำหนักกับราคาล่าสุดมากกว่า SMA
# 3. RSI (Relative Strength Index)
# RS = Average Gain / Average Loss (over n periods)
# RSI = 100 - (100 / (1 + RS))
# RSI > 70: overbought, RSI < 30: oversold
# 4. MACD (Moving Average Convergence Divergence)
# MACD Line = EMA(12) - EMA(26)
# Signal Line = EMA(9) of MACD Line
# Histogram = MACD Line - Signal Line
# 5. Bollinger Bands
# Middle Band = SMA(20)
# Upper Band = SMA(20) + 2 * StdDev(20)
# Lower Band = SMA(20) - 2 * StdDev(20)
# ราคาอยู่นอก bands = overbought/oversold
# 6. Stochastic Oscillator
# %K = (Close - Low(14)) / (High(14) - Low(14)) * 100
# %D = SMA(3) of %K
# %K > 80: overbought, %K < 20: oversold
# 7. ATR (Average True Range)
# True Range = max(High-Low, |High-PrevClose|, |Low-PrevClose|)
# ATR = SMA(14) of True Range
# ใช้วัด volatility
# 8. Volume Indicators
# OBV (On-Balance Volume):
# ถ้า Close > PrevClose: OBV = PrevOBV + Volume
# ถ้า Close < PrevClose: OBV = PrevOBV - Volume
# ยืนยัน trend ด้วย volume
# 9. Fibonacci Retracement Levels
# Key levels: 23.6%, 38.2%, 50%, 61.8%, 78.6%
# ใช้หา support/resistance levels
สร้างระบบ Technical Analysis ด้วย Python
ใช้ Python คำนวณ Technical Indicators จากข้อมูลราคาจริง
#!/usr/bin/env python3
# technical_analysis.py — คำนวณ Technical Indicators ด้วย Python
import pandas as pd
import numpy as np
import yfinance as yf
def download_data(symbol, period="1y"):
"""ดาวน์โหลดข้อมูลราคาจาก Yahoo Finance"""
df = yf.download(symbol, period=period)
return df
def sma(series, window):
return series.rolling(window=window).mean()
def ema(series, window):
return series.ewm(span=window, adjust=False).mean()
def rsi(series, window=14):
delta = series.diff()
gain = delta.where(delta > 0, 0)
loss = (-delta).where(delta < 0, 0)
avg_gain = gain.rolling(window=window).mean()
avg_loss = loss.rolling(window=window).mean()
rs = avg_gain / avg_loss
return 100 - (100 / (1 + rs))
def macd(series, fast=12, slow=26, signal=9):
ema_fast = ema(series, fast)
ema_slow = ema(series, slow)
macd_line = ema_fast - ema_slow
signal_line = ema(macd_line, signal)
histogram = macd_line - signal_line
return macd_line, signal_line, histogram
def bollinger_bands(series, window=20, num_std=2):
middle = sma(series, window)
std = series.rolling(window=window).std()
upper = middle + num_std * std
lower = middle - num_std * std
return upper, middle, lower
def atr(high, low, close, window=14):
tr1 = high - low
tr2 = abs(high - close.shift())
tr3 = abs(low - close.shift())
tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
return tr.rolling(window=window).mean()
def stochastic(high, low, close, k_window=14, d_window=3):
lowest_low = low.rolling(window=k_window).min()
highest_high = high.rolling(window=k_window).max()
k_pct = ((close - lowest_low) / (highest_high - lowest_low)) * 100
d_pct = k_pct.rolling(window=d_window).mean()
return k_pct, d_pct
def analyze(symbol="AAPL"):
"""วิเคราะห์หุ้นด้วย Technical Indicators"""
df = download_data(symbol)
close = df["Close"]
# คำนวณ indicators
df["SMA_50"] = sma(close, 50)
df["SMA_200"] = sma(close, 200)
df["EMA_20"] = ema(close, 20)
df["RSI_14"] = rsi(close, 14)
df["MACD"], df["MACD_Signal"], df["MACD_Hist"] = macd(close)
df["BB_Upper"], df["BB_Middle"], df["BB_Lower"] = bollinger_bands(close)
df["ATR_14"] = atr(df["High"], df["Low"], close)
df["Stoch_K"], df["Stoch_D"] = stochastic(df["High"], df["Low"], close)
# สรุปสัญญาณ
latest = df.iloc[-1]
print(f"\n=== Technical Analysis: {symbol} ===")
print(f"Price: {latest['Close']:.2f}")
print(f"SMA 50: {latest['SMA_50']:.2f}")
print(f"SMA 200: {latest['SMA_200']:.2f}")
print(f"RSI(14): {latest['RSI_14']:.1f}")
print(f"MACD: {latest['MACD']:.3f}")
print(f"ATR(14): {latest['ATR_14']:.2f}")
# สัญญาณซื้อขาย
signals = []
if latest["Close"] > latest["SMA_50"] > latest["SMA_200"]:
signals.append("BULLISH: Price above SMA 50 & 200 (Golden Cross)")
elif latest["Close"] < latest["SMA_50"] < latest["SMA_200"]:
signals.append("BEARISH: Price below SMA 50 & 200 (Death Cross)")
if latest["RSI_14"] > 70:
signals.append("OVERBOUGHT: RSI above 70")
elif latest["RSI_14"] < 30:
signals.append("OVERSOLD: RSI below 30")
if latest["MACD"] > latest["MACD_Signal"]:
signals.append("BULLISH: MACD above Signal line")
print("\nSignals:")
for s in signals:
print(f" - {s}")
return df
if __name__ == "__main__":
df = analyze("AAPL")
# pip install yfinance pandas numpy
Backtesting Strategy ด้วย Historical Data
สร้าง backtesting framework สำหรับทดสอบ trading strategy
#!/usr/bin/env python3
# backtest.py — Simple Backtesting Framework
import pandas as pd
import numpy as np
import yfinance as yf
class Backtest:
def __init__(self, data, initial_capital=100000):
self.data = data.copy()
self.initial_capital = initial_capital
self.positions = []
self.trades = []
def run_sma_crossover(self, fast=20, slow=50):
"""SMA Crossover Strategy"""
df = self.data
df["SMA_Fast"] = df["Close"].rolling(fast).mean()
df["SMA_Slow"] = df["Close"].rolling(slow).mean()
capital = self.initial_capital
shares = 0
buy_price = 0
for i in range(slow, len(df)):
# Buy signal: fast SMA ตัด slow SMA ขึ้น
if (df["SMA_Fast"].iloc[i] > df["SMA_Slow"].iloc[i] and
df["SMA_Fast"].iloc[i-1] <= df["SMA_Slow"].iloc[i-1] and
shares == 0):
buy_price = df["Close"].iloc[i]
shares = int(capital / buy_price)
capital -= shares * buy_price
self.trades.append({
"date": df.index[i], "action": "BUY",
"price": buy_price, "shares": shares
})
# Sell signal: fast SMA ตัด slow SMA ลง
elif (df["SMA_Fast"].iloc[i] < df["SMA_Slow"].iloc[i] and
df["SMA_Fast"].iloc[i-1] >= df["SMA_Slow"].iloc[i-1] and
shares > 0):
sell_price = df["Close"].iloc[i]
capital += shares * sell_price
pnl = (sell_price - buy_price) * shares
self.trades.append({
"date": df.index[i], "action": "SELL",
"price": sell_price, "shares": shares, "pnl": pnl
})
shares = 0
# ปิดตำแหน่งสุดท้าย
if shares > 0:
capital += shares * df["Close"].iloc[-1]
return self._calculate_stats(capital)
def _calculate_stats(self, final_capital):
total_return = (final_capital - self.initial_capital) / self.initial_capital * 100
winning_trades = [t for t in self.trades if t.get("pnl", 0) > 0]
losing_trades = [t for t in self.trades if t.get("pnl", 0) < 0]
total_trades = len([t for t in self.trades if t["action"] == "SELL"])
stats = {
"initial_capital": self.initial_capital,
"final_capital": round(final_capital, 2),
"total_return_pct": round(total_return, 2),
"total_trades": total_trades,
"winning_trades": len(winning_trades),
"losing_trades": len(losing_trades),
"win_rate": round(len(winning_trades) / max(total_trades, 1) * 100, 1),
}
print("\n=== Backtest Results ===")
for k, v in stats.items():
print(f" {k}: {v}")
print("\nTrades:")
for t in self.trades[-10:]:
pnl = f" P&L: {t['pnl']:.2f}" if "pnl" in t else ""
print(f" {t['date'].strftime('%Y-%m-%d')} {t['action']} {t['shares']}@{t['price']:.2f}{pnl}")
return stats
if __name__ == "__main__":
data = yf.download("AAPL", period="5y")
bt = Backtest(data)
stats = bt.run_sma_crossover(fast=20, slow=50)
สร้าง Dashboard แสดง Technical Indicators
สร้าง interactive dashboard ด้วย Plotly
#!/usr/bin/env python3
# ta_dashboard.py — Technical Analysis Dashboard
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import yfinance as yf
def create_dashboard(symbol="AAPL", period="6mo"):
df = yf.download(symbol, period=period)
# คำนวณ indicators
df["SMA_20"] = df["Close"].rolling(20).mean()
df["SMA_50"] = df["Close"].rolling(50).mean()
df["EMA_12"] = df["Close"].ewm(span=12).mean()
df["EMA_26"] = df["Close"].ewm(span=26).mean()
df["MACD"] = df["EMA_12"] - df["EMA_26"]
df["Signal"] = df["MACD"].ewm(span=9).mean()
df["Histogram"] = df["MACD"] - df["Signal"]
delta = df["Close"].diff()
gain = delta.where(delta > 0, 0).rolling(14).mean()
loss = (-delta).where(delta < 0, 0).rolling(14).mean()
df["RSI"] = 100 - (100 / (1 + gain / loss))
bb_mid = df["Close"].rolling(20).mean()
bb_std = df["Close"].rolling(20).std()
df["BB_Upper"] = bb_mid + 2 * bb_std
df["BB_Lower"] = bb_mid - 2 * bb_std
# สร้าง Dashboard
fig = make_subplots(
rows=4, cols=1, shared_xaxes=True,
vertical_spacing=0.03,
row_heights=[0.5, 0.15, 0.15, 0.2],
subplot_titles=[f"{symbol} Price", "Volume", "RSI", "MACD"]
)
# Candlestick
fig.add_trace(go.Candlestick(
x=df.index, open=df["Open"], high=df["High"],
low=df["Low"], close=df["Close"], name="Price"
), row=1, col=1)
fig.add_trace(go.Scatter(x=df.index, y=df["SMA_20"], name="SMA 20",
line=dict(color="blue", width=1)), row=1, col=1)
fig.add_trace(go.Scatter(x=df.index, y=df["SMA_50"], name="SMA 50",
line=dict(color="orange", width=1)), row=1, col=1)
fig.add_trace(go.Scatter(x=df.index, y=df["BB_Upper"], name="BB Upper",
line=dict(color="gray", width=1, dash="dash")), row=1, col=1)
fig.add_trace(go.Scatter(x=df.index, y=df["BB_Lower"], name="BB Lower",
line=dict(color="gray", width=1, dash="dash"), fill="tonexty"), row=1, col=1)
# Volume
colors = ["green" if c >= o else "red" for c, o in zip(df["Close"], df["Open"])]
fig.add_trace(go.Bar(x=df.index, y=df["Volume"], name="Volume",
marker_color=colors), row=2, col=1)
# RSI
fig.add_trace(go.Scatter(x=df.index, y=df["RSI"], name="RSI",
line=dict(color="purple")), row=3, col=1)
fig.add_hline(y=70, line_dash="dash", line_color="red", row=3, col=1)
fig.add_hline(y=30, line_dash="dash", line_color="green", row=3, col=1)
# MACD
fig.add_trace(go.Scatter(x=df.index, y=df["MACD"], name="MACD",
line=dict(color="blue")), row=4, col=1)
fig.add_trace(go.Scatter(x=df.index, y=df["Signal"], name="Signal",
line=dict(color="orange")), row=4, col=1)
hist_colors = ["green" if v >= 0 else "red" for v in df["Histogram"]]
fig.add_trace(go.Bar(x=df.index, y=df["Histogram"], name="Histogram",
marker_color=hist_colors), row=4, col=1)
fig.update_layout(height=900, title=f"{symbol} Technical Analysis Dashboard",
xaxis_rangeslider_visible=False, showlegend=True)
fig.show()
if __name__ == "__main__":
create_dashboard("AAPL")
# pip install plotly yfinance pandas
FAQ คำถามที่พบบ่อย
Q: Technical Analysis ใช้ได้จริงไหม?
A: มีงานวิจัยทั้งที่สนับสนุนและคัดค้าน TA ใช้ได้ดีสำหรับ identify trends และ support/resistance levels แต่ไม่ใช่ crystal ball ที่ทำนายราคาได้ 100% ควรใช้ร่วมกับ risk management และ money management ที่ดี traders ที่ประสบความสำเร็จมักใช้ TA เป็นเพียงส่วนหนึ่งของ trading system ทั้งหมด
Q: ควรเริ่มอ่านเล่มไหนัก่อน?
A: เริ่มที่ Technical Analysis of the Financial Markets ของ John Murphy เพราะครอบคลุมทุกหัวข้อตั้งแต่พื้นฐานจนถึงขั้นสูง ตามด้วย Japanese Candlestick Charting Techniques ของ Steve Nison สำหรับเรียนรู้ candlestick patterns และ Trading for a Living ของ Alexander Elder สำหรับเรื่อง psychology และ money management
Q: RSI กับ Stochastic ต่างกันอย่างไร?
A: RSI วัดความเร็วและขนาดของการเปลี่ยนแปลงราคา (momentum) ส่วน Stochastic วัดตำแหน่งของราคาปิดเทียบกับช่วงราคาในอดีต RSI ตอบสนองช้ากว่าเหมาะสำหรับ trending market ส่วน Stochastic ตอบสนองเร็วกว่าเหมาะสำหรับ ranging market ใช้ทั้งสองตัวร่วมกันจะได้สัญญาณที่น่าเชื่อถือกว่า
Q: Python Library ที่ดีที่สุดสำหรับ Technical Analysis คืออะไร?
A: TA-Lib เป็น library ที่ครบที่สุดมี indicators กว่า 150 ตัว แต่ติดตั้งยากบน Windows ทางเลือกคือ pandas-ta ที่ใช้ง่ายกว่าและรองรับ indicators มากกว่า 130 ตัว สำหรับ backtesting แนะนำ Backtrader หรือ Zipline สำหรับ visualization ใช้ mplfinance หรือ Plotly
Q: Backtesting มีข้อจำกัดอะไรบ้าง?
A: Backtesting มีข้อจำกัดหลายอย่างเช่น Survivorship Bias ที่ใช้เฉพาะหุ้นที่ยังอยู่ในตลาด, Look-Ahead Bias ที่ใช้ข้อมูลในอนาคตโดยไม่ตั้งใจ, Overfitting ที่ optimize strategy ให้เข้ากับข้อมูลอดีตมากเกินไป และ Slippage/Commission ที่ไม่ได้คิดค่าใช้จ่ายในการซื้อขายจริง ผลลัพธ์จาก backtesting จึงไม่ guarantee ผลลัพธ์ในอนาคต
