Работа завершена
Техническое задание
💼 Job Description (full text for MQL5 Jobs)
Project Overview
I need a MetaTrader 5 Expert Advisor (MQL5, Hedge account) that executes a grid-based anti-failure strategy.
The EA should anchor at the latest top (highest high), place BUY LIMIT orders at predefined retracement levels, and close all positions simultaneously when the average price reaches a global Take Profit target (in %).
After the global closure (TP, SL, or manual), the EA must cancel all remaining pending orders, re-anchor automatically to the latest high, and rebuild the entire grid.
⚠️ I already have a partial version of this system.
The main issue to fix is: when one trade closes at TP, other pending orders remain stuck on the chart.
I need it to close everything, reset, and start over cleanly after each cycle.
Strategy Logic
1. Anchor Logic (Top Reference)
-
Anchor at the highest high of a user-defined timeframe (e.g. D1) within a defined lookback period (e.g. 10,000 bars).
-
Re-anchor only if:
-
There are no open BUY positions, and
-
A new high ≥ (previous_anchor * (1 + ReanchorThrPct / 100)) occurs.
-
-
While any BUY position remains open, the anchor must not change.
-
After all positions close, the EA checks for a new high and rebuilds the grid.
2. Grid Placement (BUY LIMIT Orders)
-
Up to 10 levels, each with:
-
LevelPctN → retracement % from anchor top
-
LotN → fixed lot size for that level
-
-
BUY LIMIT price = AnchorHigh * (1 - LevelPctN/100)
-
Prevent duplicates:
If a pending order already exists within PriceTolPts (price tolerance in points), do not resend it. -
Orders use DeviationPts (slippage/deviation setting).
3. Global Take Profit by Average Price
-
When one or more BUY positions are open (same Magic Number), calculate volume-weighted average entry price.
-
Set global Take Profit = AvgPrice * (1 + TP_Percent / 100)
-
All open BUY trades must share this same TP.
-
If the difference between current TP and target TP > ModifyTolPts , the EA updates all positions’ TP accordingly.
4. Reset & Re-Arm Sequence
After all BUY positions are closed:
-
Cancel all pending BUY LIMITs for that Magic Number.
-
Recalculate AnchorHigh (check for new top using the rules above).
-
Rebuild the grid with the same parameters from the new anchor.
This reset must also trigger if trades close via TP, SL, or manual closure.
Use OnTradeTransaction with DEAL_ENTRY_OUT to detect when all positions are closed.
Technical Requirements
-
Must be coded in pure MQL5 (no MT4 or conversion).
-
Must use CTrade (Trade/Trade.mqh) and OnTradeTransaction.
-
Fully compatible with Hedge accounts.
-
Must compile with 0 errors and 0 warnings on the latest MT5 build.
-
Handle different symbol digits/points (e.g., XAUUSD, BTCUSD).
-
Must run and optimize properly in "Every tick based on real ticks" mode.
-
Include clear internal logs for:
-
Anchor/re-anchor detection
-
Grid creation/deletion
-
TP updates
-
Reset/Re-arm events
-
Acceptance Criteria
-
Compiles cleanly (0 errors/warnings) on MetaEditor 5.
-
In a visual backtest, the EA must:
-
Place BUY LIMIT grid at the anchor top.
-
When one or more trades hit TP → close all open positions + cancel all pending orders.
-
Re-anchor to the next valid top and rebuild the grid automatically.
-
Not re-anchor while trades are still open.
-
Avoid duplicate pending orders within PriceTolPts .
-
Update global TP properly when average entry changes.
-
-
Works consistently on XAUUSD, BTCUSD, and other CFD pairs.
Deliverables
-
One .mq5 file (full source code, well-commented).
-
Short “readme” with:
-
How to attach EA to chart
-
Recommended test settings
-
Suggested parameters for XAUUSD and BTCUSD (H1, 10/20/30/40/55 retracements, lots 0.01–0.03, TP=12%).
-
-
30-day bug fix period after delivery (minor corrections included).
Optional (Nice to Have)
-
Option for partial close (close X% of positions at an intermediate TP).
-
CSV export of anchor, TP, and deal data.
-
Backtest cost simulation (spread/commission/slippage).
What to Include in Proposal
-
Links or screenshots of previous MT5 EAs using OnTradeTransaction .
-
Confirmation that all acceptance criteria will be met.
-
Delivery time and final price.
🟢 Notes from client (Wily Machado):
I already have partial working logic, but compilation and event handling keep failing.
The goal is a stable, clean, and testable EA that can run long-term safely with low drawdown and consistent profits.
If you deliver that, I’ll likely hire you again for optimization and advanced modules (partial exits, trailing TP, etc.).