Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Close All at Total Profit or Loss (money) - expert for MetaTrader 5

Gilberto Cardona Velez
Gilberto Cardona Velez
  • MQL4/MQL5 developer - Expert Advisors, backtests and strategy conversion at  Laboratorio de Estrategias
  • Colombia
  • 406
Laboratorio de Estrategias - we turn trading ideas into tested, automated systems, with honest, data-driven verdicts.
Services:
- Expert Advisors for MT4 / MT5 built to your rules (entries, exits, risk, time filters), with a written risk audit
Views:
33
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Many traders want a simple rule: "close everything when my open trades are up X dollars in total, or down Y dollars". This utility does exactly that and nothing else. It watches the total floating profit of your positions (in account currency) and, when the target or the loss limit is reached, it closes all of them and can also delete pending orders. It never opens trades, so you can run it next to your manual trading or next to any other EA.

Inputs and logic

Inputs

  • Close when total profit >= - profit target in account currency (0 = off).
  • Close when total loss >= - loss limit in account currency, as a positive number (0 = off).
  • Positions to watch - all symbols, or only the symbol of the chart where the EA is attached.
  • Magic number - -1 watches every position, 0 only manual trades, any other value only that EA's trades.
  • Include swap - adds swap to the total.
  • Delete pending orders - also removes pending orders of the same filter when closing.
  • Stop after one close - the EA removes itself after closing, so it does not act again by surprise.
  • Max slippage (points) - deviation allowed for the closing orders.

How to use: attach it to any chart and timeframe (the symbol only matters with "Only this chart's symbol"), allow Algo Trading and set your limits. The chart comment shows the number of watched positions and the current total. The check runs on every tick and once per second, and closing is retried up to 3 times if the broker rejects an order.

Notes: the amounts are floating profit, not account equity. Commissions charged at opening are not included in the floating profit by MetaTrader. Test it first on a demo account. This is a risk tool, not a strategy: it does not promise profits. Not financial advice.

News Straddle EA Economic Calendar News Straddle EA Economic Calendar

News trading EA for Gold (XAUUSD) and forex: places a Buy Stop and a Sell Stop seconds before each release of the MT5 economic calendar, one cancels the other, stop loss, take profit and trailing in points. Open source code.

PDH PDL Sweep Levels PDH PDL Sweep Levels

Previous day high and low indicator for MT5 on Gold (XAUUSD), forex and indices: PDH, PDL, previous week high and low, day and week open, and an arrow when a closed candle sweeps a level and closes back inside. Open source code.

Trailing Stop and Break-Even Manager (points or ATR) Trailing Stop and Break-Even Manager (points or ATR)

Utility EA that moves the stop loss of positions you already have open: break-even with locked profit and trailing stop in points or ATR. It never opens trades.

Trade-Request Matrix: Regression Testing Invalid Stops, Volume and Close Errors with OrderCheck() Trade-Request Matrix: Regression Testing Invalid Stops, Volume and Close Errors with OrderCheck()

Part 4 of the regression-testing series. An Expert Advisor that builds a fixed matrix of 20 valid and invalid trade requests (stops at and inside the stops level, wrong-side stops, volume outside the symbol rules, oversized and unknown closes, unchanged and wrong-side modifications), checks each one with OrderCheck() without sending anything, and reports PASS, FAIL or INCONCLUSIVE per row with a digest you can compare between runs.