Virtual Stop And Target Manager
A stop loss sitting a few pips from the market, visible to the broker's server, is exactly the kind of level a dealing desk with a stop-hunting incentive is positioned to see. Managing the real stop and target in the terminal's memory instead, and only sending a market close once price actually reaches them, keeps the exact levels private. The trade-off is honest: this only works while the terminal stays connected and ticking, which is why a wide emergency stop is placed server-side regardless - not at the virtual level, but far enough away that it should never be touched under normal conditions, existing purely to cap the damage on the one occasion a connection genuinely drops. Every money calculation here is derived from the symbol's own tick value and tick size, then scaled by the position's actual lot size - never a hardcoded contract size like 100000. That assumption is wrong for gold, most indices, and any CFD whose contract size differs from a standard forex lot, and it fails silently: the code compiles, runs, and reports a risk figure that is simply wrong on the affected symbols. MoneyPerPoint and its inverse, PointsForMoneyRisk, are the two functions that do this correctly, and every other money-aware function in the header routes through them. The monitoring logic is deliberately split into a pure half and a real-trading half. CheckBreach and CheckAll take an explicit bid/ask and never call a broker/account function themselves, so breach detection can be exercised with synthetic prices - in a test, in a demo, or in a backtest harness - with no real position involved at all. PlaceEmergencyStop and ExecuteClose are the separate functions that actually touch the broker, kept apart so the logic that decides WHEN to act is testable independently of the code that DOES the acting. Notes and limitations - This is real risk-management infrastructure. Managing stops client-side means a lost connection, a crashed terminal, or a VPS outage leaves a position protected ONLY by the wide emergency stop - never disable that stop or set it unrealistically far away to save a few points of slippage. - CheckAll assumes every registered entry for a given symbol should be checked against the same bid/ask - correct for one EA managing its own positions on one symbol per call, call it once per symbol for a multi-symbol strategy. - PlaceEmergencyStop validates against the symbol's stop and freeze levels and widens the distance if needed, but a broker can still reject the request for reasons outside those two constants - check the return value. - ExecuteClose retries only the errors/retcodes each platform's house style classifies as transient (server busy/requote/price changed and similar) and gives up immediately on anything else, such as an invalid ticket. - The demo never calls PlaceEmergencyStop or ExecuteClose - both are present and real, but deliberately not exercised on live data by a script that should not be modifying or closing anyone's actual trades. - On MQL5, registering multiple simultaneous virtual entries for one symbol only reflects reality on a hedging account - see MQL4 VERSUS MQL5 DIFFERENCES above.
Script · MT4 · v1.0 · Free
About Virtual Stop And Target Manager
Virtual Stop And Target Manager is a script for MetaTrader 4. It has 3 settings, such as Lots, Max risk money and Emergency pips. MQL source code included.
Files in the download: VirtualStopManager.mqh, VirtualStopManager.txt, VirtualStopManagerDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lots | 0.50 | Synthetic position size for the worked examples |
| Max risk money | 25.0 | Max money risk used to size the virtual stop distance |
| Emergency pips | 100 | Wide emergency stop distance, in pips |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Risk & Lot Size · MT4 Script · MQL4 Source Code