Position Closure Management MT5
- Utilità
- Juergen Marcus Wolfgang Rosswinkel
- Versione: 1.40
- Aggiornato: 7 marzo 2026
- Attivazioni: 5
NOHEDGE
Automated Hedge Manager & Risk Controller for MetaTrader 5
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
OVERVIEW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Running grid, martingale, or manual hedging strategies means you constantly carry open buy/sell pairs that need to be resolved at exactly the right moment — before the spread widens at rollover, before a news spike blows your account, or exactly at your daily profit target. Doing that manually is slow, error-prone, and stressful.
NOHEDGE is a dedicated close-only utility that automates this entire process. It never opens a single trade. Instead it scans every tick, matches opposing buy/sell pairs across your account, and closes them using MT5's native CloseBy mechanism — which settles both sides in a single server transaction at zero spread cost. Partial-volume matching is fully supported, so even complex multi-lot grids are unwound cleanly.
One EA, one chart, full account scope. NOHEDGE monitors and controls all symbols simultaneously from whatever chart you attach it to. The magic-number filter lets you run multiple isolated instances for different strategies on the same account without any conflict.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WHY NOHEDGE — THE KEY DIFFERENCES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Zero spread on pair closings
Most close approaches call PositionClose() twice — once per leg — and pay the full spread twice. NOHEDGE uses the MT5 CloseBy() function that settles both legs in a single server request at zero spread. On gold or high-volatility pairs with a 30-50 point spread this is a significant real-money difference over hundreds of closes.
Accurate daily P/L — no surprises
Many tools track only the floating P/L of open positions. NOHEDGE adds all realised deals closed earlier that day before comparing against your target. You will never get an unexpected close because a previously booked loss was not counted — and you will never miss a limit because earlier profits were ignored.
Safe by default
EnableEA defaults to false. The EA cannot accidentally close a single trade until you explicitly activate it. This makes it safe to attach to a live account for observation before going live — the full dashboard and all three panic buttons remain active while the automation is paused.
3 one-click panic buttons — always live
Dashboard, rollover guard, spread filter — none of these affect the panic buttons. Even when EnableEA=false or the rollover window is active you can still hit CLOSE ALL, CLOSE PROFIT ONLY, or CLOSE LOSS ONLY at any moment. Panic close deliberately bypasses the anti-loop cooldown so every position is reachable in an emergency.
Anti-loop protection for grid EAs
Grid and martingale EAs reopen positions the instant they are closed. Without a cooldown, a close utility and a grid EA can enter a destructive cycle that burns through your equity in seconds. NOHEDGE's ring-buffer cooldown blocks re-closing the same symbol for a configurable window (default 5 minutes), then clears automatically.
Cross-symbol hedging
No other basic close manager on the MQL5 Marketplace detects hedges across different symbols. NOHEDGE can pair a EURUSD buy with a GBPUSD sell — a pattern common in correlation-based strategies and basket grids — and close them together.
Broker-grade error handling
Retry logic with exponential backoff, trade.ResultRetcode() for accurate broker rejection codes (not the unreliable GetLastError()), specific error messages for every known TRADE_RETCODE, and automatic fallback to direct close when CloseBy is unavailable — all production-tested on live accounts running 24/7 on a VPS.
Multi-instance, multi-strategy
Run NOHEDGE on Chart A managing your grid EA (MagicNumber 1001), and simultaneously on Chart B managing your scalper (MagicNumber 2002). Each instance is fully independent — same account, no conflicts.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
FEATURE OVERVIEW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Master Switch
EnableEA = false pauses all automated closing instantly. Dashboard, panic buttons, and all visual elements remain fully active. Useful when you want to monitor positions without any automation running.
Native CloseBy Pair Closing
Matched buy/sell pairs are closed using MT5's built-in CloseBy function — one server round-trip, zero spread. Partial-volume matching handles any lot-size combination. Auto-fallback to PositionClose() when the broker does not support CloseBy.
Live Dashboard Panel [NEW v1.4]
On-chart panel showing: buy and sell position count and total volume, individual P/L per side in real time, net P/L across all positions, daily P/L with animated progress bar between loss limit and profit target, and active filter status (rollover, spread, CloseBy mode, anti-loop). Updates every 2 seconds.
Daily Profit Target & Loss Limit
Automatic full-account close when daily P/L hits a configured target or limit. Calculated from floating positions AND all deals closed earlier that day — broker-accurate, not estimate-based.
Rollover Protection
Configurable quiet window (default 23:55–00:10) suspends all automated closing around the daily swap rollover. Three independent behaviours: Postpone / Close regardless / Selective close per symbol spread. Applies separately to hedge closing, daily limits, time-based close, and panic buttons.
Spread Filter
Per-symbol spread check before every close attempt. Separate maximum thresholds for standard pairs and crypto/XAU instruments. Optionally active outside the rollover window too.
Anti-Loop Protection
Ring-buffer cooldown (O(1) performance) prevents re-closing the same symbol within a configurable window. Protects against destructive cycling when an external grid EA immediately reopens closed positions.
Panic Buttons
Three permanent on-chart buttons: CLOSE ALL — CLOSE PROFIT ONLY — CLOSE LOSS ONLY. Always visible regardless of EA state. Bypass anti-loop cooldown intentionally so every position is reachable in an emergency. Auto-centre horizontally (ButtonRightMargin=0) and auto-reposition on chart resize.
Time-Based Closing
Schedule a forced close at a specific server time on individually selectable weekdays. Choose to close all positions, buy only, or sell only. Optional crypto/XAU exclusion. Ideal for Friday evening close before the weekend gap.
Closing Priority
Four close-order modes: newest first, oldest first, most profitable first, least profitable first. Applied consistently across pair closing, single-position closing, and cross-symbol mode.
Cross-Symbol Hedging [Advanced]
Matches buy and sell positions across different instruments — e.g. EURUSD buy paired with GBPUSD sell. Uses full partial-volume matching. Processes singles (unpaired) in the same pass when CloseSinglePositions is active.
Trading Day Filter
Independent per-weekday enable/disable for automated hedge closing. Run Mon–Fri only or any custom schedule.
Magic Number Filter
Restrict all operations to positions with a specific magic number. Multiple NOHEDGE instances can run simultaneously on the same account, each managing a separate strategy independently.
Panel & Button Offsets [NEW v1.4]
Independent PanelTopOffset and ButtonTopOffset inputs push the dashboard and panic buttons down from the chart top separately — for brokers whose custom toolbars overlap the default chart header area.
Position Markers
Visual arrow markers on the chart for each open position (buy = green, sell = red). Per-symbol filter option.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INPUT PARAMETERS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MASTER SWITCH
EnableEA false Master on/off — false = monitoring mode (dashboard and buttons active, no automated closing)
HEDGE CLOSING
EnableHedgeClosing true Enable automatic hedge pair detection and closing
CloseOrder Newest first Priority: Newest / Oldest / Most profitable / Least profitable
CloseOnlyMagic false Restrict management to positions matching MagicNumber
MagicNumber 12345 Magic number filter (active when CloseOnlyMagic = true)
UseDirectClose false Use PositionClose instead of CloseBy (for brokers without CloseBy support)
MaxPositionsPerCycle 5 Maximum positions closed per tick to limit server load
MaxRetries 3 Retry attempts if a close is rejected by the broker
RetryDelay 200 ms Exponential backoff base delay — doubles each attempt, capped at 1 s
VerboseLogging false Enable detailed journal logging for debugging
DAILY PROFIT / LOSS LIMITS
EnableDailyLimits true Activate the daily profit target and loss limit system
DailyProfitTarget +1000.0 Close all positions when daily P/L reaches this value (account currency)
DailyLossLimit -500.0 Close all positions when daily P/L drops to this value (account currency)
DailyLimitBehavior Respect rollover Behaviour when limit hits during rollover window: Postpone / Close regardless / Selective
CryptoHandling Always close How to treat crypto/XAU positions when a daily limit triggers
ANTI-LOOP PROTECTION
PreventTradeLoop true Lock symbol after close to prevent cycling with grid EAs
TradeLoopCooldown 300 s Seconds before the same symbol can be closed again (ring buffer, O(1))
CROSS-SYMBOL & SINGLE POSITIONS
CrossSymbolClose false Match buy and sell positions across different instruments
CloseSinglePositions false Also close unpaired (single) positions — independent of daily limits
SinglePosMaxCount 5 Maximum unpaired positions to close per cycle
MinimumLotSize 0.01 Positions below this volume are ignored
TRADING DAY FILTER
MondayEnabled true EA active on Monday
TuesdayEnabled true EA active on Tuesday
WednesdayEnabled true EA active on Wednesday
ThursdayEnabled true EA active on Thursday
FridayEnabled true EA active on Friday
SaturdayEnabled false EA active on Saturday
SundayEnabled false EA active on Sunday
ROLLOVER PROTECTION
EnableIgnoreTime true Enable the rollover quiet window
IgnoreStartHour 23 Start hour of rollover window (server time)
IgnoreStartMinute 55 Start minute
IgnoreEndHour 0 End hour of rollover window (server time)
IgnoreEndMinute 10 End minute
SPREAD FILTER
CheckSpreadInIgnoreTime true Extend spread check outside the rollover window too
MaxAllowedSpread 5.0 pts Maximum spread for standard pairs (forex, indices, etc.)
CryptoMaxSpread 25.0 pts Maximum spread for crypto / XAU pairs
CryptoPrefix BTC,ETH… Comma-separated prefixes to identify crypto/XAU instruments
TIME-BASED CLOSING
EnableTimeBasedClosing false Master switch for scheduled closing
CloseHour 17 Closing time — hour (server time, 24 h)
CloseMinute 0 Closing time — minute
CloseOnlyForex true Exclude crypto/XAU from time-based close
CloseBuyOnly false Close only buy positions at scheduled time
CloseSellOnly false Close only sell positions at scheduled time
TimeBasedCloseBehavior Respect rollover Whether to respect or override the rollover window
ClosingMon–Sun Friday only Per-day toggle (each weekday individually configurable)
PANIC BUTTONS
EnablePanicButton true Show emergency close buttons on chart
ButtonWidth 210 px Button width
ButtonHeight 35 px Button height
ButtonFontSize 7 Button label font size
ButtonRightMargin 0 0 = horizontally centred; >0 = fixed px from right edge
ButtonTopOffset 10 px Buttons distance from top of chart
ButtonColor Red Close All button background
ProfitButtonColor Green Close Profit Only button background
LossButtonColor Crimson Close Loss Only button background
TextColor White Button text colour
PanicButtonBehavior Close regardless Whether panic close respects the rollover window
INFO PANEL
EnableEAComment true Show live dashboard panel on chart
PanelInfoWidth 480 px Dashboard panel width — all internal layout scales with this
PanelTopOffset 25 px Panel distance from top of chart (independent of buttons)
CommentRefreshSeconds 2 s Dashboard refresh interval
CommentBgColor 80,80,80 Panel background colour (full RGB control)
CommentFontSize 7 Panel font size
POSITION MARKERS
ShowPositionMarkers true Arrow markers on chart for each open position
ShowOnlyCurrentSymbol true Show markers only for current chart symbol
BuyMarkerColor SeaGreen Buy marker colour
SellMarkerColor Crimson Sell marker colour
MarkerSize 8 Arrow marker size
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INSTALLATION & FIRST STEPS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Copy the compiled .ex5 file into the MT5 Experts folder:
[MT5 data folder] / MQL5 / Experts /
2. Restart MetaTrader 5 or press F5 to refresh the Navigator.
3. Drag the EA from the Navigator onto any chart.
The chart symbol does not matter — NOHEDGE manages all account symbols by default.
4. In the EA properties dialog enable Allow automated trading and click OK.
Dashboard and panic buttons appear immediately.
5. Set EnableEA = true to activate automated closing.
Until you do, the EA runs in observation mode — safe to use on a live account.
6. Set DailyProfitTarget and DailyLossLimit to your account size and enable EnableDailyLimits = true.
7. Adjust IgnoreStartHour / IgnoreEndHour to match your broker's swap rollover time.
Default 23:55 – 00:10 server time covers most brokers.
8. If your broker's toolbar overlaps the panel or buttons, adjust PanelTopOffset and ButtonTopOffset.
9. For multi-strategy setups run a second instance on a different chart with a separate MagicNumber filter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPORTANT NOTES — READ BEFORE PURCHASE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Hedge account required
MT5 accounts must be configured as hedge accounts (not netting). NOHEDGE closes buy/sell pairs by ticket — this requires that both legs exist as separate positions, which is only possible on hedge accounts. Netting accounts merge opposing positions immediately and NOHEDGE cannot manage them.
AutoTrading must be enabled
The MT5 AutoTrading button in the toolbar must be green and Allow automated trading must be checked in the EA properties dialog. Without this no close operations can execute.
EA never opens trades
NOHEDGE does not and cannot open any new positions. It only closes what already exists. It carries zero directional risk of its own.
EnableEA defaults to false — activate before use
After attaching to the chart the EA is in monitoring mode. No positions will be closed until you set EnableEA = true. This is intentional: it prevents unexpected closes on accounts that already have positions open.
Panic buttons bypass the rollover guard
By default PanicButtonBehavior = CLOSE_REGARDLESS. Even during the rollover window or high-spread conditions the three on-chart buttons will execute immediately. Change to RESPECT_IGNORE_TIME only if you specifically want rollover protection to block panic closes too.
AntiLoop cooldown does not affect panic buttons
If a position was recently closed by the EA and is still in the cooldown window, the automated hedge loop will skip it — but the panic buttons will still reach it. Emergency closes are never blocked by cooldown logic.
Spread filter uses points, not pips
MaxAllowedSpread and CryptoMaxSpread are in broker points (as returned by SYMBOL_SPREAD), not pips. On a 5-digit broker, 5 points = 0.5 pip for forex, and 50 points = 50 points for gold (XAUUSD). Verify your broker's spread unit before setting these values.
Commission accuracy
Daily P/L and position P/L calculations include profit, swap, and commission (retrieved via deal history, replacing the deprecated POSITION_COMMISSION property). This ensures accurate limit enforcement even on commission-heavy ECN accounts.
VPS recommended
For 24/7 operation and reliable rollover protection the EA should run on a VPS with a stable internet connection to your broker.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
COMPATIBILITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Platform MetaTrader 5 (Build 3000+)
Language MQL5
Instruments All — Forex, Metals (XAU/XAG), Indices, Crypto, Energy, CFDs
Timeframes Any timeframe — NOHEDGE manages the account, not the chart
Account Type Hedge accounts only (not compatible with MT5 netting accounts)
Account Size Any — configure DailyProfitTarget/DailyLossLimit in your account currency
AutoTrading Must be enabled in terminal and EA properties
Recommended VPS for 24/7 uninterrupted operation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MORE TOOLS FROM fi.con INVESTMENT GROUP
We offer a complete MT5 toolkit built by traders. If you trade actively and want more automation, reporting, and control, these tools extend your MT5 setup significantly:
🏆 Enhanced Telegram Position Tracker MT5 — the most complete Telegram reporting solution for MT5. Every trade open, close, SL/TP change, and partial close delivered in real time. Live streaming messages update P/L every 30 seconds. Dual-posting to channel + group topics. 15-button interactive follower menu. Crash detection, HFT burst protection, zero missed closures. Automatic daily, weekly, and monthly P&L reports. If you share your trades with a Telegram audience, this is the EA.
📡 MT5 to Telegram Informer — sends every trade open and close to your Telegram channel in real time. Full position lifecycle: pending order execution, SL/TP changes, partial closes, close reason labelling. Multiple channels, Topics support, configurable report fields. If you share your trades with a Telegram audience, this is your tool.
📊 Telegram Trading Reporter MT5 — automated performance reports delivered to Telegram on schedule: daily EOD summary, weekly stats, monthly overview. Analyses your full trade history and sends structured reports with P&L, win rate, profit factor, best/worst trade — all without you having to open MT5.
🛠️ Chart Order Trade Manager MT5 — professional on-chart trade management panel for active traders. Visual SL/TP placement, automatic lot size calculation from risk %, one-click breakeven, trailing stop, partial close. Designed for traders who manage positions manually while running EAs in parallel.
NOHEDGE v1.4 | fi.con Investment Group | MQL5 Marketplace
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
