| Thực Hành Với MetaTrader 5 Và TradingView

Được viết bởi thanhdt vào ngày 27/12/2025 lúc 20:23 | 248 lượt xem

Thực Hành Với MetaTrader 5 Và TradingView

Mục tiêu buổi học

  • Kết nối MT5 với Python để mở/đóng lệnh mô phỏng
  • Viết chiến lược Pine Script xác định xu hướng
  • Nhận tín hiệu TradingView qua webhook về n8n
  • Vận hành bot bằng vòng polling TP/SL

Hình minh hoạ tổng quan

https://media.b2broker.com/app/uploads/2024/08/MT5-terminal-interface-800x601.png
https://s3.tradingview.com/z/ZSyG0zv6_big.png
https://miro.medium.com/1%2ARBc1vx6-XUjbQRNvANYYEQ.png

4


Hình minh hoạ từng phần quan trọng

1. Pine Script trên TradingView

https://r2.pineify.app/assets/764d2eb58dde460fd519b4a177debd76.png
https://quantnomad.com/wp-content/uploads/2023/01/image-7.png

2. MT5 chạy tài khoản Demo

https://www.metatrader5.com/i/help/android/en/new_account.png
https://help.markettraders.com/data/img/kA04V000000u0ThSAI_en_US_1_0.png

3. n8n Webhook nhận tín hiệu từ Alert

https://hookdeck.com/_astro/untitled---2023-09-19t171122.355.Z8J-zXL9_mbWdB.webp

4. Monitoring dashboard bot giao dịch

https://cdn.dribbble.com/userupload/43559129/file/original-b393b8636efcf48fd5c40b55c1e66aff.jpg?resize=2048x1536&vertical=center
https://coinrule.com/assets/webp/mobile_landing_bg_small2.webp

Ứng dụng đa khung (MTF)

https://tradeciety.com/hubfs/XAUUSD_2023-04-28_12-08-50.png
https://forexbee.co/wp-content/uploads/2025/09/top-down-analysis-in-trading-768x1195.png

Script mẫu trong buổi học (giữ nguyên, không emoji)

//@version=5
indicator("Fin3B – AMA Trend Demo", overlay=true)

ama6  = ta.hma(close, 6)
ama10 = ta.hma(close, 10)
ama20 = ta.hma(close, 20)

plot(ama6)
plot(ama10)
plot(ama20)

trendUp = ama6 > ama10 and ama10 > ama20
bgcolor(trendUp ? color.new(color.green, 85) : na)
import MetaTrader5 as mt5
import time

mt5.initialize()
symbol = "XAUUSD"
lot = 0.01
tp = 2700
sl = 2600

request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": lot,
    "type": mt5.ORDER_TYPE_BUY,
    "price": mt5.symbol_info_tick(symbol).ask,
    "sl": sl,
    "tp": tp,
}
order = mt5.order_send(request)
print("Entry demo:", order)

while True:
    positions = mt5.positions_get(symbol=symbol)
    if not positions:
        print("Không còn position mở – dừng polling")
        break

    price = mt5.symbol_info_tick(symbol).bid
    print("Giá hiện tại:", price)

    if price >= tp:
        print("→ Đạt TP, đóng lệnh demo")
        mt5.Close(symbol)
        break
    if price <= sl:
        print("→ Chạm SL, đóng lệnh demo")
        mt5.Close(symbol)
        break

    time.sleep(10)

Kết luận buổi 20

Fin3B ở buổi này giúp bạn hiểu:

  • Xu hướng khung lớn mới là bản đồ
  • Entry khung nhỏ chỉ là trigger
  • TP/SL có thể bot tự xử lý bằng polling nếu API không hỗ trợ
  • Không giao dịch khi AMA chồng chéo
  • Luôn giám sát bot để tránh gãy hệ thống
Thành ĐT

Thành ĐT

Founder & Chief Technology Officer, HNDL
1.325 Bài viết
15.4k Người theo dõi
120k+ Lượt đọc

Chuyên gia với hơn 10 năm kinh nghiệm trong phát triển hệ thống giao dịch tự động (Trading Bot), Fintech, Mobile App và phân tích dữ liệu tài chính (Quantitative Analysis). Người sáng lập và trực tiếp dẫn dắt các khóa học thực chiến tại Hướng Nghiệp Dữ Liệu.