Loading…

Hedge On Drawdown

RISK WARNING: hedging does not eliminate risk. It opens a second live position, doubling margin usage and adding a second set of spread and swap costs, to roughly freeze the loss on the first position at the point the hedge opens - it does not undo the loss already taken, and closing the two legs unevenly, or leaving the hedge to run past the original position, can turn a capped loss into a fresh open risk. This is a damage-limitation tool, not a way to trade for free. Confirm every input on a demo account before running it live. This EA watches every open position under InpMagicNumber on the chart's own symbol. The instant one of them crosses the configured drawdown trigger - an adverse pip distance from its own entry, a floating loss in account currency, or a floating loss as a percent of balance - it opens one position in the opposite direction, sized as that ticket's own lots multiplied by InpHedgeLotMultiplier. The hedge lot size always derives from the source ticket's OWN OrderLots(), never from a fixed number entered separately, so a hedge on a 0.10 lot position and a hedge on a 1.00 lot position both scale correctly without the user doing any arithmetic. Every hedge is tagged with a separate InpHedgeMagicNumber and an order comment that records which source ticket it belongs to. That tag is what lets InpMaxHedgesPerTicket work: without tracking hedges back to their source, a position sitting past its trigger would collect a fresh hedge on every single scan, compounding exposure without limit. With the cap in place, once a ticket has reached InpMaxHedgesPerTicket hedges, it is left alone regardless of how much further it drifts. Notes and limitations - Hedges open on the SAME symbol as the source position, opposite direction. This EA does not attempt cross-symbol or correlation-based hedging. - The hedge itself carries no stop-loss or take-profit - it is opened with none set, since its purpose is to offset the source position, not to run as an independent trade. Manage or close both legs deliberately. - Checks run on a timer, not on every tick, so the trigger can be overshot slightly before the hedge opens. - This EA never closes the source position or the hedge itself - only the trader's own decisions end either leg. - MQL5 version only: requires a hedging account. It will not run at all on a netting account - see "MQL4 VERSUS MQL5 DIFFERENCES" above.

Expert advisor · MT5 · v1.0 · Free

About Hedge On Drawdown

Hedge On Drawdown is an expert advisor (trading robot) for MetaTrader 5. It increases the lot size after a losing trade (martingale), can hold buy and sell positions at the same time (hedging) and can size trades from your balance and risk percent. It has 12 settings, such as Magic number, Hedge magic number and Trigger mode. MQL source code included.

Files in the download: HedgeOnDrawdown.ex5, HedgeOnDrawdown.mq5, HedgeOnDrawdown.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Magic number20260708Magic number of the positions to protect - never 0, and must differ from InpHedgeMagicNumber
Hedge magic number20260808Magic number this EA tags every hedge it opens with
Trigger modeTRIGGER_PIPSHow the drawdown trigger below is measured
Trigger pips100Adverse pips from entry that triggers a hedge (mode = Pips)
Trigger money30.0Floating loss, account currency, that triggers a hedge (mode = Money)
Trigger percent3.0Floating loss, % of balance, that triggers a hedge (mode = Percent)
Hedge lot multiplier1.0Hedge lots = source ticket's OWN lots * this - never a fixed lot size
Max hedges per ticket1Hard cap on hedges opened against any one source ticket
Slippage pips5Slippage tolerance on the hedge entry
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds
Scan interval sec15Seconds between checks

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Hedging · Martingale · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria