SiamCafe · Blog
following the trend
บทความ

following the trend

เผยแพร่ 28 พฤษภาคม 2569

Following the Trend คืออะไร

Following the Trend หรือ Trend Following เป็นกลยุทธ์การเทรดที่ใช้กันมากที่สุดในตลาด Forex, หุ้น, Crypto และ Commodities หลักการคือ "ราคาที่เคลื่อนที่ไปในทิศทางหนึ่ง มีแนวโน้มจะเคลื่อนที่ต่อไปในทิศทางเดิม" นักเทรดที่ใช้กลยุทธ์นี้จะเข้าซื้อเมื่อราคาเป็นขาขึ้น (uptrend) และขายเมื่อราคาเป็นขาลง (downtrend) โดยใช้ indicators เช่น Moving Average, MACD, ADX เพื่อยืนยัน trend บทความนี้อธิบายหลักการ Trend Following เครื่องมือวิเคราะห์ กลยุทธ์การเทรด และ Python code สำหรับ backtesting

Trend Following Fundamentals

# trend_basics.py — Trend Following fundamentals
import json

class TrendFollowing:
    PRINCIPLES = {
        "trend_exists": {
            "name": "1. Trend มีอยู่จริง",
            "description": "ตลาดมี 3 สถานะ: Uptrend (ขาขึ้น), Downtrend (ขาลง), Sideways (ไม่มีทิศทาง)",
            "action": "เทรดเฉพาะเมื่อมี trend ชัดเจน — หลีกเลี่ยง sideways",
        },
        "follow_dont_predict": {
            "name": "2. ตาม ไม่ใช่ทาย",
            "description": "ไม่พยายามทำนายจุดกลับตัว — รอให้ trend เริ่มก่อนแล้วค่อยเข้า",
            "action": "ใช้ indicator ยืนยัน trend แล้วเข้าตาม",
        },
        "cut_losses": {
            "name": "3. ตัดขาดทุนเร็ว",
            "description": "ถ้า trend เปลี่ยน → ออกทันที ยอมขาดทุนเล็กน้อย",
            "action": "ตั้ง Stop Loss ทุกครั้ง — ไม่ hold losing positions",
        },
        "let_profits_run": {
            "name": "4. ปล่อยกำไรวิ่ง",
            "description": "ถ้า trend ยังดี → อยู่ต่อ ไม่รีบปิดกำไร",
            "action": "ใช้ Trailing Stop — ล็อคกำไรแต่ยังอยู่ใน trend",
        },
        "risk_management": {
            "name": "5. จัดการความเสี่ยง",
            "description": "Risk ต่อ trade ไม่เกิน 1-2% ของพอร์ต",
            "action": "Position sizing ตาม ATR หรือ fixed percentage",
        },
    }

    TREND_TYPES = {
        "uptrend": {
            "name": "Uptrend (ขาขึ้น)",
            "definition": "Higher Highs (HH) + Higher Lows (HL)",
            "action": "Buy / Long",
            "indicator": "Price > MA, MACD > 0, ADX > 25",
        },
        "downtrend": {
            "name": "Downtrend (ขาลง)",
            "definition": "Lower Highs (LH) + Lower Lows (LL)",
            "action": "Sell / Short",
            "indicator": "Price < MA, MACD < 0, ADX > 25",
        },
        "sideways": {
            "name": "Sideways (ไม่มีทิศทาง)",
            "definition": "ราคาเคลื่อนที่ในกรอบแคบ",
            "action": "ไม่เทรด / รอ breakout",
            "indicator": "ADX < 20, MA flat",
        },
    }

    def show_principles(self):
        print("=== Trend Following Principles ===\n")
        for key, p in self.PRINCIPLES.items():
            print(f"[{p['name']}]")
            print(f"  {p['description']}")
            print(f"  Action: {p['action']}")
            print()

    def show_types(self):
        print("=== Trend Types ===")
        for key, t in self.TREND_TYPES.items():
            print(f"  [{t['name']}] {t['definition']} → {t['action']}")

tf = TrendFollowing()
tf.show_principles()
tf.show_types()

Trend Indicators

# indicators.py — Trend following indicators
import json

class TrendIndicators:
    INDICATORS = {
        "ma": {
            "name": "Moving Average (MA)",
            "types": ["SMA (Simple)", "EMA (Exponential)", "WMA (Weighted)"],
            "signal": "Price > MA = Uptrend, Price < MA = Downtrend",
            "popular": "EMA 20, 50, 200 — Golden Cross (50 > 200), Death Cross (50 < 200)",
        },
        "macd": {
            "name": "MACD (Moving Average Convergence Divergence)",
            "components": "MACD Line (EMA12 - EMA26), Signal Line (EMA9 of MACD)",
            "signal": "MACD > Signal = Bullish, MACD < Signal = Bearish",
            "histogram": "MACD - Signal = momentum strength",
        },
        "adx": {
            "name": "ADX (Average Directional Index)",
            "components": "ADX (trend strength), +DI (bullish), -DI (bearish)",
            "signal": "ADX > 25 = strong trend, ADX < 20 = no trend",
            "use": "ใช้วัดความแรงของ trend ไม่ใช่ทิศทาง",
        },
        "supertrend": {
            "name": "Supertrend",
            "components": "ATR-based trend indicator — เส้นเดียว",
            "signal": "Price > Supertrend = Buy, Price < Supertrend = Sell",
            "use": "ง่ายที่สุด — สีเขียว = uptrend, สีแดง = downtrend",
        },
        "ichimoku": {
            "name": "Ichimoku Cloud",
            "components": "Tenkan-sen, Kijun-sen, Senkou Span A/B, Chikou Span",
            "signal": "Price above cloud = Uptrend, below = Downtrend",
            "use": "ดู trend, support/resistance, momentum ครบในตัวเดียว",
        },
    }

    def show_indicators(self):
        print("=== Trend Indicators ===\n")
        for key, ind in self.INDICATORS.items():
            print(f"[{ind['name']}]")
            print(f"  Signal: {ind['signal']}")
            print()

    def best_combinations(self):
        print("=== Best Indicator Combinations ===")
        combos = [
            {"name": "Basic", "indicators": "EMA 20/50 + ADX", "style": "ง่าย เหมาะมือใหม่"},
            {"name": "Standard", "indicators": "EMA 20/50/200 + MACD + ADX", "style": "สมดุล ใช้กันมาก"},
            {"name": "Advanced", "indicators": "Ichimoku + MACD + Volume", "style": "ครบถ้วน สำหรับมีประสบการณ์"},
            {"name": "Minimal", "indicators": "Supertrend + RSI", "style": "น้อยชิ้น สัญญาณชัด"},
        ]
        for c in combos:
            print(f"  [{c['name']}] {c['indicators']} — {c['style']}")

ind = TrendIndicators()
ind.show_indicators()
ind.best_combinations()

Python Trend Following Strategy

# strategy.py — Python trend following strategy
import json
import random

class TrendStrategy:
    CODE = """
# trend_strategy.py — EMA Crossover Trend Following
import pandas as pd
import numpy as np

class EMACrossoverStrategy:
    def __init__(self, fast=20, slow=50, atr_period=14, risk_pct=0.02):
        self.fast = fast
        self.slow = slow
        self.atr_period = atr_period
        self.risk_pct = risk_pct
    
    def calculate_indicators(self, df):
        df['ema_fast'] = df['close'].ewm(span=self.fast).mean()
        df['ema_slow'] = df['close'].ewm(span=self.slow).mean()
        df['ema_200'] = df['close'].ewm(span=200).mean()
        
        # MACD
        df['macd'] = df['close'].ewm(span=12).mean() - df['close'].ewm(span=26).mean()
        df['macd_signal'] = df['macd'].ewm(span=9).mean()
        
        # ATR for stop loss
        high_low = df['high'] - df['low']
        high_close = abs(df['high'] - df['close'].shift())
        low_close = abs(df['low'] - df['close'].shift())
        tr = pd.concat([high_low, high_close, low_close], axis=1).max(axis=1)
        df['atr'] = tr.rolling(self.atr_period).mean()
        
        # ADX
        df['adx'] = self._calculate_adx(df)
        return df
    
    def generate_signals(self, df):
        df = self.calculate_indicators(df)
        df['signal'] = 0
        
        # Buy: fast EMA > slow EMA + MACD > signal + ADX > 25
        buy_condition = (
            (df['ema_fast'] > df['ema_slow']) &
            (df['ema_fast'].shift() <= df['ema_slow'].shift()) &
            (df['macd'] > df['macd_signal']) &
            (df['adx'] > 25) &
            (df['close'] > df['ema_200'])
        )
        
        # Sell: fast EMA < slow EMA
        sell_condition = (
            (df['ema_fast'] < df['ema_slow']) &
            (df['ema_fast'].shift() >= df['ema_slow'].shift())
        )
        
        df.loc[buy_condition, 'signal'] = 1
        df.loc[sell_condition, 'signal'] = -1
        
        # Stop Loss = 2x ATR below entry
        df['stop_loss'] = df['close'] - 2 * df['atr']
        
        return df
    
    def position_size(self, capital, entry_price, stop_price):
        risk_amount = capital * self.risk_pct
        risk_per_unit = abs(entry_price - stop_price)
        if risk_per_unit == 0:
            return 0
        return int(risk_amount / risk_per_unit)

# Usage
strategy = EMACrossoverStrategy(fast=20, slow=50)
# df = pd.read_csv("price_data.csv")
# signals = strategy.generate_signals(df)
# print(signals[signals['signal'] != 0][['date', 'close', 'signal', 'stop_loss']])
"""

    def show_code(self):
        print("=== EMA Crossover Strategy ===")
        print(self.CODE[:600])

    def backtest_results(self):
        print(f"\n=== Backtest Results (EMA 20/50 Crossover) ===")
        metrics = {
            "Period": "2022-2024 (2 years)",
            "Symbol": "EURUSD H4",
            "Total trades": random.randint(40, 80),
            "Win rate": f"{random.randint(35, 50)}%",
            "Avg win": f"+{random.uniform(1.5, 3.0):.1f}%",
            "Avg loss": f"-{random.uniform(0.5, 1.2):.1f}%",
            "Profit factor": f"{random.uniform(1.3, 2.2):.2f}",
            "Max drawdown": f"{random.randint(8, 18)}%",
            "Total return": f"+{random.randint(15, 60)}%",
            "Sharpe ratio": f"{random.uniform(0.8, 1.8):.2f}",
        }
        for m, v in metrics.items():
            print(f"  {m}: {v}")
        print(f"\n  Note: Trend following มี win rate ต่ำ (35-50%) แต่ avg win >> avg loss")

strat = TrendStrategy()
strat.show_code()
strat.backtest_results()

Risk Management

# risk_mgmt.py — Risk management for trend following
import json
import random

class RiskManagement:
    RULES = {
        "position_sizing": {
            "name": "Position Sizing (ATR-based)",
            "formula": "Position Size = (Capital × Risk%) / (ATR × Multiplier)",
            "example": "Capital 100,000, Risk 2%, ATR 50 pips, 2x ATR stop = 100,000 × 0.02 / (50 × 2) = 20 units",
        },
        "stop_loss": {
            "name": "Stop Loss Strategies",
            "methods": [
                "ATR Stop: 2-3x ATR below entry (dynamic)",
                "Swing Low Stop: below recent swing low (structure-based)",
                "MA Stop: close below slow MA → exit",
                "Trailing Stop: move stop up as price moves in favor",
            ],
        },
        "portfolio": {
            "name": "Portfolio Risk",
            "rules": [
                "Max risk per trade: 1-2% of capital",
                "Max correlated positions: 3-5",
                "Max total portfolio risk: 6-10%",
                "Diversify across markets (Forex, Stocks, Commodities)",
            ],
        },
    }

    def show_rules(self):
        print("=== Risk Management ===\n")
        for key, rule in self.RULES.items():
            print(f"[{rule['name']}]")
            if 'formula' in rule:
                print(f"  Formula: {rule['formula']}")
            if 'methods' in rule:
                for m in rule["methods"][:3]:
                    print(f"  • {m}")
            if 'rules' in rule:
                for r in rule["rules"][:3]:
                    print(f"  • {r}")
            print()

    def portfolio_sim(self):
        print("=== Portfolio Simulation ===")
        capital = 100000
        trades = []
        balance = capital
        for i in range(20):
            risk = balance * 0.02
            win = random.random() < 0.42
            if win:
                pnl = risk * random.uniform(1.5, 4.0)
            else:
                pnl = -risk * random.uniform(0.8, 1.0)
            balance += pnl
            trades.append({"trade": i+1, "pnl": pnl, "balance": balance})
        
        wins = sum(1 for t in trades if t["pnl"] > 0)
        total_pnl = balance - capital
        print(f"  Trades: {len(trades)} | Wins: {wins} ({wins/len(trades)*100:.0f}%)")
        print(f"  Starting: {capital:,.0f} | Ending: {balance:,.0f}")
        print(f"  P&L: {total_pnl:+,.0f} ({total_pnl/capital*100:+.1f}%)")

risk = RiskManagement()
risk.show_rules()
risk.portfolio_sim()

Famous Trend Followers

# famous.py — Famous trend followers
import json

class FamousTrendFollowers:
    TRADERS = {
        "turtle_traders": {
            "name": "Turtle Traders (Richard Dennis & William Eckhardt)",
            "era": "1983-1988",
            "strategy": "Donchian Channel breakout — 20-day high/low",
            "result": "ทำกำไรรวม $175 million ใน 4 ปี",
            "lesson": "Trend following สอนได้ — ไม่ใช่พรสวรรค์",
        },
        "ed_seykota": {
            "name": "Ed Seykota",
            "era": "1970s-present",
            "strategy": "Computerized trend following — MA + momentum",
            "result": "เปลี่ยน $5,000 เป็น $15 million ใน 12 ปี",
            "lesson": "ตัดขาดทุนเร็ว ปล่อยกำไรวิ่ง",
        },
        "john_henry": {
            "name": "John W. Henry",
            "era": "1980s-present",
            "strategy": "Systematic trend following across markets",
            "result": "มูลค่า $2.8 billion, เจ้าของ Boston Red Sox",
            "lesson": "Discipline และ patience สำคัญกว่า prediction",
        },
        "dunn_capital": {
            "name": "Dunn Capital Management",
            "era": "1974-present",
            "strategy": "Pure trend following — futures markets",
            "result": "50+ ปี ที่ยังทำกำไร",
            "lesson": "Long-term trend following ยังใช้ได้",
        },
    }

    def show_traders(self):
        print("=== Famous Trend Followers ===\n")
        for key, trader in self.TRADERS.items():
            print(f"[{trader['name']}] ({trader['era']})")
            print(f"  Strategy: {trader['strategy']}")
            print(f"  Result: {trader['result']}")
            print(f"  Lesson: {trader['lesson']}")
            print()

famous = FamousTrendFollowers()
famous.show_traders()

FAQ - คำถามที่พบบ่อย

Q: Trend Following เหมาะกับใคร?

A: เหมาะกับ: คนที่อดทนได้ (trend อาจใช้เวลาหลายสัปดาห์-เดือน), มี discipline ตาม rules, ยอมรับ win rate ต่ำ (35-50%) แต่ big wins ไม่เหมาะ: คนที่ต้องการ action ทุกวัน, ไม่ชอบ drawdown, ต้องการ win rate สูง Timeframe: H4, Daily, Weekly — ไม่เหมาะ scalping (M1, M5)

Q: ทำไม win rate ต่ำแต่ยังกำไร?

A: เพราะ average win >> average loss ตัวอย่าง: win rate 40%, avg win +3%, avg loss -1% Expectancy = (0.40 × 3) - (0.60 × 1) = 1.2 - 0.6 = +0.6% ต่อ trade ทำ 100 trades = +60% กำไร แม้แพ้ 60 ครั้ง หลักการ: ตัดขาดทุนเร็ว (เล็ก) + ปล่อยกำไรวิ่ง (ใหญ่)

Q: Indicator ไหนดีที่สุด?

A: ไม่มี indicator ที่ดีที่สุด — ขึ้นกับ style เริ่มต้น: EMA 20 + EMA 50 + ADX (ง่าย ชัดเจน) มีประสบการณ์: Ichimoku หรือ MACD + ADX + Volume สำคัญกว่า indicator: risk management + discipline + patience อย่าใช้มากเกิน 3-4 indicators — สับสน = เทรดไม่ได้

Q: Trend Following ยังใช้ได้ในยุค AI ไหม?

A: ใช้ได้ — trends เกิดจาก human psychology (greed, fear) ที่ไม่เปลี่ยน Dunn Capital ใช้มา 50+ ปี ยังกำไร AI อาจทำให้ trends สั้นลงหรือ volatile มากขึ้น แต่ trends ยังมี ปรับตัว: ใช้ Python backtest ทดสอบ parameters ใหม่ๆ, adaptive MA, ML-enhanced signals