Work 06 · Deep dive

เครื่องมือทำรายงานผลการเทรด

Trade review reporting tool

เครื่องมือบนเครื่อง · เปิดจากไอคอนบนเดสก์ท็อป
Desktop tool · opens from a desktop icon

ดึงประวัติการเทรดจาก MetaTrader 5 มาวาดเป็นกล่องบนกราฟแท่งเทียน แล้วสรุปเป็นรายงานวินัยการเทรด ออกมาเป็นหน้าเว็บไฟล์เดียวที่เปิดได้เลยโดยไม่ต้องมีเซิร์ฟเวอร์

Pulls trade history from MetaTrader 5, draws each trade as a box on a candlestick chart, and produces a trading-discipline report as a single web page that opens directly, no server needed.

How it works

ระบบทำงานยังไง

How it works

01
ดับเบิลคลิกไอคอนDouble-click the iconบนเดสก์ท็อปOn the desktop
02
ดึงประวัติPull historyทุกไม้ ทุกการฝากถอน จากโปรแกรมเทรดEvery trade, deposit and withdrawal from the platform
03
จับคู่ไม้Pair the tradesรวมการเข้าออกหลายครั้งของไม้เดียวกันเป็นราคาเฉลี่ยCombine multiple entries/exits of one position into average prices
04
แก้เวลาFix the timeแปลงเวลาเซิร์ฟเวอร์เป็นเวลาไทยConvert server time to Thai time
05
สร้างหน้าเว็บBuild the pageไฟล์เดียว เปิดในเบราว์เซอร์ได้ทันทีA single file that opens in the browser
06
ทบทวนReviewกราฟ รายเดือน ปฏิทิน เช็ควินัย Export ภาพChart, monthly, calendar, discipline check, PNG export

ขั้นที่มีคนเป็นผู้ตัดสินใจหรือใช้งานSteps where a person decides or uses it

หน้ากราฟ: กล่องเขียวแดงคือไม้แต่ละไม้ ลูกศรคือจุดเข้าออก (ตัวเลขกำไรขาดทุนและเปอร์เซ็นต์ถูกซ่อนทั้งหมด)
หน้ากราฟ: กล่องเขียวแดงคือไม้แต่ละไม้ ลูกศรคือจุดเข้าออก (ตัวเลขกำไรขาดทุนและเปอร์เซ็นต์ถูกซ่อนทั้งหมด)
Chart view: green and red boxes are individual trades, arrows mark entries and exits (all profit/loss figures and percentages hidden)
My calls

ส่วนที่ผมเป็นคนตัดสินใจ

Decisions I made

AI เขียนโค้ดให้ แต่โจทย์ เกณฑ์ และสิ่งที่ยอมไม่ได้ ผมเป็นคนกำหนด

The AI writes the code; the problem, the criteria and the non-negotiables are mine.

ดูวินัย ไม่ใช่ดูแค่กำไรReview discipline, not just profit

รายงานมีหน้าเช็ควินัยที่ติดธงเมื่อขนาดไม้เกินที่ตั้งไว้ และหน้า "กำไรที่ทิ้งไว้บนโต๊ะ" ที่เทียบว่าราคาเคยวิ่งไปถึงไหนกับจุดที่ปิดจริง

There's a discipline page that flags positions above the set size limit, and a "profit left on the table" page comparing how far price went with where the trade was closed.

เทียบกับเงินที่ใส่เข้าไปจริงMeasure against money actually deposited

เปอร์เซ็นต์คิดจากยอดฝากรวม แทนทุนตั้งต้นที่ตั้งไว้เอง เพราะการฝากเพิ่มระหว่างทางทำให้ตัวเลขแบบเดิมหลอกตา

Percentages are based on total deposits rather than a self-declared starting balance, because topping up along the way makes the old figure misleading.

ไม่ต้องเรียลไทม์Real-time isn't needed

เป็นภาพ ณ ตอนกดเปิด ทำให้ระบบเรียบง่ายและไม่มีอะไรต้องรันค้างไว้

It's a snapshot taken when opened, which keeps the system simple with nothing running in the background.

Code

โค้ดจริงบางส่วน

Real code excerpts

โค้ดทั้งหมดเขียนโดย Claude Code ตามที่ผมสั่ง ผมอ่านแล้วอธิบายได้ว่าแต่ละท่อนทำอะไร และทำไมต้องเขียนแบบนี้ (ข้อมูลลับอย่างรหัสผ่านและที่อยู่เครื่องถูกตัดออก)

All code was written by Claude Code under my direction. I can explain what each part does and why it's written that way. (Secrets such as keys and machine paths are removed; code comments are in Thai.)

รอให้ประวัติซิงก์ครบก่อนสร้างรายงาน

Wait for history to finish syncing

หลังสลับบัญชี ประวัติการเทรดจะซิงก์ตามมาช้ากว่าเล็กน้อย ถ้าดึงทันทีจะได้ข้อมูลไม่ครบ โค้ดนี้จะรอจนไม้ที่เปิดอยู่ทุกไม้มีประวัติตอนเปิดครบก่อน แล้วค่อยหาส่วนต่างเวลาของเซิร์ฟเวอร์จากราคาล่าสุด

After switching accounts the trade history syncs a little late; pulling immediately gives incomplete data. This waits until every open position has its opening deal, then works out the server's time offset from the latest price.

# หลัง login ประวัติ deal ซิงก์ตามมาทีหลัง -> รอจนไม้ที่เปิดอยู่มี deal ตอนเปิดครบ
open_ids = {p.identifier for p in m.positions_get() or []}
for _ in range(30):
    all_deals = m.history_deals_get(H0, H1) or ()
    if open_ids <= {d.position_id for d in all_deals if d.entry == 0}:
        break
    time.sleep(0.5)

# หา offset เวลาเซิร์ฟเวอร์ (tick.time เป็นเวลาเซิร์ฟเวอร์)
srv_off_h = round((m.symbol_info_tick(SYM).time - time.time()) / 3600)
shift = int((TZ_OUT - srv_off_h) * 3600)
build.pybuild.py · เขียนโดย Claude Codewritten by Claude Code
Problems solved

ปัญหาที่เจอ และวิธีแก้

Problems and fixes

ปัญหาProblem

เวลาในรายงานเพี้ยนไปหลายชั่วโมง

Report times off by several hours

แก้ยังไงFix

โปรแกรมเทรดส่งเวลาของเซิร์ฟเวอร์มา เลยต้องคำนวณส่วนต่างจากราคาล่าสุดแล้วแปลงเป็นเวลาไทย

The platform reports server time, so the offset is computed from the latest price and converted to Thai time

ปัญหาProblem

ไม้ล่าสุดหายจากรายงาน

Latest trade missing from the report

แก้ยังไงFix

รอให้ประวัติซิงก์ครบก่อน (โค้ดด้านบน)

Wait for history to finish syncing (code above)

ปัญหาProblem

หน้าแสดงค้างเป็นข้อมูลเก่า

Page showing stale data

แก้ยังไงFix

เพราะเป็นภาพ ณ ตอนเปิด ต้องกดสร้างใหม่ ระบบจะบอกเวลาของข้อมูลไว้ท้ายหน้า

It's a snapshot, so it must be rebuilt; the data timestamp is shown at the bottom

← เว็บแคตตาล็อกสินค้าสำหรับลูกค้า B2BB2B product catalog websiteกลับไปหน้าผลงานBack to all work →