OPEN-SOURCE SCRIPT
Güncellendi

BackToBasic XEMA

216
บทความอธิบายสคริปต์ “BackToBasic XEMA”
ภาษาไทย
แนวคิดโดยย่อ
BackToBasic XEMA เกิดจากแนวคิด “กลับสู่พื้นฐานแต่เพิ่มประโยชน์” โดยใช้สัญญาณ EMA Crossover เป็นแกนหลัก แล้วต่อยอดด้วยการแสดงกำไร/ขาดทุนจริง (PnL) และเส้น Trailing Stop แนวนอน เพื่อช่วยวัดประสิทธิภาพและป้องกันการคืนกำไร

กลไกการทำงาน

Dual EMA – คำนวณ EMA สองเส้น (Fast และ Slow)

Crossover Signal – ออกสัญญาณ Buy เมื่อ Fast ตัดขึ้น Slow และ Sell เมื่อ Fast ตัดลง Slow

PnL Lines & Labels – เมื่อทิศทางกลับตัว ระบบจะคำนวณส่วนต่างราคา × จำนวน Contracts แล้ววาดเส้นเชื่อมจุดเข้า–ออก พร้อมป้ายกำไร/ขาดทุนสีเขียว / แดง

Horizontal Trailing Stop – เมื่อราคาวิ่งไปทางกำไรเกิน trailStartPips ระบบจะสร้างเส้น Trail ห่างจาก EMA อ้างอิงด้วย trailBufferPips และเลื่อนเฉพาะในทางที่ล็อกกำไร

การตั้งค่าใช้งาน (สรุปเป็นคำอธิบาย)

ปรับค่า Fast/Slow EMA ให้สัมพันธ์กับกรอบเวลาและความผันผวนของสินทรัพย์

กรอกจำนวน Contracts ตามขนาดโพซิชันจริงเพื่อให้ค่า PnL สมจริง

ค่า Trail เริ่มต้นเหมาะกับกราฟ 1 ชั่วโมงขึ้นไป หากเทรดสั้นอาจลด trailStartPips และ trailBufferPips

แนะนำใช้กับสินทรัพย์สภาพคล่องสูง (คู่เงินหลัก, XAUUSD, ดัชนี) และทดสอบบนบัญชีเดโมก่อนเสมอ

จุดเด่นเมื่อเทียบกับ EMA Crossover พื้นฐาน

เห็นผลกำไร/ขาดทุนของแต่ละการเทรดทันที ไม่ต้องคำนวณย้อนหลัง

มีเส้น Trailing Stop แนวนอนช่วยล็อกกำไรและจำกัดขาดทุน

เปิด–ปิดฟังก์ชัน PnL และ Trailing ได้จากหน้าตั้งค่า ไม่ยุ่งยาก

ข้อจำกัดและคำเตือน

ไม่เหมาะกับกราฟแบบ Heikin Ashi หรือ Renko เพราะอาจเกิด repaint

PnL คำนวณจากส่วนต่างราคาเท่านั้น ไม่รวมค่าคอมมิชชันหรือสลิปเพจ

ผลลัพธ์ในอดีตไม่รับประกันอนาคต ควรจัดการความเสี่ยงและทดลองก่อนใช้งานจริง

ลิขสิทธิ์
สคริปต์นี้พัฒนาใหม่ทั้งหมดโดย <CJSuperTrader>, © 2025

English
Concept
BackToBasic XEMA extends a classic EMA-crossover setup with real-time profit-and-loss tracking and a horizontal trailing-stop line, giving traders both clear entry/exit signals and built-in risk management.

How It Works

Dual EMAs – Calculates Fast and Slow EMAs.

Crossover Signals – Generates a Buy when the Fast EMA crosses above the Slow EMA, and a Sell when it crosses below.

PnL Lines & Labels – On every direction flip the script computes price difference × contracts, draws a line from entry to exit, and labels the result in green (profit) or red (loss).

Horizontal Trailing Stop – After price moves in profit by at least trailStartPips, a trail line is placed trailBufferPips away from the chosen EMA and moves only in the trade’s favour.

Practical Settings (plain-language guide)

Adjust Fast/Slow EMA lengths to suit your timeframe and the instrument’s volatility.

Enter your position size in Contracts so PnL lines reflect real cash values.

For shorter timeframes, lower trailStartPips and trailBufferPips; for swing trading, larger values work better.

Best used on 1-hour-and-above charts of liquid symbols (major FX pairs, gold, indices). Forward-test on demo first.

Advantages over a Basic EMA Cross

Instant visual feedback on each trade’s profit or loss.

Built-in horizontal trailing stop to lock in gains and limit downside.

Modular design – PnL and trailing features can be toggled on or off in the input panel.

Limitations & Disclaimer

Not repaint-safe on non-standard chart types such as Heikin Ashi or Renko.

PnL lines show raw price change only; commissions and slippage are not included.

Past performance does not guarantee future results – trade responsibly and test thoroughly.

License
Original Pine Script by <CJSuperTrader>, © 2025
Sürüm Notları
คำอธิบายสคริปต์ฉบับปรับปรุง (ไทย)

สคริปต์ฉบับใหม่นี้ต่อยอดจาก “BackToBasic XEMA” โดยเราได้เพิ่มจุดเด่นและปรับปรุงให้ดูง่ายขึ้น รวมทั้งขยายข้อมูลสถิติบนกราฟให้ครบถ้วนมากขึ้น:

1. เลือกกรองสัญญาณซื้อ–ขายได้
-เพิ่มเมนู “Signal Mode” ให้เลือกได้ 3 ทาง คือ ทั้งสองฝั่ง (Both), เฉพาะซื้อ (Buy Only) หรือเฉพาะขาย (Sell Only)
-เมื่อเราเลือกแล้ว สคริปต์จะบันทึกและแสดงข้อมูลเฉพาะสัญญาณที่ต้องการเท่านั้น

2. ตารางสถิติขยายเป็น 10 แถว
-จำนวนการเทรดทั้งหมด (Total Trades)
-จำนวนสัญญาณซื้อ (Buy Count)
-จำนวนสัญญาณขาย (Sell Count)
-จำนวนการเทรดที่ได้กำไร (Win Count)
-จำนวนการเทรดที่ขาดทุน (Loss Count)
-เปอร์เซ็นต์ชนะ (Win Rate)
-กำไรสูงสุดต่อเทรด (Max Profit)
-ขาดทุนสูงสุดต่อเทรด (Max Loss)
-Total Profit Buy – รวมกำไรจากฝั่งซื้อทุกเทรด
-Total Profit Sell – รวมกำไรจากฝั่งขายทุกเทรด

3. ปรับสีตารางให้สวยงามเลือกเองได้
-มีตัวเลือกสีเดียว (Stats Table Text Color) สำหรับข้อความ, ขอบ และกรอบตารางทั้งหมด
-ช่วยให้ปรับธีมกราฟให้เข้ากับสไตล์ส่วนตัวได้ง่าย

4. แสดงตัวเลขอย่างเดียว ชัดเจน
-ตัวเลขกำไร/ขาดทุนใช้ฟอร์แมต “#.00”
-ตัดสัญลักษณ์หรือคำว่า “$” ออก เหลือเพียงตัวเลข 2 ตำแหน่งทศนิยม เพื่อความเรียบร้อย

5. วิธีทำงานโดยสังเขป
-คำนวณ EMA สองเส้น (Fast & Slow) แล้วหาจุดที่เส้น EMA ตัดกัน
-เมื่อเกิดสัญญาณซื้อหรือขาย จะเปลี่ยนสถานะการเข้าเทรด (entry) และบันทึกราคาต้นทาง
-เมื่อเกิดสัญญาณกลับทิศ หรือเจอสัญญาณตรงข้าม จะคิดกำไร/ขาดทุนระหว่างราคาเข้ากับราคาปิด แล้ว:
-แสดงเส้นและตัวเลขกำไร/ขาดทุนบนกราฟ
-อัปเดตสถิติทั้งตาราง (นับจำนวน แยก Win/Loss รวมกำไรแยกฝั่ง)
-ถ้าเปิดใช้ Trailing Stop เมื่อราคาเคลื่อนตัวได้ถึงระดับที่กำหนด ระบบจะวาดเส้นหยุดตาม EMA ให้อัตโนมัติ
-สรุปผลท้ายบาร์สุดท้าย สร้างตารางสถิติเพื่อให้ดูภาพรวมการเทรดทั้งหมดในหน้าเดียว

What’s New & How It Works (English)

This updated version builds on the original “BackToBasic XEMA (Final)” indicator by adding user-friendly filters, richer statistics, and cleaner visuals:

1. Signal Mode Filter
-New “Signal Mode” dropdown: choose Both, Buy Only, or Sell Only
-Only the selected trade direction will be recorded and displayed

2. Expanded 10-Row Stats Table
-Total Trades
-Buy Count
-Sell Count
-Win Count
-Loss Count
-Win Rate (%)
-Max Profit (per trade)
-Max Loss (per trade)
-Total Profit Buy – cumulative profit from all long trades
-Total Profit Sell – cumulative profit from all short trades

3. Unified & Customizable Table Color
-Single color input (Stats Table Text Color) for text, border, and frame
-Easily match the table theme to your chart style

4. Clean Numeric Display
-Profit/loss values formatted as “#.00” (two decimal places only)
-No dollar signs or extra text, keeping the table tidy

5. How It Works in Brief
-Compute two EMAs (Fast & Slow) and detect their crossovers
-On each buy/sell signal:
-Record the entry price and bar index
-On the next opposite signal or when closing a trade:
-Calculate PnL = (exit price – entry price) × contracts
-Draw a line and label showing the PnL on the chart
-Update all table statistics (counts, wins/losses, and cumulative profits per side)
-Trailing Stop (if enabled): after price moves beyond a threshold, a horizontal stop line follows the EMA
-At the last bar: render the 10-row stats table for full visibility of your trading performance

Sürüm Notları
English
1.Different Default EMA Settings
-Enhanced: Fast EMA = 50 periods, Slow EMA = 100 periods
-Base: Fast EMA = 3 periods, Slow EMA = 30 periods

2.Simplified PnL Color Controls
-Enhanced: Single color input applies to both the PnL line and its label background
-Base: Separate inputs for line color and label background color

3.More Table Styling Options
-Enhanced: You can choose table background color and border color freely
-Base: You can only change the text color

4.Table Layout Differences
-Enhanced: Two-column layout showing paired metrics side by side
-Base: Single-column layout listing each metric on its own row

Sürüm Notları
Version
-First script uses //version=6
-Second uses //version=5

Time-filter
-v6 counts all trades
-v5 can limit stats to YTD, QTD, MTD, WTD, or All

Stats table rows
-v6 shows 5 rows (no period label)
-v5 shows 6 rows, with the top row naming the Stats Period

Label-size helper
-v6 has one function getLabelSize()
-v5 uses inline ?: expressions each time

line.new style
-v6 passes parameters positionally
-v5 uses named arguments (e.g. xloc=xloc.bar_index)

Minor naming
-v6 calls the PnL color input "PnL Profit"
-v5 calls it "PnL Profit Color"
Sürüm Notları
We’ve added two powerful upgrades that make BackToBasic XEMA even more informative:

First, the script now continuously calculates your open position’s unrealized profit or loss in “points” (where one point equals one dollar) and tags it with a clear “B” for buy or “S” for sell. This floating PnL is updated on every bar, giving you an immediate read on whether your trade is gaining or losing, without waiting for an exit signal.

Second, we’ve extended the very top row of the stats table to include a new “Unrealized” column. Placing this real-time PnL right alongside your chosen period, total trades, and win rate keeps all essential metrics aligned in one glance. Now, as soon as you glance at the stats panel, you see not only how many trades you’ve taken and your overall performance, but also exactly where your current open trade stands.

Together, these enhancements transform the indicator from a simple crossover tool into a compact trading dashboard. You get instant visibility into both closed‐trade results and live PnL, all neatly organized in a single panel—helping you make faster, more informed decisions without cluttering your chart.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.