OPEN-SOURCE SCRIPT
ที่อัปเดต: DCA Performance Backtester [Multi-Mode]

DCA Performance Backtester [Multi-Mode]
WHAT IT DOES
This indicator backtests Dollar-Cost Averaging (DCA) accumulation strategies on any symbol and shows the full result on the chart: an on-chart summary table, entry markers, average-cost line, real dividend (ex-date) tracking, a dividend-yield value zone, and a fair comparison against Lump Sum investing. It is accumulate-only (HODL) — no selling logic.
BUY MODES (can be combined)
1. Time-Based DCA — buy a fixed amount every Day / Week / Month. You can pick the weekday (weekly), the day of month (monthly, e.g. payday), or the hour (daily on intraday charts). If the market is closed on the target day, it buys the next trading day.
2. Buy the Dip — buy when price drops X% (default 12%) from the highest close of the last N bars (default 20). A cooldown (default 14 bars) spaces out repeat buys while the condition persists. Optional RSI settings:
• Filter mode — only buy when RSI is below the threshold (default 30).
• Hybrid mode — buy a normal unit on every qualifying dip (blue "D" label) AND an extra special unit when RSI is also below the threshold (red "fire" label), each stream with its own cooldown. The special unit size is adjustable via a multiplier.
3. Martingale-style averaging — first unit at a fixed size, then buy a larger unit (configurable multiplier) each time price falls another X% from the last entry, with a max-steps cap and optional reset when price recovers above average cost.
DIVIDENDS (REAL EX-DATE DATA)
Uses the symbol's actual dividend history. On each ex-date the script credits dividend × units held. Choose Gross or Net; where an exchange only provides gross figures (e.g. SET), Net is estimated as Gross × (1 − withholding tax %). Each ex-date is marked on the price chart with its per-round yield ("XD 2.35%" = dividend per share ÷ close of that day).
DIVIDEND-YIELD VALUE ZONE
Highlights price areas where the annual dividend yield at that price exceeds your threshold (default 8%/year) — useful for income-focused accumulation. Two calculation modes: trailing 12 months (TTM) or last completed calendar year. An outlier filter (default 2.5× median) excludes one-off special dividends so they do not inflate the yield. A reference line shows the exact price where yield equals the threshold.
SUMMARY TABLE
Buy count (normal vs RSI-passed dips), invested capital, units held, average cost, current portfolio value, P/L, ex-date count, total dividends received, dividends as % of invested capital, current TTM yield, DCA total return (incl. dividends), and a Lump Sum comparison computed from the same invested amount at the start date — including dividends on the Lump Sum side for a fair comparison.
ALERTS
Every buy signal fires alert() with a JSON payload (symbol, mode, price, amount, drawdown from high, RSI, and whether the RSI condition passed) — ready for webhooks. Create an alert with "Any alert() function call". Alerts fire on bar close for signals that occur after the alert is created; historical backtest markers do not fire.
HOW TO USE
Recommended on daily charts. Enable one or more buy modes, set your budget and date range, and read the "DCA beats/loses Lump Sum" row to judge whether systematic dip-buying suits the symbol. Typical tuning: calmer stocks work with smaller dip thresholds (5–7%), volatile ones with larger (12–15%).
METHOD & LIMITATIONS
Simulation buys at bar close (no intrabar fills). Accounting is computed by the script itself (indicator, not a strategy — no Strategy Tester tab). Commission % per purchase is included in cost basis. Dividend data depends on TradingView's database and may be incomplete for some markets or older periods. Past performance does not guarantee future results. Educational tool — not investment advice.
═══════════════════════════════════════════════
DCA Performance Backtester [Multi-Mode]
เครื่องมือทดสอบย้อนหลัง (backtest) กลยุทธ์สะสมหุ้นแบบ DCA กับสินทรัพย์ใดก็ได้ แสดงผลครบบนชาร์ต: ตารางสรุป, จุดซื้อ, เส้นต้นทุนเฉลี่ย, เงินปันผลจากวัน XD จริง, โซนราคาที่ปันผลคุ้ม และการเทียบกับ Lump Sum อย่างยุติธรรม — เป็นแบบซื้อสะสมอย่างเดียว (HODL) ไม่มีการขาย
โหมดการซื้อ (เปิดพร้อมกันได้)
1) DCA ตามรอบเวลา — รายวัน/รายสัปดาห์/รายเดือน เลือกวันและเวลาซื้อได้ ตลาดปิดวันเป้าหมายจะเลื่อนให้อัตโนมัติ
2) Buy the Dip — ซื้อเมื่อราคาย่อจาก High ตาม % ที่ตั้ง (ค่าเริ่มต้น 12% จากกรอบ 20 แท่ง เว้นซื้อซ้ำ 14 แท่ง) พร้อมตัวเลือก RSI สองแบบ: กรองอย่างเดียว หรือโหมดผสม — ไม้ปกติทุกครั้งที่ย่อ (ป้าย D สีฟ้า) + ไม้พิเศษเมื่อ RSI ต่ำกว่าเกณฑ์ด้วย (ป้ายไฟสีแดง) แยก cooldown สองสาย ปรับตัวคูณไม้พิเศษได้
3) ถัวเฉลี่ยขาลงแบบ Martingale — ไม้ใหญ่ขึ้นตามตัวคูณเมื่อราคาลงต่อ มีเพดานจำนวนไม้และรีเซ็ตเมื่อราคาฟื้น
เงินปันผล — ใช้ประวัติ XD จริงของสินทรัพย์ คิดจากจำนวนหน่วยที่ถือ ณ วัน XD เลือก Gross/Net ได้ (ตลาดที่มีแต่ Gross เช่น SET จะคำนวณ Net จากภาษีหัก ณ ที่จ่ายให้) จุด XD บนชาร์ตแสดง % ปันผลของงวดนั้นเทียบราคาวันนั้น
โซนปันผลคุ้ม — ไฮไลท์พื้นหลังช่วงราคาที่ yield ต่อปีสูงกว่าเกณฑ์ (ค่าเริ่มต้น 8%) เลือกวิธีคิดได้ทั้ง TTM 12 เดือน หรือปีปฏิทินล่าสุด พร้อมตัวกรองตัดปันผลพิเศษที่ทำให้ yield โป่งเกินจริง และเส้นบอกราคาที่ yield เท่าเกณฑ์พอดี
ตารางสรุป — จำนวนไม้ (แยกไม้ปกติ/ผ่าน RSI), เงินต้น, หน่วยที่ถือ, ต้นทุนเฉลี่ย, มูลค่าพอร์ต, กำไร/ขาดทุน, จำนวนครั้ง XD, ปันผลรวมและคิดเป็น % ของเงินต้น, yield ปัจจุบัน, ผลตอบแทนรวมปันผล และบรรทัดตัดสิน DCA ชนะ/แพ้ Lump Sum
Alert — ทุกสัญญาณซื้อยิง alert() เป็น JSON (สัญลักษณ์ โหมด ราคา จำนวนเงิน % ย่อ RSI และสถานะผ่าน RSI) พร้อมต่อ webhook ตั้งด้วย "Any alert() function call" — ยิงเฉพาะสัญญาณที่เกิดหลังตั้ง alert ที่ราคาปิดแท่ง
ข้อจำกัด — จำลองซื้อที่ราคาปิดแท่ง เป็น indicator จึงไม่มีแท็บ Strategy Tester ข้อมูลปันผลอิงฐานข้อมูล TradingView ผลในอดีตไม่ยืนยันอนาคต จัดทำเพื่อการศึกษา ไม่ใช่คำแนะนำการลงทุน
Release Note
WHAT IT DOESThis indicator backtests Dollar-Cost Averaging (DCA) accumulation strategies on any symbol and shows the full result on the chart: an on-chart summary table, entry markers, average-cost line, real dividend (ex-date) tracking, a dividend-yield value zone, and a fair comparison against Lump Sum investing. It is accumulate-only (HODL) — no selling logic.
BUY MODES (can be combined)
- Time-Based DCA — buy a fixed amount every Day / Week / Month. You can pick the weekday (weekly), the day of month (monthly, e.g. payday), or the hour (daily on intraday charts). If the market is closed on the target day, it buys the next trading day.
- Buy the Dip — buy when price drops X% (default 12%) from the highest close of the last N bars (default 20). A cooldown (default 14 bars) spaces out repeat buys while the condition persists. Optional RSI settings: Filter mode — only buy when RSI is below the threshold (default 30) · Hybrid mode — buy a normal unit on every qualifying dip (blue "D" label) and an extra special unit when RSI is also below the threshold (red "fire" label), each stream with its own cooldown; the special unit size is adjustable via a multiplier.
- Martingale-style averaging — first unit at a fixed size, then buy a larger unit (configurable multiplier) each time price falls another X% from the last entry, with a max-steps cap and optional reset when price recovers above average cost.
DIVIDENDS (REAL EX-DATE DATA)
Uses the symbol's actual dividend history. On each ex-date the script credits dividend × units held. Choose Gross or Net; where an exchange only provides gross figures (e.g. SET), Net is estimated as Gross × (1 − withholding tax %). Each ex-date is marked on the price chart with its per-round yield ("XD 2.35%" = dividend per share ÷ close of that day).
DIVIDEND-YIELD VALUE ZONE
Highlights price areas where the annual dividend yield at that price exceeds your threshold (default 8%/year) — useful for income-focused accumulation. Two calculation modes: trailing 12 months (TTM) or last completed calendar year. An outlier filter (default 2.5× median) excludes one-off special dividends so they do not inflate the yield. A reference line shows the exact price where yield equals the threshold.
SUMMARY TABLE
Buy count (normal vs RSI-passed dips), invested capital, units held, average cost, current portfolio value, P/L, ex-date count, total dividends received, dividends as % of invested capital, current TTM yield, DCA total return (incl. dividends), and a Lump Sum comparison computed from the same invested amount at the start date — including dividends on the Lump Sum side for a fair comparison.
ALERTS
Every buy signal fires alert() with a JSON payload (symbol, mode, price, amount, drawdown from high, RSI, and whether the RSI condition passed) — ready for webhooks. Create an alert with "Any alert() function call". Alerts fire on bar close for signals that occur after the alert is created; historical backtest markers do not fire.
HOW TO USE
- Open a daily chart of the symbol you want to test (recommended).
- Enable one or more buy modes and set your budget, unit size, and date range.
- Read the "DCA beats/loses Lump Sum" row to judge whether systematic dip-buying suits the symbol.
- Tune per symbol: calmer stocks work with smaller dip thresholds (5–7%), volatile ones with larger (12–15%).
METHOD & LIMITATIONS
Simulation buys at bar close (no intrabar fills). Accounting is computed by the script itself (indicator, not a strategy — no Strategy Tester tab). Commission % per purchase is included in cost basis. Dividend data depends on TradingView's database and may be incomplete for some markets or older periods. Past performance does not guarantee future results. Educational tool — not investment advice.
═══════════════════════════════════════════════
เครื่องมือนี้ทำอะไร
ทดสอบย้อนหลัง (backtest) กลยุทธ์สะสมหุ้นแบบ DCA กับสินทรัพย์ใดก็ได้ แสดงผลครบบนชาร์ต: ตารางสรุป, จุดซื้อ, เส้นต้นทุนเฉลี่ย, เงินปันผลจากวัน XD จริง, โซนราคาที่ปันผลคุ้ม และการเทียบกับ Lump Sum อย่างยุติธรรม — เป็นแบบซื้อสะสมอย่างเดียว (HODL) ไม่มีการขาย
โหมดการซื้อ (เปิดพร้อมกันได้)
- DCA ตามรอบเวลา — รายวัน/รายสัปดาห์/รายเดือน เลือกวันและเวลาซื้อได้ ตลาดปิดวันเป้าหมายจะเลื่อนให้อัตโนมัติ
- Buy the Dip — ซื้อเมื่อราคาย่อจาก High ตาม % ที่ตั้ง (ค่าเริ่มต้น 12% จากกรอบ 20 แท่ง เว้นซื้อซ้ำ 14 แท่ง) พร้อมตัวเลือก RSI สองแบบ: กรองอย่างเดียว หรือ โหมดผสม — ไม้ปกติทุกครั้งที่ย่อ (ป้าย D สีฟ้า) + ไม้พิเศษเมื่อ RSI ต่ำกว่าเกณฑ์ด้วย (ป้ายไฟสีแดง) แยก cooldown สองสาย ปรับตัวคูณไม้พิเศษได้
- ถัวเฉลี่ยขาลงแบบ Martingale — ไม้ใหญ่ขึ้นตามตัวคูณเมื่อราคาลงต่อ มีเพดานจำนวนไม้และรีเซ็ตเมื่อราคาฟื้น
เงินปันผล (ข้อมูล XD จริง)
ใช้ประวัติปันผลจริงของสินทรัพย์ คิดจากจำนวนหน่วยที่ถือ ณ วัน XD เลือก Gross/Net ได้ (ตลาดที่มีแต่ Gross เช่น SET จะคำนวณ Net จากภาษีหัก ณ ที่จ่ายให้) จุด XD บนชาร์ตแสดง % ปันผลของงวดนั้นเทียบราคาวันนั้น เช่น "XD 2.35%"
โซนปันผลคุ้ม (Dividend Yield Zone)
ไฮไลท์พื้นหลังช่วงราคาที่ yield ต่อปีสูงกว่าเกณฑ์ (ค่าเริ่มต้น 8%) เลือกวิธีคิดได้ทั้ง TTM 12 เดือน หรือ ปีปฏิทินล่าสุดที่จบแล้ว พร้อมตัวกรองตัดปันผลพิเศษ (เกิน 2.5 เท่าของ median) ที่ทำให้ yield โป่งเกินจริง และเส้นบอกราคาที่ yield เท่าเกณฑ์พอดี
ตารางสรุป
จำนวนไม้ (แยกไม้ปกติ/ผ่าน RSI), เงินต้น, หน่วยที่ถือ, ต้นทุนเฉลี่ย, มูลค่าพอร์ต, กำไร/ขาดทุน, จำนวนครั้ง XD, ปันผลรวมและคิดเป็น % ของเงินต้น, yield ปัจจุบัน, ผลตอบแทนรวมปันผล และบรรทัดตัดสิน DCA ชนะ/แพ้ Lump Sum (ฝั่ง Lump Sum รวมปันผลด้วยเพื่อความยุติธรรม)
การตั้ง Alert
ทุกสัญญาณซื้อยิง alert() เป็น JSON (สัญลักษณ์ โหมด ราคา จำนวนเงิน % ย่อ RSI และสถานะผ่าน RSI) พร้อมต่อ webhook — ตั้งด้วย "Any alert() function call" และยิงเฉพาะสัญญาณที่เกิดหลังตั้ง alert ที่ราคาปิดแท่งเท่านั้น
วิธีใช้
- เปิดชาร์ตรายวันของสินทรัพย์ที่ต้องการทดสอบ (แนะนำ)
- เปิดโหมดซื้อที่ต้องการ ตั้งงบ ขนาดไม้ และช่วงเวลาทดสอบ
- ดูบรรทัด "DCA ชนะ/แพ้ Lump Sum" เพื่อตัดสินว่าสินทรัพย์นั้นเหมาะกับการทยอยซื้อไหม
- จูนรายตัว: หุ้นนิ่งใช้เกณฑ์ย่อ 5–7% หุ้นเหวี่ยงแรงใช้ 12–15%
ข้อจำกัด
จำลองซื้อที่ราคาปิดแท่ง · เป็น indicator จึงไม่มีแท็บ Strategy Tester (ตารางสรุปแสดงผลครบแทน) · ข้อมูลปันผลอิงฐานข้อมูล TradingView อาจไม่ครบทุกตลาด/ช่วงเก่า · ผลในอดีตไม่ยืนยันผลในอนาคต จัดทำเพื่อการศึกษา ไม่ใช่คำแนะนำการลงทุน
Release Note
Update to using EN/TH language with configurationRelease Note
update asset presentสคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน