Chiến lược & backtestStrategy & backtests
Rủi ro & lệnh kẹtRisk & stuck orders
Ba ghi chú lịch sử về cách EA chống thua lỗ lớn, xử lý lệnh kẹt/xa, và fork 1.41.1 thêm công tắc DCA cùng MinPips linh hoạt, đặt cạnh trạng thái hiện tại. Three historical notes on how the EA fights large losses, how it handles stuck/far orders, and the 1.41.1 fork that added DCA toggles and flexible MinPips, set against the current state.
Ba phần dưới đây viết ở các thời điểm khác nhau (02/2026, cùng thời kỳ, và 14/07/2026) cho các bản EA cũ. Hiện tại: EA production 1.42 b7 (bản cũ 1.41.4 b21), config ổn định v1.42.b7-pass58.set (Config ổn định). Trong config ổn định: InpMaxDrawdownEnable=false, InpMaxLossPerDayEnable=false, InpGlobalSLClearStuckEnable=false, InpTiaProfitUSD=10.0, InpTiaPrioritizeByDistance=true, InpDCANegEnable=false, InpDCAMinPipsMode=0 (Fixed). Mỗi phần có một ô ghi chú riêng về trạng thái hiện tại.
The three parts below were written at different times (02/2026, the same period, and 14/07/2026) for older EA builds. Today: production EA 1.42 b7 (previous 1.41.4 b21), stable config v1.42.b7-pass58.set (Stable config). In the stable config: InpMaxDrawdownEnable=false, InpMaxLossPerDayEnable=false, InpGlobalSLClearStuckEnable=false, InpTiaProfitUSD=10.0, InpTiaPrioritizeByDistance=true, InpDCANegEnable=false, InpDCAMinPipsMode=0 (Fixed). Each part has its own note on the current state.
Phần 1 — Khắc phục nguyên nhân thua lỗ: Risk Management (09/02/2026)Part 1 — Fixing the causes of losses: Risk Management (09/02/2026)
Nguồn: docs/Khắc phục thua lỗ - Risk Management.md. Báo cáo phân tích: data/html/backtest/Phân tích thua lỗ ReportTester-11280950.md.Source: docs/Khắc phục thua lỗ - Risk Management.md. Analysis report: data/html/backtest/Phân tích thua lỗ ReportTester-11280950.md.
Các input InpMaxDrawdown* và InpMaxLossPerDay* vẫn còn (tham số Risk Management). Config ổn định tắt cả hai: InpMaxDrawdownEnable=false (InpMaxDrawdownPercent=35.0, InpMaxDrawdownUSD=0.0, InpMaxDrawdownCloseAll=false) và InpMaxLossPerDayEnable=false (InpMaxLossPerDayUSD=5000.0). Trong mã nguồn GoldenRobber-1.42.mq5 hai công tắc này có default true, nên file .set cần ghi rõ giá trị. Các file GoldenRobber_hybrid.set và tham số Tia/Clear Stuck nêu trong phần này là của bản 02/2026; config ổn định dùng InpTiaProfitUSD=10.0 và tắt Clear Stuck.
The InpMaxDrawdown* and InpMaxLossPerDay* inputs still exist (Risk Management parameters). The stable config turns both off: InpMaxDrawdownEnable=false (InpMaxDrawdownPercent=35.0, InpMaxDrawdownUSD=0.0, InpMaxDrawdownCloseAll=false) and InpMaxLossPerDayEnable=false (InpMaxLossPerDayUSD=5000.0). In the GoldenRobber-1.42.mq5 source both switches default to true, so a .set file must state them explicitly. The GoldenRobber_hybrid.set file and the Tia/Clear Stuck values in this part belong to the 02/2026 build; the stable config uses InpTiaProfitUSD=10.0 and has Clear Stuck off.
Tóm tắt vấn đềProblem summary
Từ phân tích backtest ReportTester-11280950:
- Chuỗi 46 lệnh thua liên tiếp: -120,789 USD (gần như toàn bộ vốn)
- R/R xấu: lỗ trung bình (-581 USD) ≈ 4.75× lời trung bình (122 USD)
- Drawdown > 100%: drawdown của Balance và Equity vượt 100% → tài khoản gần về 0
- Gross Loss > Gross Profit: 410,918 lỗ so với 309,895 lời
From the ReportTester-11280950 backtest analysis:
- A 46-trade losing streak: -120,789 USD (almost the whole account)
- Poor R/R: average loss (-581 USD) ≈ 4.75× average profit (122 USD)
- Drawdown > 100%: Balance and Equity drawdown exceeded 100% → the account nearly reached zero
- Gross Loss > Gross Profit: 410,918 loss vs 309,895 profit
Cơ chế bảo vệ 1: Max Drawdown ProtectionProtection 1: Max Drawdown Protection
| Input mớiNew input | KiểuType | Ý nghĩaMeaning |
|---|---|---|
InpMaxDrawdownEnable | bool | Bật/tắt bảo vệ drawdownEnable/disable drawdown protection |
InpMaxDrawdownPercent | double | Ngưỡng drawdown % (0-100)Drawdown threshold in % (0-100) |
InpMaxDrawdownUSD | double | Ngưỡng drawdown USD (0 = tắt)Drawdown threshold in USD (0 = off) |
InpMaxDrawdownCloseAll | bool | True = đóng hết lệnh khi vượt; False = chỉ dừng mở lệnh mớiTrue = close all positions when breached; False = only stop opening new ones |
Logic:
- Theo dõi
g_equityPeak(equity cao nhất từ đầu phiên). - Mỗi tick: tính drawdown =
(equityPeak - equity) / equityPeak * 100. - Khi drawdown ≥
InpMaxDrawdownPercenthoặc ≥InpMaxDrawdownUSD:- Đặt
g_maxDrawdownTriggered = true - Nếu
InpMaxDrawdownCloseAll = true: đóng hết lệnh - Nếu
false: chỉ chặn mở lệnh mới (vẫn cho Tia/Clear Stuck đóng lệnh)
- Đặt
- Reset khi equity phục hồi vượt peak.
Mục đích: tránh drawdown quá sâu (>100%) như trong backtest.
Logic:
- Track
g_equityPeak(highest equity since the session started). - Every tick: drawdown =
(equityPeak - equity) / equityPeak * 100. - When drawdown ≥
InpMaxDrawdownPercentor ≥InpMaxDrawdownUSD:- Set
g_maxDrawdownTriggered = true - If
InpMaxDrawdownCloseAll = true: close all positions - If
false: only block new orders (Tia/Clear Stuck may still close positions)
- Set
- Reset once equity recovers above the peak.
Purpose: avoid excessively deep drawdowns (>100%) like the one in the backtest.
Cơ chế bảo vệ 2: Max Loss Per DayProtection 2: Max Loss Per Day
| Input mớiNew input | KiểuType | Ý nghĩaMeaning |
|---|---|---|
InpMaxLossPerDayEnable | bool | Bật/tắt giới hạn lỗ theo ngàyEnable/disable the daily loss limit |
InpMaxLossPerDayUSD | double | Ngưỡng lỗ tối đa trong ngày ($)Maximum loss per day ($) |
Logic:
- Theo dõi
g_balanceAtDayStart(balance lúc 00:00 giờ server). - Mỗi tick: tính
profitInDay = Balance - balanceAtDayStart. - Khi
profitInDay <= -InpMaxLossPerDayUSD: đặtg_maxLossPerDayTriggered = true→ chặn mở lệnh mới. - Reset mỗi ngày mới (00:00 giờ server).
- Reset cờ khi trong ngày có lời (
profitInDay > 0).
Mục đích: giới hạn rủi ro theo ngày, tránh một ngày lỗ quá lớn tích tụ thành chuỗi thua.
Logic:
- Track
g_balanceAtDayStart(balance at 00:00 server time). - Every tick:
profitInDay = Balance - balanceAtDayStart. - When
profitInDay <= -InpMaxLossPerDayUSD: setg_maxLossPerDayTriggered = true→ block new orders. - Reset at each new day (00:00 server time).
- Reset the flag when the day turns profitable (
profitInDay > 0).
Purpose: cap risk per day, so one very bad day does not snowball into a losing streak.
Tích hợp vào OnTick()Integration into OnTick()
// Risk Management: kiểm tra max drawdown và max loss per day
CheckMaxDrawdown();
CheckMaxLossPerDay();
// Chỉ cho phép mở lệnh mới khi không vượt ngưỡng rủi ro
if (!g_maxDrawdownTriggered && !g_maxLossPerDayTriggered) {
ProcessNewBarEntries();
ProcessAddEntries();
CheckLotBalance();
}
(Chú thích trong code: "kiểm tra max drawdown và max loss per day"; "chỉ cho phép mở lệnh mới khi không vượt ngưỡng rủi ro".)(Code comments: "check max drawdown and max loss per day"; "only allow new orders while no risk threshold is breached".)
Hành vi:
- Khi vượt ngưỡng: chặn mở lệnh mới (Init/Add/Lot Balance).
- Vẫn cho phép: Tia đóng cụm, Clear Stuck, Global TP/SL, Hedge (để giảm exposure và phục hồi).
Behavior:
- When a threshold is breached: block new orders (Init/Add/Lot Balance).
- Still allowed: Tia cluster close, Clear Stuck, Global TP/SL, Hedge (to reduce exposure and recover).
Điều chỉnh tham số trong file setParameter changes in the set file
File: GoldenRobber_hybrid.setFile: GoldenRobber_hybrid.set
| Input | TrướcBefore | SauAfter | Lý doReason |
|---|---|---|---|
InpTiaProfitUSD | 5.0 | 3.0 | Đóng cụm sớm hơn để giảm thời gian giữ lệnh và giảm tích luỹ lệnh "xa" trong cụmClose clusters earlier to cut holding time and the build-up of "far" orders inside a cluster |
InpGlobalSLClearStuckDistancePips | 80 | 60 | Clear lệnh kẹt sớm hơnClear stuck orders sooner |
InpGlobalSLClearStuckMaxLossPctOfDayProfit | 50.0 | 65.0 | Cho phép clear khi tổng lỗ ≤ 65% lời trong ngày → clear được nhiều lệnh kẹt hơnAllow clearing when total loss ≤ 65% of the day's profit → more stuck orders can be cleared |
InpTiaProfitUSD=3.0 (trước: 5.0)
InpGlobalSLClearStuckDistancePips=60 (trước: 80)
InpGlobalSLClearStuckMaxLossPctOfDayProfit=65.0 (trước: 50.0)
Set file mới: GoldenRobber_hybrid.setNew set file: GoldenRobber_hybrid.set
Các tham số Risk Management:Risk Management parameters:
InpMaxDrawdownEnable=true
InpMaxDrawdownPercent=80.0
InpMaxDrawdownUSD=0
InpMaxDrawdownCloseAll=false
InpMaxLossPerDayEnable=true
InpMaxLossPerDayUSD=5000.0
- Max Drawdown 80%: dừng mở lệnh mới khi equity drawdown ≥ 80% từ peak (tránh >100% như backtest).
- Max Loss Per Day 5000 USD: dừng mở lệnh mới khi lỗ trong ngày ≥ 5000 USD.
- CloseAll = false: chỉ chặn mở lệnh mới, không đóng hết (để Tia/Clear Stuck có cơ hội phục hồi).
- Max Drawdown 80%: stop opening new orders when equity drawdown ≥ 80% from peak (avoiding >100% as in the backtest).
- Max Loss Per Day 5000 USD: stop opening new orders when the day's loss ≥ 5000 USD.
- CloseAll = false: only block new orders, do not close everything (so Tia/Clear Stuck get a chance to recover).
Kỳ vọng cải thiệnExpected improvements
- Giảm drawdown cực đại: từ >100% xuống ≤80% nhờ hard stop.
- Giảm chuỗi thua lớn: Max Loss Per Day giới hạn lỗ trong ngày, tránh tích tụ thành chuỗi 46 lệnh -120k.
- Cải thiện R/R: Tia đóng sớm hơn (3 USD) và Clear Stuck sớm hơn (60 pips) → giảm lỗ trung bình, tăng lời trung bình.
- Giảm thời gian giữ lệnh kẹt: Clear Stuck với MaxLossPct 65% → clear được nhiều lệnh kẹt hơn khi có lời trong ngày.
- Lower maximum drawdown: from >100% to ≤80% thanks to the hard stop.
- Fewer large losing streaks: Max Loss Per Day caps the daily loss, avoiding a 46-trade -120k streak.
- Better R/R: Tia closes earlier (3 USD) and Clear Stuck acts earlier (60 pips) → smaller average loss, larger average profit.
- Less time holding stuck orders: Clear Stuck with MaxLossPct 65% → more stuck orders cleared on profitable days.
Test lạiRe-testing
- Backtest lại cùng giai đoạn (2026.01.19 - 2026.02.16) với set file
GoldenRobber_hybrid.set. - So sánh: max drawdown có giảm xuống <80%? Còn chuỗi thua lớn (-120k) không? Lỗ trung bình có giảm, lời trung bình có tăng? Profit Factor có cải thiện từ 0.75?
- Điều chỉnh nếu cần: vẫn drawdown cao → giảm
InpMaxDrawdownPercentxuống 70% hoặc 60%; vẫn có chuỗi thua → giảmInpMaxLossPerDayUSDxuống 3000-4000; Tia đóng quá sớm → tăngInpTiaProfitUSDlên 3.5-4.0.
- Re-run the backtest on the same period (2026.01.19 - 2026.02.16) with the
GoldenRobber_hybrid.setfile. - Compare: did max drawdown fall below 80%? Is the large losing streak (-120k) still there? Did average loss shrink and average profit grow? Did Profit Factor improve from 0.75?
- Adjust if needed: drawdown still high → lower
InpMaxDrawdownPercentto 70% or 60%; still losing streaks → lowerInpMaxLossPerDayUSDto 3000-4000; Tia closing too early → raiseInpTiaProfitUSDto 3.5-4.0.
Các file đã thay đổi (02/2026)Files changed (02/2026)
MQL5/Experts/GoldenRobber/GoldenRobber.mq5- Thêm input Risk Management (dòng ~127-133)
- Thêm biến toàn cục
g_equityPeak,g_maxDrawdownTriggered,g_maxLossPerDayTriggered(dòng ~177-179) - Khởi tạo trong
OnInit()(dòng ~778-780) - Thêm hàm
CheckMaxDrawdown()(sauCheckGlobalSLClearStuck()) - Thêm hàm
CheckMaxLossPerDay()(sauCheckMaxDrawdown()) - Cập nhật
OnTick()để gọi các hàm và chặn mở lệnh mới khi vượt ngưỡng (dòng ~2380-2390)
MQL5/Experts/GoldenRobber/GoldenRobber_hybrid.set- Thêm section Risk Management
- Giảm
InpTiaProfitUSD: 5.0 → 3.0 - Giảm
InpGlobalSLClearStuckDistancePips: 80 → 60 - Tăng
InpGlobalSLClearStuckMaxLossPctOfDayProfit: 50.0 → 65.0
Kết luận: đã thêm các cơ chế bảo vệ rủi ro để khắc phục các nguyên nhân thua lỗ chính (chuỗi thua lớn, drawdown >100%, R/R xấu). Cần backtest lại để xác nhận hiệu quả.
MQL5/Experts/GoldenRobber/GoldenRobber.mq5- Added the Risk Management inputs (lines ~127-133)
- Added globals
g_equityPeak,g_maxDrawdownTriggered,g_maxLossPerDayTriggered(lines ~177-179) - Initialized in
OnInit()(lines ~778-780) - Added
CheckMaxDrawdown()(afterCheckGlobalSLClearStuck()) - Added
CheckMaxLossPerDay()(afterCheckMaxDrawdown()) - Updated
OnTick()to call them and block new orders when a threshold is breached (lines ~2380-2390)
MQL5/Experts/GoldenRobber/GoldenRobber_hybrid.set- Added a Risk Management section
- Lowered
InpTiaProfitUSD: 5.0 → 3.0 - Lowered
InpGlobalSLClearStuckDistancePips: 80 → 60 - Raised
InpGlobalSLClearStuckMaxLossPctOfDayProfit: 50.0 → 65.0
Conclusion: risk-protection mechanisms were added to address the main causes of loss (large losing streaks, drawdown >100%, poor R/R). A new backtest is needed to confirm they work.
Phần 2 — Option 1 (sửa code) vs Option 2 (chỉnh file set): xử lý lệnh kẹt / lệnh xaPart 2 — Option 1 (code change) vs Option 2 (set-file tuning): handling stuck / far orders
Nguồn: docs/Phân tích Option 1 vs Option 2 - lệnh kẹt.md (không ghi ngày; cùng thời kỳ với phần 1).Source: docs/Phân tích Option 1 vs Option 2 - lệnh kẹt.md (undated; same period as part 1).
Config ổn định tắt Clear Stuck: InpGlobalSLClearStuckEnable=false (các giá trị còn lại: DistancePips=250, Mode=1 WorstOnly, MaxLossPctOfDayProfit=35.0, ProfitPeriod=0, EmergencyPips=0) và bật InpTiaPrioritizeByDistance=true. Sau thời điểm tài liệu này, Clear Stuck có thêm InpGlobalSLClearStuckProfitPeriod (Daily/Weekly) và InpGlobalSLClearStuckEmergencyPips; xem Clear Stuck Orders và Tia. Tài liệu không cho biết Option 1A/1B đã được triển khai hay chưa.
The stable config turns Clear Stuck off: InpGlobalSLClearStuckEnable=false (remaining values: DistancePips=250, Mode=1 WorstOnly, MaxLossPctOfDayProfit=35.0, ProfitPeriod=0, EmergencyPips=0) and enables InpTiaPrioritizeByDistance=true. After this note was written, Clear Stuck gained InpGlobalSLClearStuckProfitPeriod (Daily/Weekly) and InpGlobalSLClearStuckEmergencyPips; see Clear Stuck Orders and Tia. The note does not say whether Option 1A/1B was ever implemented.
Mục tiêuGoal
- Option 1: sửa code để GoldenRobber gom các lệnh kẹt vào cụm, khi có lời thì tỉa cùng lúc.
- Option 2: chỉnh file set theo đề xuất (bật Global SL Clear Stuck + tham số phù hợp).
- Option 1: change the code so GoldenRobber groups stuck orders into a cluster and trims them together once there is profit.
- Option 2: tune the set file as proposed (enable Global SL Clear Stuck + suitable parameters).
Option 1 — hiện trạng trong codeOption 1 — current code behavior
- Tia (cụm): chỉ đóng khi tổng P/L của cụm ≥
InpTiaProfitUSD(vd $5). Mọi tổ hợp có lệnh "xa" (lỗ lớn) đều có tổng âm → không bao giờ đạt target → không đóng được. - Flexible partial close: chạy khi vừa có lệnh lời vừa có lệnh lỗ. Dùng lời để tạo "budget", rồi tỉa lỗ (đã ưu tiên lệnh xa nếu
InpTiaPrioritizeByDistance = true). Khi chỉ có lệnh một phía và toàn lỗ (vd 7 Sell, 0 Buy) thì không có lời → không có budget → không tỉa được.
- Tia (cluster): closes only when the cluster's total P/L ≥
InpTiaProfitUSD(e.g. $5). Any combination that includes a "far" order (large loss) sums negative → never reaches the target → cannot close. - Flexible partial close: runs when there are both winning and losing positions. Profit creates a "budget", which is then used to trim losers (far orders first if
InpTiaPrioritizeByDistance = true). When only one side is open and all of it is losing (e.g. 7 Sells, 0 Buys) there is no profit → no budget → nothing can be trimmed.
1A. Ưu tiên cụm có nhiều lệnh "xa" khi duyệt mask (khuyến nghị)1A. Prefer clusters with more "far" orders during the mask scan (recommended)
Ý tưởng: khi có nhiều tổ hợp cùng thoả sum ≥ minTarget, thay vì đóng tổ hợp đầu tiên tìm được, chọn tổ hợp chứa nhiều lệnh "xa" (theo khoảng cách giá) nhất, để khi có lời ta "tỉa" cả lệnh kẹt xa cùng lúc.
Cách làm:
- Duyệt mask như hiện tại.
- Với mỗi mask thoả điều kiện (kiểu BotDCA, sum ≥ minTarget), tính "điểm ưu tiên" = số lệnh lỗ trong cụm có khoảng cách tới giá hiện tại ≥ ngưỡng (vd dùng
InpGlobalSLClearStuckDistancePipshoặc một input riêng). - Chọn mask có điểm ưu tiên cao nhất (ưu tiên cụm có nhiều lệnh xa).
- Đóng cụm đó (đóng lời trước, tỉa lỗ trong budget như hiện tại).
Ưu: không thay đổi điều kiện "có lời mới đóng"; chỉ thay đổi chọn cụm nào khi có nhiều cụm đạt target → gom lệnh kẹt vào cụm được tỉa khi có lời.
Nhược: cần thêm biến lưu "best mask" và một vòng tính khoảng cách; khi lệnh > 14 thì vẫn bị giới hạn TIA_MAX_POSITIONS.
Idea: when several combinations satisfy sum ≥ minTarget, instead of closing the first one found, pick the one containing the most "far" orders (by price distance), so that when there is profit the far stuck orders get trimmed at the same time.
How:
- Scan masks as today.
- For each qualifying mask (BotDCA style, sum ≥ minTarget), compute a "priority score" = the number of losing orders in the cluster whose distance to the current price ≥ a threshold (e.g.
InpGlobalSLClearStuckDistancePipsor a dedicated input). - Choose the mask with the highest priority score (prefer clusters with many far orders).
- Close that cluster (winners first, then trim losers within budget as today).
Pros: the "close only with profit" rule is unchanged; only which cluster gets chosen changes when several reach the target → stuck orders are grouped into the cluster that gets trimmed with profit.
Cons: needs an extra "best mask" variable and a distance loop; with more than 14 orders it is still bounded by TIA_MAX_POSITIONS.
1B. Tăng "budget" tỉa lỗ trong Flexible partial close1B. Enlarge the loss-trimming "budget" in Flexible partial close
Ý tưởng: hiện tại budget = P_sum - minTarget - 0.50. Có thể thêm tuỳ chọn (vd chỉ khi bật ưu tiên xa): cho phép budget = P_sum - X với X nhỏ (vd 0 hoặc 1) để dùng gần như toàn bộ lời tỉa lỗ → tỉa được nhiều lệnh xa hơn trong một lần.
Ưu: khi đã có lời + lỗ, "tỉa cùng lúc" mạnh hơn, đặc biệt với lệnh xa (đã sắp theo khoảng cách).
Nhược: net sau khi đóng còn rất ít (chỉ còn X USD), dễ bị trượt giá/commission làm lệch; cần test kỹ.
Idea: today budget = P_sum - minTarget - 0.50. An option could be added (e.g. only when distance priority is on) to allow budget = P_sum - X with a small X (e.g. 0 or 1), spending almost all the profit on trimming losers → more far orders trimmed in one pass.
Pros: once there is both profit and loss, trimming together is more aggressive, especially for far orders (already sorted by distance).
Cons: the net after closing is tiny (only X USD left), easily skewed by slippage/commission; needs careful testing.
1C. Không giải quyết trường hợp "toàn lỗ một phía"1C. Does not solve the "all losing on one side" case
Khi chỉ còn một phía và toàn lỗ (vd 7 Sell, 0 Buy), không có lệnh lời → không có cụm nào đạt target và không có budget tỉa lỗ. Option 1 (gom cụm + tỉa khi có lời) không thay đổi được tình huống này; cần cơ chế khác (vd Global SL Clear Stuck).When only one side remains and all of it is losing (e.g. 7 Sells, 0 Buys), there are no winners → no cluster reaches the target and there is no trimming budget. Option 1 (cluster grouping + trim with profit) cannot change this situation; another mechanism is needed (e.g. Global SL Clear Stuck).
Kết luận Option 1Option 1 conclusion
- Làm được: ưu tiên cụm có nhiều lệnh xa (1A) + có thể nới budget tỉa lỗ (1B) → khi có cả lời và lỗ thì "gom lệnh kẹt vào cụm" và tỉa chúng cùng lúc khi có lời.
- Không thay thế được: khi toàn lỗ một phía, vẫn cần Global SL Clear Stuck (hoặc chấp nhận giữ lệnh đến khi phía kia có lời).
- Achievable: prefer clusters with many far orders (1A) + optionally widen the trimming budget (1B) → when there is both profit and loss, stuck orders are grouped into a cluster and trimmed together with profit.
- Not a replacement: when one side is all losing you still need Global SL Clear Stuck (or accept holding until the other side is profitable).
Option 2 — cơ chế Global SL Clear StuckOption 2 — the Global SL Clear Stuck mechanism
| Input | Ý nghĩaMeaning |
|---|---|
InpGlobalSLClearStuckEnable = true | Bật clear lệnh kẹtEnables clearing stuck orders |
InpGlobalSLClearStuckDistancePips | Coi lệnh là "xa" khi giá đã đi xa mức mở lệnh ≥ N pips (vd 80)An order counts as "far" when price has moved ≥ N pips from its open (e.g. 80) |
InpGlobalSLClearStuckMaxLossPctOfDayProfit | Chỉ clear khi tổng lỗ (floating) ≤ X% lời trong ngày (đã chốt) — tránh clear khi đang thua nặngClear only when total (floating) loss ≤ X% of the day's (realized) profit — avoids clearing on a heavy losing day |
InpGlobalSLClearStuckMode:InpGlobalSLClearStuckMode:
| Mode | TênName | Hành viBehavior |
|---|---|---|
| 0 | All | Đóng hếtClose everything |
| 1 | WorstOnly | Chỉ đóng 1 lệnh lỗ lớn nhấtClose only the single worst losing order |
| 2 | FarOnly | Chỉ đóng những lệnh "xa" (giá đã đi ≥ DistancePips so với từng lệnh)Close only "far" orders (price moved ≥ DistancePips from each one) |
| 3 | SameSideOnly | Chỉ đóng cùng phía với lệnh lỗ lớn nhất (tất cả Buy hoặc tất cả Sell)Close only the side of the worst loser (all Buys or all Sells) |
| 4 | FarPartial | Partial close lệnh "xa" trong giới hạn % day profitPartially close "far" orders within the % of day profit limit |
Trạng thái file GoldenRobber_test.set (đã kiểm tra lúc đó)State of GoldenRobber_test.set (checked at the time)
File set lúc đó đã có:The set file at the time already contained:
InpGlobalSLClearStuckEnable=true
InpGlobalSLClearStuckDistancePips=80
InpGlobalSLClearStuckMode=2
InpGlobalSLClearStuckMaxLossPctOfDayProfit=50
→ Clear Stuck đã được bật và cấu hình đúng hướng (Mode 2 FarOnly: chỉ clear lệnh xa, và chỉ khi tổng lỗ ≤ 50% lời trong ngày).→ Clear Stuck was already on and configured in the right direction (Mode 2 FarOnly: only far orders, and only when total loss ≤ 50% of the day's profit).
Gợi ý chỉnh thêm (tuỳ chọn)Optional further tuning
- DistancePips: 80 phù hợp XAUUSD; nếu muốn "xa" hơn mới clear thì tăng (vd 100).
- Mode: giữ 2 (FarOnly) nếu chỉ muốn đóng lệnh thật sự xa; chuyển 4 (FarPartial) nếu muốn partial close lệnh xa trong giới hạn % day profit (ít "sốc" hơn so với đóng hết lệnh xa).
- MaxLossPctOfDayProfit: 50 là cân bằng; giảm (vd 30) nếu chỉ muốn clear khi ngày đó lời nhiều hơn.
- DistancePips: 80 suits XAUUSD; raise it (e.g. 100) if orders should be "farther" before clearing.
- Mode: keep 2 (FarOnly) to close only truly far orders; switch to 4 (FarPartial) to partially close far orders within the % of day profit limit (less of a "shock" than closing all far orders).
- MaxLossPctOfDayProfit: 50 is balanced; lower it (e.g. 30) to clear only on days with more profit.
Kết luận Option 2Option 2 conclusion
- Không cần sửa code; chỉ cần chỉnh set (và set lúc đó đã gần đúng).
- Clear Stuck xử lý được cả trường hợp toàn lỗ một phía (7 Sell, 0 Buy): khi giá đã đi xa lệnh lỗ lớn nhất và thoả điều kiện % day profit thì đóng (theo mode đã chọn).
- No code change needed; only the set file (and the set at the time was already close).
- Clear Stuck also handles the all-losing-one-side case (7 Sells, 0 Buys): once price is far from the worst loser and the % of day profit condition holds, it closes (per the chosen mode).
So sánh nhanhQuick comparison
| Tiêu chíCriterion | Option 1 (sửa code)Option 1 (code change) | Option 2 (chỉnh set)Option 2 (set tuning) |
|---|---|---|
| Gom lệnh kẹt, tỉa khi có lờiGroup stuck orders, trim with profit | CóYes (nếu làm 1A + 1B)(with 1A + 1B) | KhôngNo (Tia vẫn chỉ clear cụm đạt target; Clear Stuck là cơ chế riêng)(Tia still clears only clusters that hit target; Clear Stuck is a separate mechanism) |
| Xử lý khi toàn lỗ một phíaHandles all-losing-one-side | KhôngNo (vẫn cần Clear Stuck)(still needs Clear Stuck) | CóYes (Clear Stuck đóng lệnh xa khi đủ điều kiện)(Clear Stuck closes far orders when conditions hold) |
| Rủi ro / độ phức tạpRisk / complexity | Cao hơn (logic mới, test nhiều)Higher (new logic, lots of testing) | Thấp (chỉ tham số)Low (parameters only) |
| Thời gian triển khaiTime to deliver | Nhiều (code + test)Long (code + test) | Ít (chỉnh set, có thể tinh chỉnh sau)Short (tune the set, refine later) |
Đề xuấtRecommendation
- Ưu tiên Option 2: giữ/hoàn thiện file set với Clear Stuck như trên (đã có sẵn trong test set). Đủ để xử lý lệnh "xa"/kẹt, kể cả khi toàn lỗ một phía.
- Nếu muốn "gom lệnh kẹt vào cụm và tỉa cùng lúc khi có lời": làm thêm Option 1A (ưu tiên mask có nhiều lệnh xa); Option 1B chỉ nên xem xét sau khi backtest kỹ. Option 1 không thay thế Option 2 cho trường hợp toàn lỗ một phía.
- Prefer Option 2: keep/refine the set file with Clear Stuck as above (already present in the test set). It is enough to handle far/stuck orders, including the all-losing-one-side case.
- If you want to "group stuck orders into a cluster and trim them together with profit": also build Option 1A (prefer masks with many far orders); consider Option 1B only after thorough backtesting. Option 1 does not replace Option 2 for the all-losing-one-side case.
Phần 3 — Ghi chú fork GoldenRobber v1.41.1 (14/07/2026)Part 3 — GoldenRobber v1.41.1 fork notes (14/07/2026)
Nguồn: docs/GoldenRobber-1.41.1-NOTES.md.Source: docs/GoldenRobber-1.41.1-NOTES.md.
Cả hai tính năng của 1.41.1 (InpDCAPosEnable/InpDCANegEnable và InpDCAMinPipsMode) vẫn có trong EA production 1.42 b7. Config ổn định pass58 dùng đúng hướng "DCANeg off" được đề xuất test ở đây: trend TF M3 (InpTrendFilterTF=3), InpDCANegEnable=false, InpDCAPosEnable=true, InpDCAMinPipsMode=0 (Fixed; các giá trị Pivot còn lại PivotTF=20, PivotK=1.0, Floor=5 không có tác dụng). Nhận định "config M3 vẫn là họ dễ cháy" bên dưới là kết luận của 07/2026; kết quả backtest về sau của pass58 xem tại So sánh backtest và Phân tích pass58.
Both 1.41.1 features (InpDCAPosEnable/InpDCANegEnable and InpDCAMinPipsMode) are still in the production EA 1.42 b7. The stable pass58 config follows the "DCANeg off" direction proposed for testing here: M3 trend TF (InpTrendFilterTF=3), InpDCANegEnable=false, InpDCAPosEnable=true, InpDCAMinPipsMode=0 (Fixed; the remaining Pivot values PivotTF=20, PivotK=1.0, Floor=5 have no effect). The statement below that "M3 configs remain the blow-up-prone family" is a 07/2026 conclusion; for pass58's later backtest results see Backtest comparison and pass58 analysis.
Nền & tương thíchBase & compatibility
- Nền: fork từ v1.41 (Multi-TF Trend Confirm), KHÔNG có stair-step (1.42–1.47).
- File:
GoldenRobber-1.41.1.mq5/.ex5· Compile: 0 errors. - Ngày: 2026-07-14.
- Tương thích ngược: mặc định
MinPipsMode=Fixed,DCAPosEnable=DCANegEnable=true→ chạy y hệt 1.41. Chỉ khi opt-in mới đổi hành vi.
- Base: forked from v1.41 (Multi-TF Trend Confirm), WITHOUT stair-step (1.42–1.47).
- File:
GoldenRobber-1.41.1.mq5/.ex5· Compile: 0 errors. - Date: 2026-07-14.
- Backward compatibility: defaults
MinPipsMode=Fixed,DCAPosEnable=DCANegEnable=true→ behaves exactly like 1.41. Behavior changes only when you opt in.
Lưu ý: "1.42–1.47" ở đây là nhánh stair-step thử nghiệm của tháng 07/2026, không phải bản production 1.42 b7 hiện tại (xem Build & release).Note: "1.42–1.47" here refers to the experimental stair-step line of 07/2026, not today's production build 1.42 b7 (see Builds & releases).
Compile có 1 warning vô hại: version '1.41.1' incompatible with MQL5 Market, must be xxx.yyy. Chỉ ảnh hưởng nếu publish lên MQL5 Market (EA này private → bỏ qua). Muốn hết warning → đổi sang version 2 phần (vd 2.00).
The compile has 1 harmless warning: version '1.41.1' incompatible with MQL5 Market, must be xxx.yyy. It matters only when publishing to the MQL5 Market (this EA is private → ignore). To silence it, switch to a two-part version (e.g. 2.00).
1. Bật/tắt nhóm DCA (tiết kiệm CPU)1. DCA branch on/off switches (save CPU)
| Input | Default | Ý nghĩaMeaning |
|---|---|---|
InpDCAPosEnable | true | false = KHÔNG bồi DCAPos (bỏ qua nhánh add trong vòng lặp)false = NO DCAPos adds (skip the add branch in the loop) |
InpDCANegEnable | true | false = KHÔNG bồi DCANeg (bỏ qua nhánh add trong vòng lặp)false = NO DCANeg adds (skip the add branch in the loop) |
- Tắt một nhánh → EA bỏ qua toàn bộ xử lý add của nhánh đó mỗi tick (SR check,
IsNearSupportResistance…) → tiết kiệm CPU. - KHÔNG đụng lệnh đang mở của nhánh đó (TP/close vẫn quản lý bình thường) — chỉ chặn MỞ THÊM.
- KHÔNG ảnh hưởng Init (mở round mới) — chỉ ảnh hưởng ADD (bồi trong round).
- Trường hợp dùng: config như pass10-hybrid, nếu DCANeg hiếm khi khớp →
InpDCANegEnable=falseđể gọn + nhẹ.
- Disabling a branch → the EA skips all add processing for that branch every tick (SR check,
IsNearSupportResistance…) → saves CPU. - Open positions of that branch are NOT touched (TP/close still managed normally) — only NEW adds are blocked.
- Init (opening a new round) is NOT affected — only ADDs (averaging within a round).
- Use case: a config like pass10-hybrid where DCANeg rarely fires →
InpDCANegEnable=falsefor a leaner, lighter EA.
2. Flexible MinPips (khoảng cách ADD: cố định hoặc động theo pivot)2. Flexible MinPips (ADD spacing: fixed or pivot-driven)
| Input | Default | Ý nghĩaMeaning |
|---|---|---|
InpDCAMinPipsMode | Fixed (0) | Fixed = InpDCAPos/NegMinPips cố định (như cũ); Pivot = khoảng cách độngFixed = fixed InpDCAPos/NegMinPips (as before); Pivot = dynamic spacing |
InpDCAMinPipsPivotTF | H4 | TF lấy pivot range. H4 = swing intraday (khuyến nghị); H1 sát hơn (nhiều lệnh); D1 rộng hơn (ít lệnh)TF for the pivot range. H4 = intraday swing (recommended); H1 tighter (more orders); D1 wider (fewer orders) |
InpDCAMinPipsPivotK | 1.0 | Hệ số × (nửa range pivot). Lớn = khoảng cách rộng hơnMultiplier × (half the pivot range). Larger = wider spacing |
InpDCAMinPipsFloor | 12 | Sàn tối thiểu (pips) — lọc nhiễu spread. Chỉ dùng khi mode=PivotMinimum floor (pips) — filters spread noise. Used only when mode=Pivot |
Công thức (mode=Pivot):Formula (mode=Pivot):
MinPips = max(Floor, K × half-pivot-range(TF))
- Dùng pivot Classic:
R1 − S1 = range kỳ trước→ base = nửa range đó, quy ra pips, cache 1 lần/bar. - Chỉ áp cho khoảng cách ADD (2 nhánh DCAPos/DCANeg). Khoảng cách Init-round giữ cố định (không đổi hành vi mở round).
- Tự thích ứng theo biến động: vàng chạy mạnh → range lớn → khoảng cách giãn → ít lệnh ngược trend bị kẹt hơn; thị trường êm → khoảng cách sát → dọn nhanh.
- Uses the Classic pivot:
R1 − S1 = previous period's range→ base = half of that range, converted to pips, cached once per bar. - Applies only to ADD spacing (both DCAPos/DCANeg branches). Init-round spacing stays fixed (round-opening behavior unchanged).
- Self-adapts to volatility: gold moving hard → large range → wider spacing → fewer counter-trend orders get stuck; calm market → tighter spacing → faster clean-up.
Config test sẵn sàngReady-made test config
ScalpingTrending-pass10-1.41.1-DCANegOff-14072026.set — nền pass10-hybrid + DCANeg tắt + MinPipsMode Fixed (cô lập biến DCANeg-off để so sánh).ScalpingTrending-pass10-1.41.1-DCANegOff-14072026.set — pass10-hybrid base + DCANeg off + MinPipsMode Fixed (isolates the DCANeg-off variable for comparison).
Cách test đề xuất (đổi 1 biến mỗi lần)Suggested test plan (one variable at a time)
- Baseline: pass10 gốc trên EA 1.41.1 (mọi default) → phải bằng pass10 cũ.
- DCANeg off: config trên (
DCANegEnable=false) → so profit/DD với baseline. Nếu ~giống → DCANeg đúng là "vô dụng" ở đây, tắt được để nhẹ. - Pivot MinPips: đổi
InpDCAMinPipsMode=1, giữ TF=H4, K=1.0 → backtest 2023-2026, dựng lại equity DD, so với Fixed. Xem cú 05/02/2025 có nông đi không, whipsaw có tệ đi không. - Tinh chỉnh
PivotK(0.7–1.5) vàPivotTF(H1/H4/D1) nếu bước 3 có triển vọng.
- Baseline: original pass10 on EA 1.41.1 (all defaults) → must equal the old pass10.
- DCANeg off: the config above (
DCANegEnable=false) → compare profit/DD with the baseline. If roughly equal → DCANeg really is "useless" here and can be switched off for a lighter EA. - Pivot MinPips: set
InpDCAMinPipsMode=1, keep TF=H4, K=1.0 → backtest 2023-2026, reconstruct equity DD, compare with Fixed. Check whether the 05/02/2025 dip gets shallower and whether whipsaw gets worse. - Tune
PivotK(0.7–1.5) andPivotTF(H1/H4/D1) if step 3 looks promising.
Lưu ý bản chất (từ điều tra trước đó)Fundamental caveats (from earlier investigation)
- Khoảng cách MinPips là đòn bẩy THỨ CẤP — không thay được cách sửa gốc về regime (Trend TF). Config pass10 (M3) vẫn là họ dễ cháy; khoảng cách linh hoạt chỉ giảm nhẹ, không chữa.
- So sánh phải dùng equity DD dựng lại (reconstruct) — không tin DD của optimizer (pass10 báo 35% nhưng thật 76%).
- MinPips spacing is a SECONDARY lever — it cannot replace the root regime fix (Trend TF). The pass10 (M3) config is still the blow-up-prone family; flexible spacing only mitigates, it does not cure.
- Comparisons must use reconstructed equity DD — do not trust the optimizer's DD (pass10 reported 35% but was really 76%).