Join our fan page
Trade Guardian - stop loss watchdog and drawdown limiter that re-arms - expert for MetaTrader 5
- Views:
- 51
- Rating:
- Published:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
Trade Guardian is a defensive Expert Advisor. It never opens a trade. It supervises the positions you already have and steps in when a risk rule is broken.
It does three things, and each one can be switched off on its own. Closing positions is disabled by default, so you can attach the EA to a live chart and let it only warn until you trust it.
1) Missing stop loss. On every timer tick the EA walks the open positions and finds the ones with no stop loss. With InpEnforceStopLoss it attaches one at InpATR_Mult times the ATR (period InpATR_Period) of the chart timeframe, on the correct side of the entry, and never closer to the price than InpMinStopPoints points or the broker minimum stop level. Stops are only placed on the chart symbol, because the ATR handle belongs to the chart.
2) Daily loss limit. InpMaxDailyLossPct is measured against the balance recorded at the opening of the trading day, so the limit follows the account instead of drifting away from a fixed starting figure. The reference is refreshed automatically when a new day begins.
3) Total drawdown limit that re-arms. InpMaxTotalDDPct is measured from the equity peak. A peak-referenced limit has a well known failure mode: once it fires, equity can never climb back to a frozen peak, so the guard stays latched forever and the account is dead. InpCooldownHours solves it. After the given number of hours the peak is rebased to the current equity, the guard re-arms and normal work continues. The rebase is written to the log, so you can see exactly when it happened.
Scope. InpCurrentSymbolOnly restricts the guard to the chart symbol, InpMagicFilter restricts it to one magic number (-1 guards every position). When a limit is hit, InpCloseOnBreach decides whether the guarded positions are closed or only reported, InpAlertOnBreach raises a terminal alert, and InpPanel draws a small status panel on the chart with the current daily loss, the drawdown from the peak and the state of the guard.
The picture below shows the two limits: the daily one measured from the day's opening balance, the total one measured from the equity peak, and the cooldown after which the peak is rebased and the guard re-arms.

CalendarExport
This Expert Advisor is that missing bridge. Attach it to any chart and it periodically writes the calendar to a CSV file in `MQL5\Files`, where anything outside the terminal can read it.
TradeHistoryLogger
Exporting your deal history is easy and a dozen scripts already do it..
Accelerator Oscillator (AC)
The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.
MACD Signals
Indicator edition for new platform.