Position Closure Management MT5
- Utilità
- Juergen Marcus Wolfgang Rosswinkel
- Versione: 1.30
- Attivazioni: 5
NOHEDGE
Automated Position Manager for MetaTrader 5
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
OVERVIEW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NOHEDGE is a trade management utility for MetaTrader 5 that automatically detects and closes hedged positions — opposite buy and sell orders on the same or across different symbols. It is designed for traders who use grid, martingale, or manual hedging strategies and need a reliable, configurable exit mechanism with integrated risk controls.
The EA does not open any trades. It exclusively manages and closes existing positions according to the configured rules. On every tick it scans all open positions and closes matched buy/sell pairs using the native MT5 CloseBy mechanism — eliminating the spread cost that would otherwise apply when closing each leg individually. Partial volume matching is fully supported.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CORE FEATURES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Native CloseBy Mechanism
Closes matched pairs using the MT5 CloseBy function to minimise spread cost. Falls back to individual close if CloseBy is unavailable on the broker.
Closing Priority
Configurable close order: newest first, oldest first, most profitable first, or least profitable first.
Daily Limits
Automatically closes all positions when a daily profit target or daily loss limit is reached — calculated from open positions AND all deals already closed that day.
Rollover Protection
Configurable quiet window around the daily swap rollover. The EA suspends all closing activity during this period. Three behaviours configurable when a daily limit is hit inside the window: postpone, close regardless, or selective close.
Spread Filter
Skips symbols where the current spread exceeds the configured maximum. A separate, higher threshold is available for crypto instruments.
Cross-Symbol Hedging
Optional mode to match buy and sell positions across different instruments — e.g. a buy on EURUSD paired with a sell on GBPUSD.
Time-Based Closing
Force-close all, only buy, or only sell positions at a configured time on individually selectable weekdays.
Panic Buttons
Three one-click emergency buttons directly on the chart: CLOSE ALL · CLOSE PROFIT ONLY · CLOSE LOSS ONLY.
Magic Number Filter
Optionally restricts management to positions opened by a specific EA, identified by magic number.
Anti-Loop Protection
Cooldown timer prevents repeated closing of the same symbol within a configurable window (default 5 minutes) to guard against rapid cycling caused by external EAs.
Status Dashboard
Live on-chart panel showing position counts, volumes, buy/sell P/L breakdown, daily P/L progress, and active filter status.
Chart Markers
Visual arrow markers for each open position with profit tooltip. Daily profit target and loss limit are displayed as horizontal lines on the chart.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INPUT PARAMETERS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GENERAL
CloseOrder Newest first Priority: Newest / Oldest / Most profitable / Least profitable
MaxRetries 3 Retry attempts if a close is rejected by the broker
RetryDelay 200 ms Exponential backoff base delay between retries (doubles each attempt, capped at 1 s)
MagicNumber 12345 Magic number filter (active when CloseOnlyMagic = true)
CloseOnlyMagic false Restrict management to positions matching the specified magic number
EnableHedgeClosing true Master switch for automatic hedge pair detection and closing
UseDirectClose false Use individual PositionClose instead of CloseBy
MaxPositionsPerCycle 5 Maximum positions closed per tick to limit server load
VerboseLogging false Enable detailed journal logging for debugging
DAILY 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 ignore time Behaviour when limit hits during rollover window: Postpone / Close regardless / Selective
CryptoHandling Always close How to treat crypto positions when a daily limit triggers
PreventTradeLoop true Enable anti-cycling cooldown after closing a pair
TradeLoopCooldown 300 s Seconds before the same symbol can be closed again
ROLLOVER PROTECTION
EnableIgnoreTime true Enable the rollover protection quiet window
IgnoreStartHour 23 Hour (server time) at which the protection window begins
IgnoreStartMinute 55 Minute at which the protection window begins
IgnoreEndHour 0 Hour (server time) at which the protection window ends
IgnoreEndMinute 10 Minute at which the protection window ends
CheckSpreadInIgnoreTime true Also skip symbols with spread above threshold inside the window
MaxAllowedSpread 5.0 pts Maximum allowed spread for non-crypto symbols
CryptoMaxSpread 25.0 pts Maximum allowed spread for crypto symbols
CryptoPrefix BTC,ETH… Comma-separated prefixes used to identify crypto instruments
TIME-BASED CLOSING
EnableTimeBasedClosing false Close positions at a specific time of day
CloseHour 17 Hour at which positions are closed (server time, 24 h)
CloseMinute 0 Minute at which positions are closed
CloseOnlyForex true Exclude crypto positions from time-based close
CloseBuyOnly false Close only buy positions at the specified time
CloseSellOnly false Close only sell positions at the specified time
ClosingMonday–Sunday Friday only Per-day toggle for time-based closing (each weekday individually configurable)
CROSS-SYMBOL AND SINGLE POSITIONS
CrossSymbolClose false Match buy and sell positions across different instruments
CloseSinglePositions false Also close unmatched (unpaired) positions
SinglePosMaxCount 5 Maximum unmatched positions to close per cycle
MinimumLotSize 0.01 Positions below this volume are ignored
PANIC BUTTON
EnablePanicButton true Display emergency close buttons on the chart
PanicButtonBehavior Close regardless Whether panic close respects the rollover protection window
PanicButtonX / Y 20 / 50 Screen position of the button panel in pixels from top-left
ButtonWidth / Height 150 / 30 Button dimensions in pixels
ButtonColor Red Background colour for the main panic button
ProfitButtonColor Green Background colour for the profit-only button
LossButtonColor Crimson Background colour for the loss-only button
DAY FILTER
MondayEnabled true Enable EA activity on Monday
TuesdayEnabled true Enable EA activity on Tuesday
WednesdayEnabled true Enable EA activity on Wednesday
ThursdayEnabled true Enable EA activity on Thursday
FridayEnabled true Enable EA activity on Friday
SaturdayEnabled false Enable EA activity on Saturday
SundayEnabled false Enable EA activity on Sunday
VISUALISATION
ShowPositionMarkers true Show arrow markers on the chart for each open position
ShowOnlyCurrentSymbol true Show markers only for the chart's own symbol
BuyMarkerColor SeaGreen Colour of buy position markers
SellMarkerColor Crimson Colour of sell position markers
EnableEAComment true Show the live status dashboard on the chart
CommentRefreshSeconds 2 Dashboard refresh interval in seconds
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INSTALLATION
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Copy the compiled .ex5 file to the MetaTrader 5 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.
4. In the EA properties dialog, enable "Allow automated trading" and click OK.
The status dashboard appears immediately on the chart.
FIRST STEPS
1. Attach the EA to any chart. The symbol of the chart does not affect scope — the EA manages all account symbols by default.
2. Set DailyProfitTarget and DailyLossLimit to your desired values and enable EnableDailyLimits = true.
3. Configure the rollover protection window (IgnoreStartHour / IgnoreEndHour) to match your broker's daily swap time. Default is 23:55 – 00:10 server time.
4. If you trade with EAs that use a magic number, enable CloseOnlyMagic = true and enter the correct MagicNumber to avoid interfering with unrelated positions.
5. For multi-system setups, run multiple instances on different charts — each with a different magic number filter — to manage positions from separate trading systems independently.
IMPORTANT NOTES
- AutoTrading must be active in MetaTrader 5 (toolbar button or Ctrl+E).
- "Allow automated trading" must be enabled in the EA properties.
- The EA does not open any trades. It exclusively manages and closes existing positions.
- Visual elements are automatically suppressed during backtesting to avoid rendering overhead.
- If a CloseBy creates a residual position due to volume mismatch, the remainder is logged and processed in the next cycle.
- Volume-mismatch events are always written to the journal regardless of the VerboseLogging setting.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CHANGELOG
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
── v1.3 (Current) ──────────────────────────────────────────────
FIX #01 Commission sign error in P/L calculation corrected
FIX #02 Daily P/L now includes all deals closed earlier the same day
FIX #03 CloseBy error code handling replaced with ResultRetcode()
FIX #04 Integer overflow in retry backoff delay resolved
FIX #05 Array overflow in pair creation loop fixed
FIX #06 Monthly date rollover bug corrected
FIX #07 Cross-symbol fallthrough case handled correctly
FIX #08 Partial-close orphan positions now tracked and reprocessed
FIX #09 Profit check now includes swap and commission
FIX #10 Deprecated POSITION_COMMISSION replaced with deal history lookup
── v1.0 (Initial Release) ──────────────────────────────────────
NEW #1 Core hedge pair detection and CloseBy management
NEW #2 Panic buttons (CLOSE ALL / CLOSE PROFIT ONLY / CLOSE LOSS ONLY)
NEW #3 Daily profit target and loss limit system
NEW #4 Rollover protection quiet window
NEW #5 Spread filter with separate crypto threshold
NEW #6 Live status dashboard on chart
NEW #7 Chart position markers with profit tooltip
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
COMPATIBILITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Platform MetaTrader 5 (Build 3000+)
Language MQL5
Instruments All (Forex, Metals, Indices, Crypto, Energy)
Timeframes All timeframes
Account Type Demo and Live (Hedge accounts required for hedging strategies)
AutoTrading Must be enabled in terminal and EA properties
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NOHEDGE v1.3 | fi.con Investment Group | MQL5 Marketplace
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
