MT5 Grid EA with Auto Re-Anchor, Anti-Failure Logic, and Global Take Profit System

Job finished

Execution time 12 days
Feedback from customer
approved! thank you Rodrigue
Feedback from employee
Happy to work with you

Specification

💼 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:

    1. There are no open BUY positions, and

    2. 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:

  1. Cancel all pending BUY LIMITs for that Magic Number.

  2. Recalculate AnchorHigh (check for new top using the rules above).

  3. 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.


Magic (ulong)
AnchorTF (ENUM_TIMEFRAMES)
BarsLookback (int)
ReanchorThrPct (double)
LevelsCount (int)
LevelPct1..10 (double)
Lot1..10 (double)
TP_Percent (double)
PriceTolPts (int)
ModifyTolPts (int)
DeviationPts (int)

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

  1. Compiles cleanly (0 errors/warnings) on MetaEditor 5.

  2. 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.

  3. 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.). 



Responded

1
Developer 1
Rating
(18)
Projects
22
9%
Arbitration
6
33% / 50%
Overdue
1
5%
Working
2
Developer 2
Rating
(4)
Projects
5
20%
Arbitration
1
100% / 0%
Overdue
0
Free
3
Developer 3
Rating
(160)
Projects
285
35%
Arbitration
18
22% / 61%
Overdue
42
15%
Loaded
4
Developer 4
Rating
(14)
Projects
19
11%
Arbitration
1
0% / 100%
Overdue
5
26%
Free
5
Developer 5
Rating
(1)
Projects
3
0%
Arbitration
0
Overdue
0
Free
6
Developer 6
Rating
(308)
Projects
553
35%
Arbitration
79
32% / 42%
Overdue
200
36%
Loaded
7
Developer 7
Rating
Projects
0
0%
Arbitration
1
0% / 100%
Overdue
0
Free
8
Developer 8
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
9
Developer 9
Rating
(1)
Projects
2
0%
Arbitration
1
0% / 100%
Overdue
0
Free
Published: 2 codes
10
Developer 10
Rating
(350)
Projects
421
54%
Arbitration
20
55% / 15%
Overdue
29
7%
Working
11
Developer 11
Rating
(16)
Projects
20
0%
Arbitration
10
0% / 80%
Overdue
6
30%
Free
12
Developer 12
Rating
(252)
Projects
258
30%
Arbitration
0
Overdue
3
1%
Free
Published: 2 codes
13
Developer 13
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
Similar orders
I have an existing MT5 Expert Advisor (“E-Core”). I need an experienced MQL5 developer to integrate a structured risk management upgrade and a higher timeframe trend filter into the current code. Two files will be provided: 1️⃣ E-Core Source Code (Current Version) 2️⃣ Update Instructions File (contains exact inputs, functions, and logic to integrate) The developer must: Integrate the update logic
DO NOT RESPOND TO WORK WITH ANY AI. ( I CAN ALSO DO THAT ) NEED REAL DEVELOPING SKILL Hedge Add-On Rules for Existing EA Core Idea SL becomes hypothetical (virtual) for the initial basket and for the hedge basket . When price hits the virtual SL level , EA does not close the losing trades. Instead, EA opens one hedge basket in the opposite direction. Original basket direction Hedge basket direction (opposite) Inputs
Billionflow 30 - 100 USD
Trading specifications: Indicators: Bollinger band ( Period 40, Deviation 1 apply to close) Moving Average (Exponential ) Period 17 applied to high Moving Average ( Exponential ) Period 17 applied to low But Signal enter a buy trade when prices crosses the lower band of the bollinger band up and also crosses the moving average channel of high and low the reverse is true for sell signal
Hello, I am a user of the "BUY STOP SELL STOP V6" trading bot, which is an advanced Grid System bot. The bot is primarily designed for Gold (XAUUSD), but I want it to work on all currency pairs. "The bot contains a privacy/protection code that prevents it from running on other accounts or being modified on any platform, as it has a client account number lock mechanism" --- Bot Description & Current Settings Bot Type
I am looking for a highly experienced Pine Script v5 developer to build a professional, non repaint price action indicator for TradingView. or a ready made one so i can purchase. This is a structured two phase project. The goal is to create a clean, intelligent price action tool that works for both fast intraday trading and swing trading. Only apply if you have strong Pine experience and understand liquidity
Hello, I’m looking for an experienced MQL4/MQL5 developer to work with me on an ongoing basis. My clients request services such as: Converting TradingView Pine Script indicators/strategies into MT4 or MT5 Expert Advisors Converting MT4 EAs to MT5 (and MT5 to MT4) Compiling and fixing existing MQL4 / MQL5 EA code Adding simple features like alerts, SL/TP, lot size, and basic money management This job is for
I am looking someone to create an EA based on my MACD Histo indicator / strategy from Pinescript. I will send it to you for you to replicate. The EA shall have: - Divergence length in bars, min and max values. - Pivot Logic - Entry on close of divergence confirmation bar. - Dynamic lot size dependent on SL/TP, in monetary value. - SL / TP in percent away from entry, separate values for long and short. - Time, day and
Hello, I have a breakout EA with reversal logic. I own the full source code for both MT4 and MT5 versions. I need the modifications implemented for both MT4 and MT5 versions. I need several modifications: – Multiple reversals with configurable parameters – Breakeven functionality – Entry only after candle close beyond range + offset – Time-based activation – Alternative offset calculation logic – Automatic close at
simple automated trading system with adaptive risk management and trend-based execution. The EA manages trades with dynamic position handling and built-in stability filters. Designed for single-position trading and disciplined execution 30 usd budget
PROJECT DESCRIPTION Looking for 1 experienced MQL5 developer to build 2 Expert Advisors for MetaTrader 5, targeting XAUUSD and major currency pairs. Strong preference for a single developer handling both EAs to maximize code reuse, reduce cost, and ensure consistency. EA1 — Grid Martingale Pro · Buy/Sell grid with Fixed or ATR Dynamic distance (ATR read once per fill, stored in grid_step_at_open[]) · Gap

Project information

Budget
50+ USD