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

工作已完成

执行时间1 一天
客户反馈
Great developer
员工反馈
Great client! Clear communication, patient, professional. Pleasure to work with. Recommended!

指定

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.


反馈

1
开发者 1
等级
(17)
项目
21
10%
仲裁
4
50% / 50%
逾期
1
5%
工作中
2
开发者 2
等级
(14)
项目
18
17%
仲裁
5
40% / 40%
逾期
0
空闲
3
开发者 3
等级
(21)
项目
27
4%
仲裁
4
0% / 0%
逾期
3
11%
工作中
4
开发者 4
等级
(452)
项目
788
48%
仲裁
70
17% / 53%
逾期
139
18%
工作中
5
开发者 5
等级
(102)
项目
158
21%
仲裁
23
9% / 78%
逾期
16
10%
工作中
6
开发者 6
等级
(305)
项目
546
35%
仲裁
79
32% / 42%
逾期
196
36%
工作中
7
开发者 7
等级
(13)
项目
13
38%
仲裁
1
0% / 100%
逾期
1
8%
空闲
8
开发者 8
等级
(28)
项目
31
10%
仲裁
13
8% / 69%
逾期
0
繁忙
9
开发者 9
等级
(9)
项目
18
39%
仲裁
5
0% / 40%
逾期
3
17%
已载入
10
开发者 10
等级
(24)
项目
30
13%
仲裁
12
0% / 67%
逾期
8
27%
工作中
11
开发者 11
等级
(12)
项目
19
42%
仲裁
3
0% / 67%
逾期
3
16%
空闲
12
开发者 12
等级
(7)
项目
12
17%
仲裁
12
17% / 50%
逾期
3
25%
空闲
发布者: 9 文章
13
开发者 13
等级
(13)
项目
19
32%
仲裁
6
33% / 50%
逾期
0
空闲
14
开发者 14
等级
(57)
项目
89
43%
仲裁
4
0% / 100%
逾期
3
3%
工作中
15
开发者 15
等级
(7)
项目
8
13%
仲裁
5
40% / 20%
逾期
0
空闲
16
开发者 16
等级
(1)
项目
1
0%
仲裁
2
0% / 0%
逾期
0
工作中
17
开发者 17
等级
(3)
项目
1
100%
仲裁
3
0% / 100%
逾期
0
空闲
18
开发者 18
等级
项目
0
0%
仲裁
0
逾期
0
空闲
19
开发者 19
等级
项目
0
0%
仲裁
0
逾期
0
空闲
20
开发者 20
等级
(247)
项目
253
30%
仲裁
0
逾期
3
1%
空闲
发布者: 2 代码
21
开发者 21
等级
(25)
项目
29
21%
仲裁
20
10% / 50%
逾期
8
28%
工作中
22
开发者 22
等级
(176)
项目
227
19%
仲裁
20
40% / 20%
逾期
0
工作中
23
开发者 23
等级
(491)
项目
954
75%
仲裁
26
19% / 65%
逾期
100
10%
已载入
发布者: 1 文章, 6 代码
24
开发者 24
等级
项目
0
0%
仲裁
0
逾期
0
空闲
相似订单
Boeta 40+ USD
Trade make the market look easy check update show me the lost and profits show me my profit I made show canddle step by step explain show traders marking the profits show time difference between the countries
I am seeking an experienced freelance marketing and algorithmic trading specialist to develop a user-friendly automated trading bot for the Pocket Option platform. The system should feature a simple and secure interface that allows direct login using my existing credentials. The bot will be designed to operate exclusively on multiple OTC currency pairs (a minimum of 10, such as EUR/USD OTC, GBP/JPY OTC, and similar
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
GoldTrade EA 30 - 60 USD
Hi, I am looking for someone who has already developed a high-performance Gold EA that can outperform the one shown in my screenshot. If you have such an EA, please apply for this job. Please describe how the EA works (for example, whether it uses a grid system) and provide backtest results along with the set files. If the EA meets my expectations, you can make the necessary adjustments and I will use it as my own
I am looking for someone who has or who can modify the Margin Trader EA by MaryJane preferably the MT5 version by making it pyramid using a fixed lot size addition(preferably 1st trade lot size) instead of using all the margin available to define the lotsize
Create simple EA 30 - 60 USD
Start BUY:- when i click start BUY button new panel should open which should contain bellow points:- Trigger Price Time frame Cross/Close RR ration Trailing Stop ratio Maximum Trade count Risk (percentage or cash) (Option to Increase risk when SL hit) Remove Trigger (True/False ) I will explain above point one by one here bellow •Trigger price :- here we enter price at which when market cross or
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
PrimeFlowEA — v1 Specification Objective: PrimeFlowEA v1 is designed to enforce disciplined, rule-based execution within a single daily trading session. The goal of v1 is correct behavior and execution discipline , not optimization or performance tuning. 1. Market & Time Platform: MetaTrader 5 (MQL5) Symbol(s): User-selectable (single symbol per chart) Execution timeframe: Configurable (default: M5 / M15)
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

项目信息

预算
100 - 150 USD