MQL5 Expert Advisor Modification: Pyramid and Re-Entry Trade Manager

Auftrag beendet

Ausführungszeit 1 Tag
Bewertung des Kunden
Great developer
Bewertung des Entwicklers
Great client! Clear communication, patient, professional. Pleasure to work with. Recommended!

Spezifikation

General Idea of the Trading Strategy / EA Functionality

This order is for modifying and completing an existing MQL5 Expert Advisor (EA) that acts as a trade manager for user-opened "master" trades ( trades opened by another EA or user that has a stop loss as at trade open, it could be a stop or limit order or even a market execution). The EA does not generate trading signals or open/modify/close master trades itself—masters are always opened by the user or another EA. Instead, the EA automates pyramid pending orders (additional entries at stepped levels), manages their fills and closures, arms re-entries when pyramid positions close at a loss, and handles re-placement of re-entry pendings when price retraces. The goal is to create a "pyramiding with re-entry" structure that adds positions in the direction of the master trade while providing risk management through breakeven trailing and lot adjustments based on losses.

The underlying concept is a position management system for trend-following or momentum trades: after a master is opened, the EA builds a pyramid of pending stop orders at calculated levels beyond the master's entry (spaced by a multiple of the master's stop loss distance). If a pyramid position closes (e.g., at SL), and it's a loss, the EA "arms" a re-entry mechanism at that level. When price retraces to the prior level, it places a pending order to re-enter at the original pyramid level, with reduced lot size to account for the loss. This allows recovery from drawdowns while limiting risk through lot reduction and breakeven moves.

Key abstractions:

  • Master Trade: A user-opened position that the EA monitors but never touches.
  • Pyramid Levels: Stepped entry prices calculated from the master's SL distance, where pending stops are placed.
  • Re-Entry: An armed pending order mechanism triggered by price retrace after a pyramid loss, allowing limited re-attempts at the same level.

This is not a full trading robot but a management overlay. The existing code (provided as .mq5 source) already implements core features like master detection, pyramid placement, fill mapping, persistence via GlobalVariables, and fallbacks for broker issues (e.g., reticketing). However, specific bugs and incomplete parts (detailed in "What Needs to Be Done") prevent reliable re-entry arming and triggering, especially across restarts.

For visualization, refer to the following conceptual flow (text-based; developer can request charts if needed):

  1. User opens Master (e.g., BUY at 1.1000, SL at 1.0950 → slDist = 50 pips).
  2. EA places Pyramid Level 1: BUY_STOP at 1.1000 + (50 * PyramidingStepR), e.g., 1.1025 if StepR=0.5.
  3. On fill: Map position to master/level.
  4. If pyramid closes at loss: Arm re-entry with trigger at master entry (1.1000), entry at 1.1025, reduced lot.
  5. When price >= trigger (1.1000): Place pending BUY_STOP at 1.1025 (shifted if needed for stops level).

Recommended reading for context: MQL5 articles on OnTradeTransaction, GlobalVariables for persistence, and handling broker reticketing.

Terms and Definitions

To ensure clarity, here are key terms used in this specification. All prices are normalized using NormalizeDouble(price, _Digits) for storage and comparisons. Use bold for these terms in code comments.

  • Master Trade: A position opened externally (user/other EA) with MAGIC_TEST magic number that has a stop loss as at trade open, it could be a stop or limit order or even a market execution. Identified by ticket/position ID. EA monitors its open_price, sl, tp, lot, direction (is_long=true for BUY).
  • Pyramid Pending Order: A pending STOP order (BUY_STOP for long masters, SELL_STOP for short) placed at calculated level_price. SL/TP inherited from master distances.
  • Level (N): 1-based integer for pyramid steps. Formula: level_price(N) = master_open + sign * (slDist * PyramidingStepR * N), where sign=+1 for BUY, -1 for SELL; slDist = |master_open - master_sl|.
  • Re-Entry: A structure armed after a pyramid loss, containing triggerPrice (prior level or master open), entryPrice (closed level's price), lot (reduced), remaining attempts (up to MaxReentriesPerLevel).
  • Mapping: Association of pending/order/position to master and level. Primary: ticket-based; Fallback: price-nearest within FallbackTolerancePoints * _Point.
  • Persistence: Storage via GlobalVariables (e.g., EA_pos<symbol>&#x3C;POSITION_ID> = "masterTicket|level|entryPrice" as string) to survive terminal restarts.</symbol>
  • Reticketing: Broker assigns new ticket after OrderSend; detect by scanning OrdersTotal() for matching price/volume/time.
  • Shift-Outwards: Adjust pending price to satisfy SYMBOL_TRADE_STOPS_LEVEL (stop_gap = level * _Point): For BUY_STOP, max(entry_price, Ask + stop_gap); For SELL_STOP, min(entry_price, Bid - stop_gap).
  • Breakeven Buffer: spread * BreakevenBufferSpreads added to prior level for SL move (e.g., for BUY: prior_entry + buffer).
  • Loss Count: Per-master counter incremented on pyramid loss; resets on master close. Used in lot = master.lot * PyramidLotMultiplier * pow(LotSizeReductionFactor, loss_count + (profit<0?1:0)).
  • Unmatched: Queue for fills/closes without immediate mapping; persisted as EA_nomap<symbol>_&#x3C;POSITION_ID> = entryPrice; rescanned in ProcessUnmatched().</symbol>

Input parameters (exact names, types, defaults, ranges):

  • EnableTrading (bool) = true: Global enable/disable.
  • TestLots (double) = 0.01: Lot for optional test master.
  • TestSL_Pips (double) = 50: SL pips for test.
  • TestTP_Pips (double) = 150: TP pips for test.
  • PyramidingStepR (double) = 0.5: Step multiplier (0.1 to 3.0+).
  • PyramidLotMultiplier (double) = 0.5: Base lot multiplier.
  • LotSizeReductionFactor (double) = 0.9: Reduction per loss.
  • BreakevenBufferSpreads (double) = 1.5: Buffer multiplier.
  • UseStructureForTrailing (bool) = true: True=continuous trailing; False=one-time on next fill.
  • MaxReentriesPerLevel (int) = 10: Max re-attempts per level.
  • PatchMaxRetries (int) = 5: Order send retries.
  • PatchTestMode (bool) = false: Force triggers for testing.
  • MaxPyramidLevels (int) = 100: Max levels.
  • FallbackTolerancePoints (int) = 50: Price match tolerance (was 200; reduce for accuracy).
  • PersistenceEnabled (bool) = true: Enable globals.

Description of Setup Preceding Actions

The EA starts in OnInit by loading persisted states (pendings, positions, unmatched) via GlobalVariables. It scans PositionsTotal() for existing masters (magic == MAGIC_TEST). If none, optionally places a test master if PatchTestMode. For each master, it builds pyramid pendings if not already present (up to MaxPyramidLevels).

Events triggering actions:

  • New master detected: Place pyramid pendings at levels 1+.
  • Pending fill (TRADE_TRANSACTION_DEAL_ADD, ENTRY_IN): Map to master/level, persist.
  • Pyramid close (ENTRY_OUT): If loss, arm re-entry for that level.
  • Price retrace (OnTimer, 1s): Check armed re-entries; if triggered, place pending.
  • Any error/reticket: Retry with backoff; fallback match if needed.

Signal / Event Descriptions

No traditional "signals" as this is a manager, but events:

  • Pyramid Placement Event: On new master or level availability. Condition: Master exists, level N not placed/filled. Action: Compute level_price, place pending with SL/TP from master dists.
  • Fill Mapping Event: On DEAL_ENTRY_IN with MAGIC_PYRAMID. Condition: Match ticket to pendingPyramids[] (primary) or price/history (fallback). Action: Create positionMap entry, persist as string, add to master's pyramidPositions[].
  • Close Arming Event: On DEAL_ENTRY_OUT. Condition: Mapped position, profit < 0. Action: Arm re-entry with trigger = prior level (or master if level=1), entry = closed level, lot reduced, remaining = MaxReentriesPerLevel.
  • Re-Entry Trigger Event: OnTimer, price >= trigger (BUY) or <= (SELL). Condition: Armed, remaining >0, no pending. Action: Place pending at entryPrice (shifted), decrement remaining.
  • Trailing Event: On new pyramid fill. If UseStructureForTrailing=true: Move all prior SLs to prior levels + buffer. Else: Move immediate prior to its entry + buffer.

Lifetime: Re-entries persist until remaining=0 or master closes (remove all related). Pendings/mappings persist via globals indefinitely unless master closes.

Placing of Orders and Opening of Positions

  • Use OrderSendAsync for pendings (BUY_STOP/SELL_STOP).
  • SL/TP: slDist/tpDist from master.
  • Lot: For pyramids = master.lot * PyramidLotMultiplier; For re-entries = adjusted by loss_count.
  • On success: Persist ticket→level, detect reticket.
  • Retries: Exponential backoff (500ms base, up to PatchMaxRetries).
  • Abort if slDist < stop_gap: Log ERROR, skip.

Management of Trading Positions/Orders

  • Trailing: As above, enforce stop_gap, move SL outward only.
  • Breakeven: +buffer to prior entry.
  • Monitor floating P/L: No, closes by SL/TP or manual.
  • Partial fills: Map each positionID separately to same level.

Cancellation of Orders and Closing of Positions

  • Cancel: On master close (remove all pendings/re-entries for that master).
  • Close: Positions close by SL/TP (EA doesn't close them).
  • Re-entry cancel: If remaining=0 or master gone.

Order Lot Calculation

Fixed for initial pyramids; reduced for re-entries via formula. No MM yet (fixed lot base).

Processing Trading Errors and Environment State

  • Log all: Use PrintFormat with tags (DEBUG-PENDING, DEBUG-FILL, etc.).
  • Errors: Analyze return codes, log ERROR: with code/desc.
  • Restarts: Load globals in OnInit; keep on Deinit.
  • Notifications: None; rely on journal.
  • Bar vs Tick: Use OnTradeTransaction for events, OnTimer(1s) for checks (bar-opening friendly).

Difference Between Bar-Opening and In-Bar Trading

Operate on ticks (OnTradeTransaction) for fills/closes; timer for triggers (in-bar ok, not scalping).

Important Aspects

  • Defensive: Bounds checks, Select() verifies, backward array removes.
  • Testing: Provide README with tester scripts for acceptance (pyramid place, fill map, close arm, retrace place, restart recovery).
  • No grid/martingale: Pure pyramid with limited re-entries.
  • Developer: Provide full source/ex5, debugging guide (log tags), minimal license server if requested.

What is Contained in the Existing Code (Current Implemented Features)

  • Master load/reload in OnInit.
  • Pyramid placement with retries/reticketing.
  • Fill mapping (primary/fallback) in OnTradeTransaction.
  • Persistence load/save for pendings/positions/unmatched.
  • Re-entry arming on close (primary/fallback).
  • Re-entry placement in OnTimer with shift-outwards.
  • Trailing in PlacePyramid/TrailTo.
  • Extensive logging/tags.

What Needs to Be Done (Modifications and Fixes)

Prioritized fixes to complete re-entry functionality:

  1. Update SavePosGlobal/LoadPosGlobals to store/parse string "masterTicket|level|entryPrice"; always load without skipping if master absent.
  2. Remove skips in LoadPosGlobals for missing masters; keep mappings persistent.
  3. Add ResolvePendingPositionMaps() in OnInit/OnTick to link loaded mappings to masters when they appear.
  4. Add masterTicket to ReEntry struct; use FindManagedTradeIndexByTicket for checks.
  5. Reduce fallback tolerance to 50 points everywhere.
  6. Ensure atomicity: Use local tickets, more debugs around mutations.
  7. Update OnTradeTransaction SavePosGlobal calls to pass full params.
  8. Add periodic DebugDumpPositionMap in OnTimer (debug mode).
  9. Verify/Delete globals with new formats.
  10. Implement acceptance tests in README (step-by-step with expected logs).

Deliverables: Updated .mq5/.ex5, README with tests/guide, short changelog.

Budget/Time: [To be discussed; initial estimate based on fixes]. Provide questions on unclear points before starting.


Bewerbungen

1
Entwickler 1
Bewertung
(17)
Projekte
21
10%
Schlichtung
4
50% / 50%
Frist nicht eingehalten
1
5%
Arbeitet
2
Entwickler 2
Bewertung
(14)
Projekte
18
17%
Schlichtung
5
40% / 40%
Frist nicht eingehalten
0
Frei
3
Entwickler 3
Bewertung
(21)
Projekte
27
4%
Schlichtung
4
0% / 0%
Frist nicht eingehalten
3
11%
Arbeitet
4
Entwickler 4
Bewertung
(452)
Projekte
788
48%
Schlichtung
70
17% / 53%
Frist nicht eingehalten
139
18%
Arbeitet
5
Entwickler 5
Bewertung
(102)
Projekte
158
21%
Schlichtung
23
9% / 78%
Frist nicht eingehalten
16
10%
Arbeitet
6
Entwickler 6
Bewertung
(305)
Projekte
546
35%
Schlichtung
79
32% / 42%
Frist nicht eingehalten
196
36%
Arbeitet
7
Entwickler 7
Bewertung
(13)
Projekte
13
38%
Schlichtung
1
0% / 100%
Frist nicht eingehalten
1
8%
Frei
8
Entwickler 8
Bewertung
(28)
Projekte
31
10%
Schlichtung
13
8% / 69%
Frist nicht eingehalten
0
Überlastet
9
Entwickler 9
Bewertung
(9)
Projekte
18
39%
Schlichtung
5
0% / 40%
Frist nicht eingehalten
3
17%
Beschäftigt
10
Entwickler 10
Bewertung
(24)
Projekte
30
13%
Schlichtung
12
0% / 67%
Frist nicht eingehalten
8
27%
Arbeitet
11
Entwickler 11
Bewertung
(12)
Projekte
19
42%
Schlichtung
3
0% / 67%
Frist nicht eingehalten
3
16%
Frei
12
Entwickler 12
Bewertung
(7)
Projekte
12
17%
Schlichtung
12
17% / 50%
Frist nicht eingehalten
3
25%
Frei
Veröffentlicht: 10 Artikel
13
Entwickler 13
Bewertung
(13)
Projekte
19
32%
Schlichtung
6
33% / 50%
Frist nicht eingehalten
0
Frei
14
Entwickler 14
Bewertung
(57)
Projekte
89
43%
Schlichtung
4
0% / 100%
Frist nicht eingehalten
3
3%
Arbeitet
15
Entwickler 15
Bewertung
(7)
Projekte
8
13%
Schlichtung
5
40% / 20%
Frist nicht eingehalten
0
Frei
16
Entwickler 16
Bewertung
(1)
Projekte
1
0%
Schlichtung
2
0% / 0%
Frist nicht eingehalten
0
Arbeitet
17
Entwickler 17
Bewertung
(3)
Projekte
1
100%
Schlichtung
3
0% / 100%
Frist nicht eingehalten
0
Frei
18
Entwickler 18
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
19
Entwickler 19
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
20
Entwickler 20
Bewertung
(247)
Projekte
253
30%
Schlichtung
0
Frist nicht eingehalten
3
1%
Frei
Veröffentlicht: 2 Beispiele
21
Entwickler 21
Bewertung
(25)
Projekte
29
21%
Schlichtung
20
10% / 50%
Frist nicht eingehalten
8
28%
Arbeitet
22
Entwickler 22
Bewertung
(176)
Projekte
227
19%
Schlichtung
20
40% / 20%
Frist nicht eingehalten
0
Arbeitet
23
Entwickler 23
Bewertung
(491)
Projekte
954
75%
Schlichtung
26
19% / 65%
Frist nicht eingehalten
100
10%
Beschäftigt
Veröffentlicht: 1 Artikel, 6 Beispiele
24
Entwickler 24
Bewertung
Projekte
0
0%
Schlichtung
0
Frist nicht eingehalten
0
Frei
Ähnliche Aufträge
I am looking of an Expert Advisor (EA) that has undergone independent validation and demonstrates a capability to successfully navigate prop firm challenges, as well as efficiently manage funded accounts. It is imperative that you provide a comprehensive explanation of the strategy utilized by your EA, along with a demo version that has a 30-day expiration. This will facilitate extensive back testing and forward
Hellow,l hope you are well,l am writing to place an order for a professional trading robot.l am looking for a reliable,well optimized robot that can trade efficiently,manage risk properly and deliver consistent performance in the market,I am particularly interested in a trading robot that uses a proven and transparent strategy,has strong risk management features,works well on common trading platforms,is suitable for
I am looking for an experienced MQL5 developer to build a professional MT5 software (indicator or semi-automated EA) for metals and major forex pairs. 📌 PLATFORM & MARKETS Platform: MetaTrader 5 Instruments: XAUUSD (Gold vs USD) XAGUSD (Silver vs USD) EURUSD GBPUSD USDJPY Trading styles: Scalping Intraday / short-term swing 🎯 MAIN OBJECTIVE I do NOT want an aggressive fully automated robot. I want a
The robot will take buy trades when the 2 ema cross over the 10 ema and price has closed above the 50 ema. The take profit and stop loss can be set as an optional level by the user. The robot will take sell trades when the 2 ema cross under the 10 ema and price has closed under the 50 ema. The take profit and stop loss can be set as an optional level by the user. The entry timeframe will be 15 minutes, but it could
I want to check if this indicator is repainting or not Whick mean the results of back testing is legit or not if anyone can help me to review it kindly to well to contact me i will be happy to work and go on long term work with anyone thanks
Specifications – Development of an MQL5 Expert Advisor (Reverse Engineering) Project context: I have access to a real trading history consisting of more than 500 trades executed over a period of approximately 3 years. These trades have been exported into a CSV file containing all available information, including date, time, symbol, order type, entry price, and exit price. Important: I do not have access to the
1.Sinyal Perdagangan : Sinyal beli: garis MACD utama memotong garis sinyal ke atas (macd_current>signal_current && macd_previous<signal_previous). Sinyal jual: garis MACD utama memotong garis sinyal ke bawah (macd_current<signal_current && macd_previous>signal_previous). Gambar di bawah menunjukkan kasus beli dan jual. 2. Posisi ditutup pada sinyal yang berlawanan: Posisi beli ditutup pada sinyal jual, dan posisi
Trading Bot Executes Trades on Specific Days via TradingView Alerts **As a** trader, **I want** to develop a trading bot that integrates with TradeLocker and MTS, **So that** when a TradingView alert (based on a 2,4,5,10,15,30 minute break and retest strategy whichever one) is triggered first. the bot will execute trades on both platforms, but only on specific days of the week. --- ## Acceptance Criteria 1
Project Description I am looking to collaborate with an experienced MQL5 / algorithmic trading developer who also has hands-on experience with Large Language Models (LLMs) and AI-driven systems. This is a long-term partnership opportunity , not a one-off paid freelance job. I bring 9 years of practical Elliott Wave trading experience , applied in live market conditions. The objective is to translate Elliott Wave
Hello, I’m looking for an experienced MT4 (MQL4) developer to convert the Lucky Reversal indicator from indicatorspot.com into a fully functional Expert Advisor (EA). Project Scope Code an MT4 EA that replicates the exact logic and signals of the Lucky Reversal indicator Trades should open and close automatically based on the indicator’s rules Must match indicator behavior 1:1 (no approximations) EA Requirements MT4

Projektdetails

Budget
100 - 150 USD