OPEN-SOURCE SCRIPT
Telah dikemas kini

[TH] กลยุทธ์ SMC หลายกรอบเวลา (V5.2 - M15 Lead)

427
English Explanation
This Pine Script code implements a multi-timeframe trading strategy based on Smart Money Concepts (SMC). It's designed to identify high-probability trading setups by aligning signals across three different timeframes.

The core logic is as follows:

High Timeframe (HTF) - M15: Determines the overall market direction or bias.

Medium Timeframe (MTF) - M5: Identifies potential Points of Interest (POI), such as Order Blocks or Fair Value Gaps, in alignment with the M15 bias.

Low Timeframe (LTF) - Current Chart: Looks for a specific entry trigger within the M5 POI to execute the trade.

Detailed Breakdown
## Part 1: Inputs & Settings

This section allows you to customize the indicator's parameters:

General Settings:

i_pivotLookback: Sets the lookback period for identifying pivot highs and lows on the LTF, which is crucial for finding the Change of Character (CHoCH).

M15 Bias Settings:

i_m15EmaFast / i_m15EmaSlow: These two EMA (Exponential Moving Average) values on the 15-minute chart determine the main trend. A bullish trend is confirmed when the fast EMA is above the slow EMA, and vice-versa for a bearish trend.

M5 Point of Interest (POI) Settings:

i_showM5Fvg / i_showM5Ob: Toggles the visibility of Fair Value Gaps (FVG) and Order Blocks (OB) on the 5-minute chart. These are the zones where the script will look for trading opportunities.

i_maxPois: Limits the number of POI zones drawn on the chart to keep it clean.

LTF Entry Settings:

i_entryMode:

Confirmation: The script waits for a Change of Character (CHoCH) on the LTF (your current chart) after the price enters an M5 POI. A CHoCH is a break of a recent pivot high (for buys) or pivot low (for sells), suggesting a potential reversal. This is the safer entry method.

Aggressive: The script triggers an entry as soon as the price touches the 50% level of the M5 POI, without waiting for a CHoCH. This is higher risk but can provide a better entry price.

i_showChoch: Toggles the visibility of the CHoCH confirmation lines.

Trade Management Settings:

i_tpRatio: Sets the Risk-to-Reward Ratio (RRR) for the Take Profit target. For example, a value of 2.0 means the Take Profit distance will be twice the Stop Loss distance.

i_slMode: (New in V5.2) Provides four different methods to calculate the Stop Loss:

POI Zone (Default): Places the SL at the outer edge of the M5 POI zone.

Last Swing: Places the SL at the most recent LTF swing high/low before the entry.

ATR: Uses the Average True Range (ATR) indicator to set a volatility-based SL.

Previous Candle: Places the SL at the high or low of the candle immediately preceding the entry. This is the tightest and riskiest option.

i_maxHistory: Sets the number of past trades to display on the chart.

## Part 2: Data Types & Variables

This section defines custom data structures (type) to organize information:

Poi: A structure to hold all information related to a single Point of Interest, including its price boundaries, direction (bullish/bearish), and whether it has been mitigated (touched by price).

Trade: A structure to store details for each trade, such as its entry price, SL, TP, result (Win/Loss/Active), and chart objects for drawing.

## Part 3: Core Logic & Calculations

This is the engine of the indicator:

Data Fetching: It uses request.security to pull EMA data from the M15 timeframe and candle data (high, low, open, close) from the M5 timeframe.

POI Identification: The script constantly scans the M5 data for FVG and OB patterns. When a valid pattern is found that aligns with the M15 bias (e.g., a bullish OB during an M15 uptrend), it's stored as a Poi and drawn on the chart.

Entry Trigger:

It checks if the price on the LTF enters a valid (unmitigated) POI zone.

Based on the selected i_entryMode, it either waits for a CHoCH or enters aggressively.

Once an entry condition is met, it calculates the SL based on the i_slMode, calculates the TP using the i_tpRatio, and creates a new Trade.

Trade Monitoring: For every active trade, the script checks on each new bar if the price has hit the SL or TP level. When it does, the trade's result is updated, and the visual boxes are finalized.

## Part 5: On-Screen Display

This part creates the Performance Dashboard table shown on the top-right of the chart. It provides a real-time summary of:

M15 Bias: Current market direction.

Total Trades: The total number of completed trades from the history.

Win Rate: The percentage of winning trades.

Total R-Multiple: The cumulative Risk-to-Reward multiple (sum of RRR from wins minus losses). A positive value indicates overall profitability.

🇹🇭 คำอธิบายและข้อแนะนำภาษาไทย
สคริปต์นี้เป็น Indicator สำหรับกลยุทธ์การเทรดแบบ Smart Money Concepts (SMC) ที่ใช้การวิเคราะห์จากหลายกรอบเวลา (Multi-Timeframe) เพื่อหาจุดเข้าเทรดที่มีความเป็นไปได้สูง

หลักการทำงานของ Indicator มีดังนี้:

Timeframe ใหญ่ (HTF) - M15: ใช้กำหนดทิศทางหลักของตลาด หรือ "Bias"

Timeframe กลาง (MTF) - M5: ใช้หาโซนสำคัญ หรือ "Point of Interest (POI)" เช่น Order Blocks หรือ Fair Value Gaps ที่สอดคล้องกับทิศทางจาก M15

Timeframe เล็ก (LTF) - กราฟปัจจุบัน: ใช้หาสัญญาณยืนยันเพื่อเข้าเทรดในโซน POI ที่กำหนดไว้

รายละเอียดของโค้ด
## ส่วนที่ 1: การตั้งค่า (Inputs & Settings)

ส่วนนี้ให้คุณปรับแต่งค่าต่างๆ ของ Indicator ได้:

การตั้งค่าทั่วไป:

i_pivotLookback: กำหนดระยะเวลาที่ใช้มองหาจุดกลับตัว (Pivot) ใน Timeframe เล็ก (LTF) เพื่อใช้ยืนยันสัญญาณ Change of Character (CHoCH)

การตั้งค่า M15 (ทิศทางหลัก):

i_m15EmaFast / i_m15EmaSlow: ใช้เส้น EMA 2 เส้นบน Timeframe 15 นาที เพื่อกำหนดเทรนด์หลัก หาก EMA เร็วอยู่เหนือ EMA ช้า จะเป็นเทรนด์ขาขึ้น และในทางกลับกัน

การตั้งค่า M5 (จุดสนใจ - POI):

i_showM5Fvg / i_showM5Ob: เปิด/ปิด การแสดงโซน Fair Value Gaps (FVG) และ Order Blocks (OB) บน Timeframe 5 นาที ซึ่งเป็นโซนที่สคริปต์จะใช้หาโอกาสเข้าเทรด

i_maxPois: จำกัดจำนวนโซน POI ที่จะแสดงผลบนหน้าจอ เพื่อไม่ให้กราฟดูรกเกินไป

การตั้งค่า LTF (การเข้าเทรด):

i_entryMode:

ยืนยัน (Confirmation): เป็นโหมดที่ปลอดภัยกว่า โดยสคริปต์จะรอให้เกิดสัญญาณ Change of Character (CHoCH) ใน Timeframe เล็กก่อน หลังจากที่ราคาเข้ามาในโซน POI แล้ว

เชิงรุก (Aggressive): เป็นโหมดที่เสี่ยงกว่า โดยสคริปต์จะเข้าเทรดทันทีที่ราคาแตะระดับ 50% ของโซน POI โดยไม่รอสัญญาณยืนยัน CHoCH

i_showChoch: เปิด/ปิด การแสดงเส้น CHoCH บนกราฟ

การตั้งค่าการจัดการเทรด:

i_tpRatio: กำหนด อัตราส่วนกำไรต่อความเสี่ยง (Risk-to-Reward Ratio) เพื่อตั้งเป้าหมายทำกำไร (Take Profit) เช่น 2.0 หมายถึงระยะทำกำไรจะเป็น 2 เท่าของระยะตัดขาดทุน

i_slMode: (ฟีเจอร์ใหม่ V5.2) มี 4 รูปแบบในการคำนวณ Stop Loss:

โซน POI (ค่าเริ่มต้น): วาง SL ไว้ที่ขอบนอกสุดของโซน POI

Swing ล่าสุด: วาง SL ไว้ที่จุด Swing High/Low ล่าสุดของ Timeframe เล็ก (LTF) ก่อนเข้าเทรด

ATR: ใช้ค่า ATR (Average True Range) เพื่อกำหนด SL ตามระดับความผันผวนของราคา

แท่งเทียนก่อนหน้า: วาง SL ไว้ที่ราคา High/Low ของแท่งเทียนก่อนหน้าที่จะเข้าเทรด เป็นวิธีที่ SL แคบและเสี่ยงที่สุด

i_maxHistory: กำหนดจำนวนประวัติการเทรดที่จะแสดงย้อนหลังบนกราฟ

## ส่วนที่ 2: ประเภทข้อมูลและตัวแปร

ส่วนนี้เป็นการสร้างโครงสร้างข้อมูล (type) เพื่อจัดเก็บข้อมูลให้เป็นระบบ:

Poi: เก็บข้อมูลของโซน POI แต่ละโซน เช่น กรอบราคาบน-ล่าง, ทิศทาง (ขึ้น/ลง) และสถานะว่าถูกใช้งานไปแล้วหรือยัง (Mitigated)

Trade: เก็บรายละเอียดของแต่ละการเทรด เช่น ราคาเข้า, SL, TP, ผลลัพธ์ (Win/Loss/Active) และอ็อบเจกต์สำหรับวาดกล่องบนกราฟ

## ส่วนที่ 3: ตรรกะหลักและการคำนวณ

เป็นหัวใจสำคัญของ Indicator:

ดึงข้อมูลข้าม Timeframe: ใช้ฟังก์ชัน request.security เพื่อดึงข้อมูล EMA จาก M15 และข้อมูลแท่งเทียนจาก M5 มาใช้งาน

ระบุ POI: สคริปต์จะค้นหา FVG และ OB บน M5 ตลอดเวลา หากเจ้ารูปแบบที่สอดคล้องกับทิศทางหลักจาก M15 (เช่น เจอ Bullish OB ในขณะที่ M15 เป็นขาขึ้น) ก็จะวาดโซนนั้นไว้บนกราฟ

เงื่อนไขการเข้าเทรด:

เมื่อราคาใน Timeframe เล็ก (LTF) วิ่งเข้ามาในโซน POI ที่ยังไม่เคยถูกใช้งาน

สคริปต์จะรอสัญญาณตาม i_entryMode ที่เลือกไว้ (รอ CHoCH หรือเข้าแบบ Aggressive)

เมื่อเงื่อนไขครบ จะคำนวณ SL และ TP จากนั้นจึงบันทึกการเทรดใหม่

ติดตามการเทรด: สำหรับเทรดที่ยัง "Active" อยู่ สคริปต์จะคอยตรวจสอบทุกแท่งเทียนว่าราคาไปถึง SL หรือ TP แล้วหรือยัง เมื่อถึงจุดใดจุดหนึ่ง จะบันทึกผลและสิ้นสุดการวาดกล่องบนกราฟ

## ส่วนที่ 5: การแสดงผลบนหน้าจอ

ส่วนนี้จะสร้างตาราง "Performance Dashboard" ที่มุมขวาบนของกราฟ เพื่อสรุปผลการทำงานแบบ Real-time:

M15 Bias: แสดงทิศทางของตลาดในปัจจุบัน

Total Trades: จำนวนเทรดทั้งหมดที่เกิดขึ้นในประวัติ

Win Rate: อัตราชนะ คิดเป็นเปอร์เซ็นต์

Total R-Multiple: ผลตอบแทนรวมจากความเสี่ยง (R) ทั้งหมด (ผลรวม RRR ของเทรดที่ชนะ ลบด้วยจำนวนเทรดที่แพ้) หากเป็นบวกแสดงว่ามีกำไรโดยรวม

📋 ข้อแนะนำในการใช้งาน
Timeframe ที่เหมาะสม: Indicator นี้ถูกออกแบบมาให้ใช้กับ Timeframe เล็ก (LTF) เช่น M1, M3 หรือ M5 เนื่องจากมันดึงข้อมูลจาก M15 และ M5 มาเป็นหลักการอยู่แล้ว

สไตล์การเทรด:

Confirmation: เหมาะสำหรับผู้ที่ต้องการความปลอดภัยสูง รอการยืนยันก่อนเข้าเทรด อาจจะตกรถบ้าง แต่ลดความเสี่ยงจากการเข้าเทรดเร็วเกินไป

Aggressive: เหมาะสำหรับผู้ที่ยอมรับความเสี่ยงได้สูงขึ้น เพื่อให้ได้ราคาเข้าที่ดีที่สุด

การเลือก Stop Loss:

"Swing ล่าสุด" และ "โซน POI" เป็นวิธีมาตรฐานตามหลัก SMC

"ATR" เหมาะกับตลาดที่มีความผันผวนสูง เพราะ SL จะปรับตามสภาพตลาด

"แท่งเทียนก่อนหน้า" เป็นวิธีที่เสี่ยงที่สุด เหมาะกับการเทรดเร็วและต้องการ RRR สูงๆ แต่ก็มีโอกาสโดน SL ง่ายขึ้น

การบริหารความเสี่ยง: Indicator นี้เป็นเพียง เครื่องมือช่วยวิเคราะห์ ไม่ใช่สัญญาณซื้อขายอัตโนมัติ 100% ผู้ใช้ควรมีความเข้าใจในหลักการของ SMC และทำการบริหารความเสี่ยง (Risk Management) อย่างเคร่งครัดเสมอ

การทดสอบย้อนหลัง (Backtesting): ควรทำการทดสอบ Indicator กับสินทรัพย์และตั้งค่าต่างๆ เพื่อให้เข้าใจลักษณะการทำงานและประสิทธิภาพของมันก่อนนำไปใช้เทรดจริง
Nota Keluaran
credit
Nota Keluaran
change name and photo
Nota Keluaran
name

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.