MT5 Safety EA: Close Oldest Losing Trade On Low Margin Level (Pepperstone, 30:1, Fixed Grid)

MQL5 Experts

Tâche terminée

Temps d'exécution 4 heures
Commentaires du client
Superb service. Andrey delivered a flawless system in half a day — no revisions needed. Fast, professional, and highly skilled. He’s now my go-to MQL5 developer. Strongly recommended.
Commentaires de l'employé
Thanks for the project. Looking forward to the next one!

Spécifications

I need a simple but reliable safety EA for MetaTrader 5 (MQL5) to protect my account from margin calls while running multiple Dark Gold EAs on Pepperstone UK.

My setup

– Broker: Pepperstone UK
– Platform: MT5
– Stop-out: 50%
– Leverage: 30:1
– Strategy: Several Dark Gold EAs (around 6 charts). Each uses a fixed grid with no martingale, for example: 0.01, 0.01, 0.01 … up to about 15 positions. All grid positions are equal lot size.

Goal of the EA

I want a separate safety EA that I attach to ONE chart only. It does not open trades. It only:

– Monitors account margin level
– When margin level gets too low (for example 80%), it closes exactly ONE trade: the oldest losing trade
– Waits a configurable cooldown time
– Repeats if needed, until margin improves or there are no more trades

Reasoning

Because I use a fixed grid with equal lot size, the oldest trades are usually the ones furthest away from the current price and doing the most damage to the basket’s average entry and take profit. Closing the oldest losing trade removes the “tail” of the grid and pulls the basket TP closer to current price, so a smaller retrace can clean up the rest.

Functional requirements

  1. Attachment and scope
    – EA runs on exactly one chart (any symbol).
    – It monitors all open positions on the whole account, not just the chart symbol.
    – It must be compatible with running multiple Dark Gold EAs in parallel.

  2. Margin level trigger
    – On every tick, the EA reads ACCOUNT_MARGIN_LEVEL (percentage).
    – Input: MarginLevelThreshold (double, default 80.0).
    – If margin level > threshold: do nothing.
    – If margin level <= threshold: trigger the close logic.

  3. Trade selection logic
    – EA scans all open positions.
    – Optional filter by Magic Number:
    – Input: MagicFilter (long, default -1).
    – If MagicFilter = -1: manage all trades.
    – If MagicFilter = some value: manage only trades with that magic.
    – Optional filter “only losing trades”:
    – Input: OnlyCloseLosing (bool, default true).
    – If true: only trades with POSITION_PROFIT < 0 are considered.
    – From the remaining eligible trades, select the oldest by POSITION_TIME.
    – Close exactly that one position.

  4. Closing and cooldown
    – After closing one position successfully, the EA must wait a minimum cooldown time before closing another, even if margin is still low.
    – Input: CooldownSeconds (int, default 5).
    – The idea is a “slow bleed” of risk, not an instant flush of the whole account.

  5. Notifications
    – Input: SendPushNotifications (bool, default true).
    – If enabled, when the EA closes a position it should send SendNotification() with: ticket, symbol, volume, and margin level at the moment of closing.
    – Also log this clearly in the Experts tab.

  6. Safety conditions
    – The EA must not open trades.
    – It must not modify SL/TP of existing trades.
    – It must only close trades as per the margin logic above.
    – It must not freeze or block the terminal (no heavy loops).

Inputs (must be configurable in EA parameters)

– MarginLevelThreshold (double, default 80.0)
– OnlyCloseLosing (bool, default true)
– CooldownSeconds (int, default 5)
– MagicFilter (long, default -1)
– SendPushNotifications (bool, default true)
– Optional: BrokerStopOutLevel (double, default 50.0) just for logging / information

Example behaviour

– Margin level at 300%: EA does nothing.
– Margin level falls to 82%: still above 80%, EA does nothing.
– Margin level drops to 80% or below:
– EA scans eligible trades (respecting MagicFilter and OnlyCloseLosing).
– Picks the oldest losing trade by POSITION_TIME.
– Closes this single trade.
– Logs it and optionally sends a push notification.
– Starts a cooldown (for example 5 seconds).
– After the cooldown, if margin is still <= threshold, it repeats and closes the next oldest losing trade.
– This continues until margin recovers above threshold or there are no more eligible positions.

Deliverables

– MQL5 source code (.mq5) with clear comments.
– Compiles and runs cleanly on latest MT5 build.
– Brief explanation in comments or text where:
– Margin level is checked
– Oldest losing trade is selected
– Cooldown is managed
– MagicFilter is applied


Répondu

1
Développeur 1
Évaluation
(18)
Projets
22
9%
Arbitrage
6
33% / 50%
En retard
1
5%
Chargé
2
Développeur 2
Évaluation
(104)
Projets
169
24%
Arbitrage
23
9% / 78%
En retard
16
9%
Travail
3
Développeur 3
Évaluation
(328)
Projets
510
19%
Arbitrage
33
45% / 30%
En retard
34
7%
Chargé
4
Développeur 4
Évaluation
(60)
Projets
87
29%
Arbitrage
24
13% / 58%
En retard
7
8%
Travail
5
Développeur 5
Évaluation
(16)
Projets
35
23%
Arbitrage
4
0% / 50%
En retard
2
6%
Travail
6
Développeur 6
Évaluation
(2)
Projets
3
0%
Arbitrage
0
En retard
0
Gratuit
7
Développeur 7
Évaluation
(1)
Projets
2
0%
Arbitrage
1
0% / 100%
En retard
1
50%
Gratuit
8
Développeur 8
Évaluation
(144)
Projets
186
41%
Arbitrage
24
58% / 21%
En retard
13
7%
Gratuit
9
Développeur 9
Évaluation
(509)
Projets
977
74%
Arbitrage
27
19% / 67%
En retard
101
10%
Gratuit
Publié : 1 article, 6 codes
10
Développeur 10
Évaluation
Projets
0
0%
Arbitrage
0
En retard
0
Gratuit
11
Développeur 11
Évaluation
(4)
Projets
6
17%
Arbitrage
2
0% / 100%
En retard
3
50%
Gratuit
12
Développeur 12
Évaluation
Projets
0
0%
Arbitrage
0
En retard
0
Gratuit
13
Développeur 13
Évaluation
(271)
Projets
553
50%
Arbitrage
57
40% / 37%
En retard
227
41%
Travail
14
Développeur 14
Évaluation
(311)
Projets
557
35%
Arbitrage
79
32% / 43%
En retard
202
36%
Travail
15
Développeur 15
Évaluation
(10)
Projets
15
27%
Arbitrage
0
En retard
3
20%
Gratuit
16
Développeur 16
Évaluation
Projets
0
0%
Arbitrage
0
En retard
0
Gratuit
17
Développeur 17
Évaluation
(10)
Projets
19
42%
Arbitrage
6
0% / 50%
En retard
3
16%
Travail
18
Développeur 18
Évaluation
(16)
Projets
20
0%
Arbitrage
10
0% / 80%
En retard
6
30%
Gratuit
19
Développeur 19
Évaluation
(24)
Projets
30
13%
Arbitrage
12
0% / 75%
En retard
8
27%
Gratuit
20
Développeur 20
Évaluation
Projets
0
0%
Arbitrage
0
En retard
0
Gratuit
21
Développeur 21
Évaluation
Projets
2
0%
Arbitrage
4
25% / 50%
En retard
1
50%
Gratuit
22
Développeur 22
Évaluation
(627)
Projets
989
47%
Arbitrage
33
36% / 36%
En retard
98
10%
Travail
Publié : 6 codes
23
Développeur 23
Évaluation
(266)
Projets
598
35%
Arbitrage
64
20% / 58%
En retard
147
25%
Gratuit
Publié : 1 article, 22 codes
24
Développeur 24
Évaluation
(162)
Projets
287
34%
Arbitrage
18
22% / 61%
En retard
42
15%
Travail
25
Développeur 25
Évaluation
(3)
Projets
1
100%
Arbitrage
3
0% / 100%
En retard
0
Gratuit
26
Développeur 26
Évaluation
(40)
Projets
47
28%
Arbitrage
14
21% / 64%
En retard
1
2%
Occupé
27
Développeur 27
Évaluation
(255)
Projets
262
30%
Arbitrage
0
En retard
3
1%
Gratuit
Publié : 2 codes
28
Développeur 28
Évaluation
(6)
Projets
5
0%
Arbitrage
2
50% / 50%
En retard
2
40%
Gratuit
29
Développeur 29
Évaluation
(12)
Projets
16
13%
Arbitrage
4
50% / 25%
En retard
4
25%
Chargé
30
Développeur 30
Évaluation
Projets
0
0%
Arbitrage
0
En retard
0
Gratuit
Commandes similaires
I need an MT5 Expert Advisor built as a high-precision volumizer for Forex. Its core purpose is to generate controlled trading volume for rebates, while still maintaining low-risk account growth. I am not looking for aggressive profit chasing. I am looking for a stable, intelligent EA that can produce volume in a disciplined way without damaging the account. The ideal system should trade major currency pairs, avoid
1. IF price forms: - Higher highs + higher lows → TREND = BUY - Lower highs + lower lows → TREND = SELL ELSE → NO TRADE 2. IF: - Trend = BUY - Price retraces to support zone - Bullish engulfing candle forms - TDI green crosses above red (optional) THEN: - Execute BUY 3. IF: - Trend = SELL - Price retraces to resistance - Bearish engulfing forms - TDI confirms THEN: - Execute SELL 4. Risk per trade = 1% of account Lot
I need a high frequency trading robot for gold in one or 5 minute timeframe the robot should have spread filter where it should only open trades below a set spread should have news filter to allow trading during fundal news or not the robot should have input in number of minutes to close all open trades and remove pending orders before fundamental news as part of news filter. It should also have the number of minutes
Hello! I want to programm EA that uses volume profile indicator, but I am not sure if this is possible. Only experienced programmers please, I will not select a programmer who did only few jobs. Before starting I need to make sure you understand everything and that this is for sure technically possible
Hello, I am looking for a professional trading system including: 1- Trading Bot (Expert Advisor): - Good profit performance - High security and strong risk management - Works efficiently during high market volatility (news and strong movements) - Works on all pairs (Forex + Gold) 2- Signal Indicator: - Provides clear Buy and Sell signals - Includes Take Profit and Stop Loss - No repaint (signals must not change or
Hi, I’m looking for a top-tier, profit-optimized EA that has the potential to scale trading returns significantly. My goal is to maximize growth over time. Can you help develop a bespoke EA that could potentially scale to high six or seven figures
Max amount grid 30+ USD
max amount grid step for magic number do keep deleting .only when it is in negative floating .but when it is profit allow to go over the max and replays to grid step
Apply with a screen of your work . Symbol Specific Logic . Live Chart Optimization Check the Core logic . [back tests as well] Change points to pips . Create buffer for the zone
I will pay 3000+ USD (negotiable) for an EA for existing MT5 that generates a minimum of 15-20% or higher a month consistently (provide source code after final deal) Looking for a highly profitable EA Please send demo version directly subject (Buying profitable EA Budget up to $ 3000 USD), past results and optimal settings so I can test, if it performs in a strategy tester i will also need option to forward test it

Informations sur le projet

Budget
50 - 120 USD