Watch how to download trading robots for free
Find us on Facebook!
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
Scripts

One-Click Close All Positions with Slippage Guard - script for MetaTrader 5

Gerardo Lopez Martinez
Gerardo Lopez Martinez
  • Algorithmic Trading & Prop Firm Risk Systems at  Institutional MQL5 Developer
  • Mexico
  • 480
Professional MQL5 & C# Algorithmic Trading Developer | Institutional Execution & Prop Firm Risk Systems
Views:
37
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

One-Click Close All Positions with Slippage Guard is a fast execution utility script for MetaTrader 5 that closes open positions safely while protecting against abnormal spreads and excessive slippage.

How it works:

  • Iterates backwards through open positions and filters by scope, optional Magic Number, and live spread before sending close orders via CTrade .
  • Automatically retries transient broker errors (REQUOTE , PRICE_CHANGED , PRICE_OFF , TIMEOUT , CONNECTION ) and prints a complete execution summary in the Experts log and an Alert popup.

Input Parameters:

  • InpCloseScope (default: CLOSE_ALL_SYMBOLS) — Filter mode: All Symbols, Current Symbol Only, Profitable Positions Only, or Losing Positions Only.
  • InpMagicFilter (default: -1) — Optional Magic Number filter (-1 closes positions from any Magic Number).
  • InpClosePending (default: false) — If true , also deletes matching pending orders.
  • InpMaxSlippagePts (default: 30) — Maximum allowed slippage deviation in points passed to CTrade .
  • InpMaxSpreadPts (default: 0) — Maximum spread in points allowed to close a position (0 disables spread filtering).
  • InpMaxRetries (default: 3) — Maximum retry attempts on transient requotes or price changes.
  • InpRetryDelayMs (default: 100) — Delay in milliseconds between retry attempts.


One-Click Close All Positions with Slippage Guard


Tick Volume Delta Histogram (Buy/Sell Pressure Estimate) Tick Volume Delta Histogram (Buy/Sell Pressure Estimate)

Estimates buy/sell pressure by splitting the tick volume of every bar into a buy part and a sell part. The difference (delta) is shown as a four-color histogram with an optional EMA line.

Session VWAP with Standard Deviation Bands Session VWAP with Standard Deviation Bands

Session-anchored VWAP with volume-weighted standard deviation bands. It restarts at every daily, weekly or monthly session open and shows how far price has stretched from the average price paid during the session.

Spread and Tick Velocity Monitor Spread and Tick Velocity Monitor

Lightweight real-time HUD for MetaTrader 5 that monitors live spread (points and pips), session Min/Avg/Max spread, and tick arrival velocity (ticks/sec and ticks/min) with automatic market regime classification.

MACD Signals MACD Signals

Indicator edition for new platform.