เข้าสู่ระบบสมัครสมาชิก
หน้าแรกHome / บทความฟรีFree articles / ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a pro
ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a proเริ่มต้นBeginnerอ่าน 5 นาที5 min read9 / 13 ในหมวดนี้9 of 13 in this section

พื้นฐาน EA และการเทรดอัตโนมัติบน MT4/MT5EA and Automated Trading Basics on MT4/MT5

EA ทำงานอย่างไร ต้องตั้งค่าอะไรบ้าง ตรวจอย่างไรว่าทำงานถูก และความเสี่ยงที่คนมักมองไม่เห็นเมื่อปล่อยให้โปรแกรมเทรดแทนHow an EA works, what to configure, how to check it is behaving, and the risks people miss when they let a program trade for them.

กราฟ XAUUSD ประกอบหมวด ทดสอบระบบและเทรดแบบมืออาชีพ / Testing & trading like a pro
ในบทความนี้ · 7
  1. EA ทำงานอย่างไร
  2. ค่าที่ต้องเข้าใจก่อนเปิดใช้
  3. ตรวจว่า EA ทำงานถูก
  4. การรันตลอด 24 ชั่วโมง
  5. จุดอ่อน / ข้อผิดพลาดที่พบบ่อย
  6. ใช้บนมือถือ
  7. สรุป
In this article · 7
  1. How an EA works
  2. Settings to understand before you switch it on
  3. Checking that the EA behaves
  4. Running around the clock
  5. Weaknesses / common mistakes
  6. On a phone
  7. Summary

EA (Expert Advisor) คือโปรแกรมที่รันอยู่ใน MetaTrader 4 หรือ 5 และทำตามกฎที่เขียนไว้โดยอัตโนมัติ ตั้งแต่อ่านราคา ตัดสินใจ ส่งคำสั่ง ไปจนถึงเลื่อน SL หรือปิดไม้ ข้อดีคือทำตามกฎได้สม่ำเสมอโดยไม่มีอารมณ์ และทำงานได้ตลอดเวลาที่ตลาดเปิด แต่ EA ไม่ได้ฉลาดกว่ากฎที่อยู่ข้างใน ถ้ากฎไม่มีความได้เปรียบ EA ก็จะขาดทุนอย่างมีระเบียบเช่นกัน

EA ทำงานอย่างไร

  • ทำงานเมื่อมีราคาใหม่ (Tick) ทุกครั้งที่ราคาขยับ EA จะถูกเรียกให้ตรวจเงื่อนไข บางตัวทำงานตามตัวจับเวลาด้วย
  • ทำงานบนกราฟที่แปะไว้ EA หนึ่งตัวต่อหนึ่งกราฟ ถ้าปิดกราฟหรือปิดโปรแกรม EA ก็หยุด
  • แยกไม้ของตัวเองด้วย Magic number ตัวเลขประจำที่ติดไปกับทุกคำสั่ง ทำให้ EA รู้ว่าไม้ไหนเป็นของมัน ถ้าใช้ EA หลายตัวในบัญชีเดียว ต้องตั้งเลขไม่ซ้ำกัน
  • ต้องให้สิทธิ์เทรด ปุ่ม Algo Trading (MT5) หรือ AutoTrading (MT4) ต้องเปิด และในหน้าตั้งค่าของ EA ต้องอนุญาตให้เทรดอัตโนมัติ

ไฟล์ที่ใช้คือ .mq4/.mq5 (โค้ดต้นฉบับ) และ .ex4/.ex5 (ไฟล์ที่คอมไพล์แล้ว) วางในโฟลเดอร์ MQL4/Experts หรือ MQL5/Experts ซึ่งเปิดได้จากเมนู File > Open Data Folder

ดูภาพด้านล่าง

EA ทำงานทีละรอบอย่างไรHow an EA works, one cycle
1ราคาใหม่ (Tick) เข้ามาA new price (tick) arrives2ตรวจเงื่อนไขตามกฎที่เขียนไว้Check the written conditions3ครบ ส่งคำสั่งพร้อม Magic numberIf met, send the order with its magicnumber4ดูแลไม้ เลื่อน SL หรือปิดตามกฎManage the trade: move SL or close5บันทึกผลในแท็บ Experts/JournalLog the result in Experts/Journal

ค่าที่ต้องเข้าใจก่อนเปิดใช้

  1. ขนาดไม้ แบบล็อตคงที่ หรือแบบ % ความเสี่ยงของทุน
  2. SL และ TP EA ตั้งให้ทุกไม้หรือไม่ ไม้ที่ไม่มี SL คือความเสี่ยงไม่จำกัด
  3. จำนวนไม้สูงสุด ป้องกันการเปิดซ้อนเกินตั้งใจ
  4. ฟิลเตอร์สเปรดและเวลา เช่น ไม่เปิดไม้ถ้าสเปรดกว้างผิดปกติ หรือช่วงก่อนข่าว
  5. Magic number ไม่ซ้ำกับ EA ตัวอื่น
เช็คก่อนเปิด EACheck before switching an EA on
1ขนาดไม้ ล็อตคงที่ หรือ % ของทุนSize: fixed lot or % of account2SL และ TP ตั้งทุกไม้หรือไม่Does every trade get SL and TP?3จำกัดจำนวนไม้สูงสุดCap the number of open trades4ฟิลเตอร์สเปรดและเวลาSpread and time filters5Magic number ไม่ซ้ำ EA อื่นA magic number no other EA uses
🧮 ความเสี่ยงที่ EA ใช้จริง ไม่ใช่ที่ตั้งไว้

บัญชี $1,000 ตั้ง EA ให้เสี่ยง 1% = $10 ต่อไม้ เทรดทองคำ ล็อตขั้นต่ำและขั้นขยับคือ 0.01 SL $8: ล็อต = 10 ÷ (8 × 100) = 0.0125 ปัดลงเป็น 0.01 ความเสี่ยงจริง = 8 × 100 × 0.01 = $8 (0.8%) SL $3: ล็อต = 10 ÷ (3 × 100) ≈ 0.033 ปัดลงเป็น 0.03 ความเสี่ยงจริง = 3 × 100 × 0.03 = $9 (0.9%) SL $15: ล็อต = 10 ÷ (15 × 100) ≈ 0.0067 ต่ำกว่าล็อตขั้นต่ำ ถ้า EA บังคับเปิดที่ 0.01 ความเสี่ยงจริง = 15 × 100 × 0.01 = $15 (1.5%) สูงกว่าที่ตั้งใจครึ่งหนึ่ง บัญชีเล็กจึงคุมความเสี่ยงได้หยาบกว่าที่ตัวเลขในหน้าตั้งค่าบอก ควรเช็คว่า EA ข้ามไม้หรือบังคับล็อตขั้นต่ำในกรณีนี้

ดูภาพด้านล่าง

ตั้งเสี่ยง $10 แต่เสี่ยงจริงเท่าไร (บัญชี $1,000)Set $10 risk, real risk ($1,000 account)
ที่ตั้งไว้ 1%Setting, 1%$10SL $8 → 0.01 ล็อต$8 stop → 0.01 lot$8 (0.8%)SL $3 → 0.03 ล็อต$3 stop → 0.03 lot$9 (0.9%)SL $15 → บังคับ 0.01$15 stop → forced0.01$15 (1.5%)
ล็อตขั้นต่ำ 0.01 ทำให้บัญชีเล็กคุมความเสี่ยงได้หยาบA 0.01 minimum lot makes small-account risk coarse

ตรวจว่า EA ทำงานถูก

  • แท็บ Experts และ Journal ด้านล่างโปรแกรม แสดงข้อความของ EA และผลการส่งคำสั่ง ถ้าคำสั่งถูกปฏิเสธจะมีรหัสข้อผิดพลาดบอกไว้
  • ไอคอนบนกราฟ มุมขวาบนของกราฟจะแสดงว่า EA ทำงานหรือถูกปิดสิทธิ์เทรดอยู่
  • ทดสอบใน Strategy Tester โหมด Visualization ดูว่า EA เข้าออกตรงกับกฎจริง ดู Backtest
  • รันบน demo ก่อน อย่างน้อยหลายสัปดาห์ แล้วต่อด้วยบัญชีจริงไม้เล็ก ดู Forward test

ถ้าอยากลองเขียน EA เองจากกฎที่มี ให้ AI ช่วยร่างโค้ดได้ ดูตัวอย่างคำสั่งที่ หน้ารวม prompt แต่โค้ดที่ได้ต้องคอมไพล์และทดสอบทุกครั้ง AI เขียนผิดได้

ตรวจว่า EA ทำงานถูกChecking that the EA behaves
1อ่านแท็บ Experts และ JournalRead the Experts and Journal tabs2ดูไอคอนมุมขวาบนของกราฟCheck the icon at the chart's top right3ดูใน Visualization ว่าตรงกฎConfirm in Visualization it follows therules4รัน demo หลายสัปดาห์Run on demo for several weeks5ต่อด้วยบัญชีจริงไม้เล็กThen live at small size

การรันตลอด 24 ชั่วโมง

EA ต้องการคอมพิวเตอร์ที่เปิดอยู่และต่ออินเทอร์เน็ตตลอด ถ้าคอมดับ ไฟตก หรือเน็ตหลุด EA จะหยุดดูแลไม้ที่เปิดค้าง (SL/TP ที่ส่งไปที่เซิร์ฟเวอร์แล้วยังทำงาน แต่ trailing stop หรือการปิดตามเงื่อนไขในโปรแกรมจะไม่ทำงาน) หลายคนจึงใช้ VPS

คอมดับหรือเน็ตหลุด อะไรยังทำงานComputer off or offline: what still works
ยังทำงาน (อยู่ที่เซิร์ฟเวอร์)Still works (on the server)✓SL ที่ส่งไปแล้วStops already sent✓TP ที่ส่งไปแล้วTargets already sentหยุดทำงาน (อยู่ในโปรแกรม)Stops (inside the program)✗Trailing stop ของ EAThe EA's trailing stop✗การปิดไม้ตามเงื่อนไขในโค้ดRule-based exits in the code✗การเปิดไม้ใหม่New entries

จุดอ่อน / ข้อผิดพลาดที่พบบ่อย

  • ซื้อ EA จากผลงานสวย ๆ ไม่รู้ว่าข้างในเป็น grid หรือ martingale ที่สะสมความเสี่ยงไว้ จนวันหนึ่งล้างพอร์ต ดู วิธีดูกลโกง
  • ไม่มี SL ในตัวระบบ อาศัยว่า "EA จะปิดเอง" ถ้าโปรแกรมหยุดทำงานไม้ก็ไม่มีใครดูแล
  • Magic number ซ้ำ EA สองตัวไปปิดหรือแก้ไม้ของกันและกัน
  • ปล่อยทิ้งไม่ดู EA ก็ยังต้องตรวจทุกวัน ดู log ดูว่าทำงานอยู่จริง และผลยังอยู่ในกรอบปกติ
  • ปรับค่าหลังขาดทุนทุกครั้ง เป็นการ overfit กับตลาดจริง
  • ไม่ตรวจเรื่องสิทธิ์ของโปรแกรม EA ที่ขอให้เปิด DLL หรือส่งข้อมูลออกไปเว็บภายนอก ต้องรู้ว่ามันส่งอะไรไปที่ไหน
ใช้ EA อย่างปลอดภัยRunning an EA safely
ทำแบบนี้Do✓ทุกไม้มี SL ในตัวระบบA stop on every trade, built in✓Magic number ไม่ซ้ำกันUnique magic numbers✓เช็ค log และผลทุกวันCheck logs and results dailyอย่าทำแบบนี้Don't✗ซื้อเพราะผลงานสวยอย่างเดียวBuy on pretty results alone✗ปล่อยทิ้งไม่ดูSet and forget✗ปรับค่าใหม่หลังขาดทุนทุกครั้งRe-tune after every loss

ใช้บนมือถือ

แอป MT4/MT5 บนมือถือรัน EA ไม่ได้ แต่ใช้ดูผลงานของ EA ที่รันบนคอมหรือ VPS ได้ โดยล็อกอินบัญชีเดียวกัน ระวังการปิดไม้ด้วยมือจากมือถือขณะ EA กำลังดูแลไม้นั้นอยู่ EA บางตัวอาจเปิดไม้ใหม่ทดแทนทันที

สรุป

  • EA คือกฎการเทรดที่ถูกเขียนเป็นโปรแกรม ดีได้เท่ากับกฎข้างใน
  • เข้าใจขนาดไม้ SL Magic number และฟิลเตอร์ก่อนเปิดใช้
  • ความเสี่ยงจริงอาจต่างจากที่ตั้ง โดยเฉพาะบัญชีเล็กที่ติดล็อตขั้นต่ำ
  • ตรวจ log ทดสอบใน Visualization และรัน demo ก่อนเสมอ
  • EA ต้องการเครื่องที่เปิดตลอด และยังต้องมีคนดูแลทุกวัน

An EA (Expert Advisor) is a program that runs inside MetaTrader 4 or 5 and follows written rules automatically: reading prices, deciding, sending orders, moving stops and closing trades. Its strength is that it follows the rules consistently, without emotion, whenever the market is open. But an EA is no smarter than the rules inside it. If the rules have no edge, the EA will lose money in a very orderly way.

How an EA works

  • It reacts to new prices (ticks). Each time price changes, the EA is called to check its conditions. Some also run on a timer.
  • It runs on the chart it is attached to. One EA per chart. Close the chart or the terminal and the EA stops.
  • It identifies its trades by magic number. An ID attached to every order tells the EA which trades belong to it. With several EAs on one account, give each a different number.
  • It needs permission to trade. The Algo Trading button (MT5) or AutoTrading button (MT4) must be on, and live trading must be allowed in the EA's settings.

The files are .mq4/.mq5 (source code) and .ex4/.ex5 (compiled). They go in the MQL4/Experts or MQL5/Experts folder, which you can open from File > Open Data Folder.

See the chart below.

EA ทำงานทีละรอบอย่างไรHow an EA works, one cycle
1ราคาใหม่ (Tick) เข้ามาA new price (tick) arrives2ตรวจเงื่อนไขตามกฎที่เขียนไว้Check the written conditions3ครบ ส่งคำสั่งพร้อม Magic numberIf met, send the order with its magicnumber4ดูแลไม้ เลื่อน SL หรือปิดตามกฎManage the trade: move SL or close5บันทึกผลในแท็บ Experts/JournalLog the result in Experts/Journal

Settings to understand before you switch it on

  1. Position size: a fixed lot, or a % of the account at risk.
  2. SL and TP: does the EA set them on every trade? A trade without a stop has unlimited risk.
  3. Maximum open trades, to prevent unintended stacking.
  4. Spread and time filters, e.g. no new trades when the spread is unusually wide or just before news.
  5. Magic number, different from any other EA.
เช็คก่อนเปิด EACheck before switching an EA on
1ขนาดไม้ ล็อตคงที่ หรือ % ของทุนSize: fixed lot or % of account2SL และ TP ตั้งทุกไม้หรือไม่Does every trade get SL and TP?3จำกัดจำนวนไม้สูงสุดCap the number of open trades4ฟิลเตอร์สเปรดและเวลาSpread and time filters5Magic number ไม่ซ้ำ EA อื่นA magic number no other EA uses
🧮 The risk the EA actually takes, not the one you set

A $1,000 account, EA set to risk 1% = $10 per trade on gold. Minimum lot and lot step are 0.01. $8 stop: lot = 10 ÷ (8 × 100) = 0.0125, rounded down to 0.01. Real risk = 8 × 100 × 0.01 = $8 (0.8%). $3 stop: lot = 10 ÷ (3 × 100) ≈ 0.033, rounded down to 0.03. Real risk = 3 × 100 × 0.03 = $9 (0.9%). $15 stop: lot = 10 ÷ (15 × 100) ≈ 0.0067, below the minimum. If the EA forces 0.01, real risk = 15 × 100 × 0.01 = $15 (1.5%), half again what you intended. Small accounts control risk more coarsely than the settings suggest. Check whether the EA skips the trade or forces the minimum lot in this case.

See the chart below.

ตั้งเสี่ยง $10 แต่เสี่ยงจริงเท่าไร (บัญชี $1,000)Set $10 risk, real risk ($1,000 account)
ที่ตั้งไว้ 1%Setting, 1%$10SL $8 → 0.01 ล็อต$8 stop → 0.01 lot$8 (0.8%)SL $3 → 0.03 ล็อต$3 stop → 0.03 lot$9 (0.9%)SL $15 → บังคับ 0.01$15 stop → forced0.01$15 (1.5%)
ล็อตขั้นต่ำ 0.01 ทำให้บัญชีเล็กคุมความเสี่ยงได้หยาบA 0.01 minimum lot makes small-account risk coarse

Checking that the EA behaves

  • Experts and Journal tabs at the bottom of the terminal show the EA's messages and order results. Rejected orders show an error code.
  • The chart icon in the top-right corner shows whether the EA is running or blocked from trading.
  • Strategy Tester in Visualization mode lets you confirm entries and exits match the rules. See Backtesting.
  • Run it on demo first, for several weeks at least, then live at small size. See Forward testing.

If you want to build an EA from your own rules, an AI assistant can draft the code; see the prompt library. Always compile and test the result. AI makes mistakes.

ตรวจว่า EA ทำงานถูกChecking that the EA behaves
1อ่านแท็บ Experts และ JournalRead the Experts and Journal tabs2ดูไอคอนมุมขวาบนของกราฟCheck the icon at the chart's top right3ดูใน Visualization ว่าตรงกฎConfirm in Visualization it follows therules4รัน demo หลายสัปดาห์Run on demo for several weeks5ต่อด้วยบัญชีจริงไม้เล็กThen live at small size

Running around the clock

An EA needs a computer that is on and connected all the time. If the computer shuts down, the power cuts out or the internet drops, the EA stops managing open trades. Stops and targets already sent to the server still work, but trailing stops or rule-based exits inside the program do not. That is why many people use a VPS.

คอมดับหรือเน็ตหลุด อะไรยังทำงานComputer off or offline: what still works
ยังทำงาน (อยู่ที่เซิร์ฟเวอร์)Still works (on the server)✓SL ที่ส่งไปแล้วStops already sent✓TP ที่ส่งไปแล้วTargets already sentหยุดทำงาน (อยู่ในโปรแกรม)Stops (inside the program)✗Trailing stop ของ EAThe EA's trailing stop✗การปิดไม้ตามเงื่อนไขในโค้ดRule-based exits in the code✗การเปิดไม้ใหม่New entries

Weaknesses / common mistakes

  • Buying an EA for its pretty results without knowing it is a grid or martingale quietly accumulating risk until it wipes the account. See Avoiding scams.
  • No stop loss in the system, relying on "the EA will close it". If the program stops, nobody manages the trade.
  • Duplicate magic numbers, so two EAs close or modify each other's trades.
  • Set and forget. An EA still needs a daily check: the logs, that it is actually running, and that results are within the normal range.
  • Re-tuning after every loss. That is overfitting to live data.
  • Ignoring permissions. If an EA asks for DLL imports or sends data to outside websites, find out what it sends and where.
ใช้ EA อย่างปลอดภัยRunning an EA safely
ทำแบบนี้Do✓ทุกไม้มี SL ในตัวระบบA stop on every trade, built in✓Magic number ไม่ซ้ำกันUnique magic numbers✓เช็ค log และผลทุกวันCheck logs and results dailyอย่าทำแบบนี้Don't✗ซื้อเพราะผลงานสวยอย่างเดียวBuy on pretty results alone✗ปล่อยทิ้งไม่ดูSet and forget✗ปรับค่าใหม่หลังขาดทุนทุกครั้งRe-tune after every loss

On a phone

The MT4/MT5 mobile apps cannot run EAs, but by logging in to the same account you can monitor an EA running on a computer or VPS. Be careful closing a trade by hand from your phone while the EA manages it; some EAs will immediately open a replacement.

Summary

  • An EA is trading rules written as a program, only as good as those rules.
  • Understand position size, stops, magic number and filters before switching it on.
  • Real risk can differ from the setting, especially on small accounts limited by the minimum lot.
  • Check the logs, test in Visualization mode and run on demo first.
  • An EA needs a machine that is always on, and still needs a human check every day.
อยากได้เป็น EA: คลังพรอมต์สร้าง EA ฟรีWant it as an EA: free EA prompt libraryคัดลอกพรอมต์ 37 กลยุทธ์ไปวางใน ChatGPT, Gemini หรือ Claude ให้ AI ของคุณเขียน EA ให้Copy one of 37 strategy prompts into ChatGPT, Gemini or Claude and let your AI write the EA.
เปิดฟรี ›Open free ›

อ่านต่อRead next

กราฟ XAUUSD ประกอบหมวด รูปแบบและกลยุทธ์การเทรด / Trading styles & strategies
รูปแบบและกลยุทธ์การเทรดTrading styles & strategiesกลางIntermediate5 นาที5 min

การเทรดด้วยระบบอัตโนมัติ (Algorithmic / EA Trading)Algorithmic and EA Trading

ระบบเทรดอัตโนมัติ (EA) ทำอะไรได้และไม่ได้ ขั้นตอนจากไอเดียถึงบัญชีจริง ทำไมผลทดสอบย้อนหลังมักดีกว่าความจริง และวิธีดูแลระบบที่รันอยู่What an automated trading system (EA) can and cannot do, the path from idea to live account, why backtests usually beat reality, and how to supervise a running system.

กราฟ XAUUSD ประกอบหมวด ทดสอบระบบและเทรดแบบมืออาชีพ / Testing & trading like a pro
ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a proกลางIntermediate5 นาที5 min

การทดสอบย้อนหลัง (Backtesting) และ Strategy Tester ของ MT5Backtesting and the MT5 Strategy Tester

วิธีทดสอบกฎการเทรดกับข้อมูลในอดีตให้ได้ผลที่เชื่อถือได้ ทั้งแบบมือและด้วย Strategy Tester ของ MT5 พร้อมกับดักที่ทำให้ผลสวยเกินจริงHow to test trading rules on past data in a way you can trust, by hand and with the MT5 Strategy Tester, plus the traps that make results look better than they are.

กราฟ XAUUSD ประกอบหมวด ทดสอบระบบและเทรดแบบมืออาชีพ / Testing & trading like a pro
ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a proกลางIntermediate4 นาที4 min

VPS และคุณภาพการส่งคำสั่ง (Execution)VPS and Execution Quality

VPS คืออะไร จำเป็นเมื่อไหร่ เลือกอย่างไร และวิธีวัดสลิปเพจกับความหน่วงว่ากระทบผลการเทรดแค่ไหนWhat a VPS is, when you need one, how to choose, and how to measure slippage and latency to see how much they affect your results.

กราฟ XAUUSD ประกอบหมวด ทดสอบระบบและเทรดแบบมืออาชีพ / Testing & trading like a pro
ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a proกลางIntermediate5 นาที5 min

การทดสอบไปข้างหน้า (Forward Testing)Forward Testing

ทดสอบระบบกับตลาดจริงที่ยังไม่เกิดก่อนใช้เงินก้อนใหญ่ วัดอะไร นานแค่ไหน และเมื่อไหร่ควรหยุดHow to test a system on live, unseen market data before committing real size: what to measure, how long to run it, and when to stop.

กราฟ XAUUSD ประกอบหมวด ทดสอบระบบและเทรดแบบมืออาชีพ / Testing & trading like a pro
ทดสอบระบบและเทรดแบบมืออาชีพTesting & trading like a proเริ่มต้นBeginner5 นาที5 min

วิธีดูกลโกงในวงการเทรดHow to Spot Trading Scams

รู้ทันรูปแบบหลอกลวงที่พบบ่อย ทั้งภาพผลกำไรปลอม การการันตีผลตอบแทน และการรับบริหารพอร์ต พร้อมคำถามที่ใช้ตรวจสอบก่อนเสียเงินRecognise the most common trading scams, from fake profit screenshots to guaranteed returns and managed-account schemes, with questions to ask before you pay anything.