แนวรับแนวต้านหุ้น
แนวรับ Support ระดับราคาที่แรงซื้อหยุดราคาไม่ให้ลง แนวต้าน Resistance ระดับราคาที่แรงขายหยุดราคาไม่ให้ขึ้น
ทะลุแนวรับ แนวรับกลายเป็นแนวต้าน ทะลุแนวต้าน แนวต้านกลายเป็นแนวรับ Role Reversal ยืนยันด้วย Volume
Python คำนวณแนวรับแนวต้าน
# support_resistance.py — คำนวณแนวรับแนวต้าน
import numpy as np
import pandas as pd
def find_support_resistance(prices, window=20, threshold=0.02):
"""หาแนวรับแนวต้านจากข้อมูลราคา"""
levels = []
for i in range(window, len(prices) - window):
# Swing High
if prices[i] == max(prices[i-window:i+window+1]):
levels.append(("resistance", prices[i], i))
# Swing Low
if prices[i] == min(prices[i-window:i+window+1]):
levels.append(("support", prices[i], i))
# รวมระดับที่ใกล้กัน
merged = []
used = set()
for i, (type1, price1, idx1) in enumerate(levels):
if i in used:
continue
group = [price1]
for j, (type2, price2, idx2) in enumerate(levels):
if j != i and j not in used:
if abs(price1 - price2) / price1 < threshold:
group.append(price2)
used.add(j)
used.add(i)
avg_price = np.mean(group)
strength = len(group)
merged.append({
"type": type1,
"price": round(avg_price, 2),
"strength": strength,
"touches": strength,
})
return sorted(merged, key=lambda x: x["price"])
def fibonacci_retracement(high, low, direction="up"):
"""คำนวณ Fibonacci Retracement Levels"""
diff = high - low
fib_levels = {
"0.0%": high if direction == "up" else low,
"23.6%": high - 0.236 * diff if direction == "up" else low + 0.236 * diff,
"38.2%": high - 0.382 * diff if direction == "up" else low + 0.382 * diff,
"50.0%": high - 0.500 * diff if direction == "up" else low + 0.500 * diff,
"61.8%": high - 0.618 * diff if direction == "up" else low + 0.618 * diff,
"78.6%": high - 0.786 * diff if direction == "up" else low + 0.786 * diff,
"100%": low if direction == "up" else high,
}
return fib_levels
def pivot_points(high, low, close):
"""คำนวณ Pivot Points"""
pp = (high + low + close) / 3
r1 = 2 * pp - low
s1 = 2 * pp - high
r2 = pp + (high - low)
s2 = pp - (high - low)
r3 = high + 2 * (pp - low)
s3 = low - 2 * (high - pp)
return {
"R3": round(r3, 2),
"R2": round(r2, 2),
"R1": round(r1, 2),
"PP": round(pp, 2),
"S1": round(s1, 2),
"S2": round(s2, 2),
"S3": round(s3, 2),
}
# ตัวอย่าง
np.random.seed(42)
prices = 100 + np.cumsum(np.random.randn(252) * 1.5)
# หาแนวรับแนวต้าน
levels = find_support_resistance(prices, window=10)
print("Support & Resistance Levels:")
for level in levels[-8:]:
icon = "S" if level["type"] == "support" else "R"
bar = "#" * level["strength"]
print(f" [{icon}] {level['price']:>8.2f} | Touches: {level['touches']} {bar}")
# Fibonacci Retracement
high = max(prices)
low = min(prices)
fib = fibonacci_retracement(high, low, "up")
print(f"\nFibonacci Retracement (High={high:.2f}, Low={low:.2f}):")
for level, price in fib.items():
print(f" {level:>6}: {price:.2f}")
# Pivot Points
pp = pivot_points(prices[-1] + 2, prices[-1] - 3, prices[-1])
print(f"\nPivot Points:")
for name, price in pp.items():
print(f" {name}: {price}")
เทคนิคการใช้แนวรับแนวต้าน
# trading_strategies.py — กลยุทธ์ใช้แนวรับแนวต้าน
from dataclasses import dataclass
from typing import List
@dataclass
class TradingSetup:
name: str
entry: str
stop_loss: str
target: str
risk_reward: str
description: str
class SRStrategies:
"""กลยุทธ์ Support & Resistance"""
def __init__(self):
self.setups: List[TradingSetup] = []
def add(self, setup: TradingSetup):
self.setups.append(setup)
def show_all(self):
print(f"\n{'='*55}")
print(f"Trading Strategies — Support & Resistance")
print(f"{'='*55}")
for setup in self.setups:
print(f"\n [{setup.name}]")
print(f" {setup.description}")
print(f" Entry: {setup.entry}")
print(f" Stop Loss: {setup.stop_loss}")
print(f" Target: {setup.target}")
print(f" R:R = {setup.risk_reward}")
strategies = SRStrategies()
setups = [
TradingSetup(
"Bounce Trade (ซื้อที่แนวรับ)",
"ซื้อเมื่อราคาลงมาแตะแนวรับ + Candlestick Reversal",
"ใต้แนวรับ 1-2%",
"แนวต้านถัดไป",
"1:2 ขึ้นไป",
"รอราคาเด้งจากแนวรับ ยืนยันด้วย Bullish Candle + Volume เพิ่ม",
),
TradingSetup(
"Breakout Trade (ทะลุแนวต้าน)",
"ซื้อเมื่อราคาทะลุแนวต้าน + Volume สูง",
"ใต้แนวต้านเดิม (ที่กลายเป็นแนวรับ)",
"แนวต้านถัดไป หรือ Extension",
"1:2 ขึ้นไป",
"รอราคาทะลุแนวต้าน Close เหนือ + Volume มากกว่าค่าเฉลี่ย",
),
TradingSetup(
"Retest Trade (ทดสอบแนวรับใหม่)",
"ซื้อเมื่อราคากลับมาทดสอบแนวต้านเดิมที่กลายเป็นแนวรับ",
"ใต้แนวรับใหม่",
"High เดิม หรือ Extension",
"1:3 ขึ้นไป",
"หลัง Breakout ราคามักกลับมา Retest แนวต้านเดิม ถ้ายืนได้ = ซื้อ",
),
TradingSetup(
"Range Trade (เทรดในกรอบ)",
"ซื้อที่แนวรับ ขายที่แนวต้าน",
"นอกกรอบ Support/Resistance",
"แนวต้าน (ซื้อ) หรือ แนวรับ (ขาย)",
"1:1.5 ขึ้นไป",
"ใช้เมื่อราคา Sideways ในกรอบ Support-Resistance ชัดเจน",
),
]
for s in setups:
strategies.add(s)
strategies.show_all()
# วิธีหาแนวรับแนวต้าน
methods = {
"Swing High/Low": "จุดกลับตัวของราคาในอดีต ยิ่งแตะหลายครั้งยิ่งแข็ง",
"Round Numbers": "ราคากลมๆ 100, 500, 1000 มีผลทางจิตวิทยา",
"Moving Average": "SMA 50, 200 เป็นแนวรับแนวต้านเคลื่อนที่",
"Fibonacci": "38.2%, 50%, 61.8% จากจุดสูง/ต่ำ",
"Volume Profile": "ราคาที่มี Volume สูง = แนวรับแนวต้านแข็ง",
"Pivot Points": "คำนวณจาก High, Low, Close วันก่อน",
"Trendline": "เส้นแนวโน้มเชื่อมจุด Swing High/Low",
}
print(f"\n\nวิธีหาแนวรับแนวต้าน:")
for method, desc in methods.items():
print(f" {method}: {desc}")
Volume Profile Analysis
# volume_profile.py — Volume Profile Analysis
import numpy as np
def volume_profile(prices, volumes, bins=20):
"""สร้าง Volume Profile"""
price_min = min(prices)
price_max = max(prices)
bin_size = (price_max - price_min) / bins
profile = {}
for i in range(bins):
lower = price_min + i * bin_size
upper = lower + bin_size
mid = (lower + upper) / 2
total_vol = 0
for j in range(len(prices)):
if lower <= prices[j] < upper:
total_vol += volumes[j]
profile[round(mid, 2)] = total_vol
return profile
def find_poc(profile):
"""หา Point of Control (ราคาที่มี Volume สูงสุด)"""
return max(profile, key=profile.get)
def find_value_area(profile, percentage=0.70):
"""หา Value Area (70% ของ Volume)"""
total_vol = sum(profile.values())
target_vol = total_vol * percentage
poc = find_poc(profile)
sorted_prices = sorted(profile.keys())
poc_idx = sorted_prices.index(poc)
included = {poc: profile[poc]}
current_vol = profile[poc]
low_idx = poc_idx - 1
high_idx = poc_idx + 1
while current_vol < target_vol:
low_vol = profile.get(sorted_prices[low_idx], 0) if low_idx >= 0 else 0
high_vol = profile.get(sorted_prices[high_idx], 0) if high_idx < len(sorted_prices) else 0
if low_vol >= high_vol and low_idx >= 0:
included[sorted_prices[low_idx]] = low_vol
current_vol += low_vol
low_idx -= 1
elif high_idx < len(sorted_prices):
included[sorted_prices[high_idx]] = high_vol
current_vol += high_vol
high_idx += 1
else:
break
prices_in_va = sorted(included.keys())
return min(prices_in_va), max(prices_in_va)
# ตัวอย่าง
np.random.seed(42)
prices = 100 + np.cumsum(np.random.randn(252) * 1.5)
volumes = np.random.randint(100000, 500000, 252)
profile = volume_profile(prices, volumes, bins=15)
poc = find_poc(profile)
va_low, va_high = find_value_area(profile)
print("Volume Profile Analysis:")
print(f" Point of Control (POC): {poc:.2f}")
print(f" Value Area Low (VAL): {va_low:.2f}")
print(f" Value Area High (VAH): {va_high:.2f}")
print(f"\n Volume Distribution:")
max_vol = max(profile.values())
for price in sorted(profile.keys(), reverse=True):
vol = profile[price]
bar_len = int(vol / max_vol * 30)
bar = "#" * bar_len
marker = " <-- POC" if price == poc else ""
print(f" {price:>8.2f} | {bar}{marker}")
เคล็ดลับ
- Multiple Touches: แนวรับแนวต้านที่ถูกแตะหลายครั้งจะแข็งแกร่งกว่า
- Volume: ยืนยัน Breakout ด้วย Volume สูงกว่าค่าเฉลี่ย
- Role Reversal: แนวรับที่ถูกทะลุกลายเป็นแนวต้าน และกลับกัน
- Multiple Timeframes: ดูแนวรับแนวต้านจากหลาย Timeframes
- Fibonacci 61.8%: Golden Ratio สำคัญที่สุดสำหรับ Retracement
- Round Numbers: ราคากลมๆ มีผลทางจิตวิทยาการเทรด
การนำความรู้ไปประยุกต์ใช้งานจริง
แหล่งเรียนรู้ที่แนะนำ ได้แก่ Official Documentation ที่อัพเดทล่าสุดเสมอ Online Course จาก Coursera Udemy edX ช่อง YouTube คุณภาพทั้งไทยและอังกฤษ และ Community อย่าง Discord Reddit Stack Overflow ที่ช่วยแลกเปลี่ยนประสบการณ์กับนักพัฒนาทั่วโลก
เปรียบเทียบข้อดีและข้อเสีย
จากตารางเปรียบเทียบจะเห็นว่าข้อดีมีมากกว่าข้อเสียอย่างชัดเจน โดยเฉพาะในแง่ของประสิทธิภาพและความสามารถในการ Scale สำหรับข้อเสียส่วนใหญ่สามารถแก้ไขได้ด้วยการเรียนรู้อย่างเป็นระบบและวางแผนทรัพยากรให้เหมาะสม
สรุปประเด็นสำคัญ
สิ่งที่ควรทำต่อหลังอ่านบทความนี้จบ คือ ลองตั้ง Lab Environment ทดสอบด้วยตัวเอง อ่าน Official Documentation เพิ่มเติม เข้าร่วม Community เช่น Discord หรือ Facebook Group ที่เกี่ยวข้อง และลองทำ Side Project เล็กๆ เพื่อฝึกฝน หากมีคำถามเพิ่มเติม สามารถติดตามเนื้อหาได้ที่ SiamCafe.net ซึ่งอัพเดทบทความใหม่ทุกสัปดาห์
แนวรับ (Support) คืออะไร
ระดับราคาแรงซื้อหยุดราคาไม่ให้ลง ผู้ซื้อเข้ามาซื้อราคาเด้งกลับ ทะลุแนวรับกลายเป็นแนวต้านใหม่ ยืนยันด้วย Volume
แนวต้าน (Resistance) คืออะไร
ระดับราคาแรงขายหยุดราคาไม่ให้ขึ้น ผู้ขายเข้ามาขายราคาร่วง ทะลุแนวต้านกลายเป็นแนวรับใหม่ Role Reversal
วิธีหาแนวรับแนวต้านทำอย่างไร
Swing High Low จุดกลับตัว Round Numbers ราคากลม Moving Averages SMA 50 200 Fibonacci 38.2% 50% 61.8% Volume Profile Pivot Points Trendline
Fibonacci Retracement ใช้อย่างไร
ลากจุดต่ำสุดไปสูงสุด Uptrend ได้ระดับ 23.6% 38.2% 50% 61.8% 78.6% แนวรับแนวต้าน 61.8% Golden Ratio สำคัญที่สุด ร่วมกับ Price Action
สรุป
แนวรับแนวต้านเป็นเครื่องมือสำคัญ Technical Analysis Support แรงซื้อหยุดราคาลง Resistance แรงขายหยุดราคาขึ้น Role Reversal Fibonacci Retracement 61.8% Golden Ratio Volume Profile POC Value Area Python คำนวณอัตโนมัติ ยืนยันด้วย Volume
