Apply Missing Stops And Targets
An unprotected position is usually not a decision, it is an accident. A market order fired from the one-click panel has no stop. An EA crashed after entry. A stop was deleted during a fumbled drag. This script sweeps the whole book and fills in whatever protection is missing, without touching anything that is already there. That last part is the actual contract. The script only ever writes a level whose current value is zero. A position that already carries a stop keeps it, even if the target is missing and gets filled in, and the other way round. That one-way rule is what makes it safe to run over a mixed book where an EA is managing some positions and the trader has hand-placed levels on others - nothing deliberate is ever replaced by a template distance. Distances are measured from the open price by default, because the open price is where the risk of the trade was defined; a 50 pip stop means the same thing whether you apply it a second or an hour after entry. The catch, and the reason naive versions of this script fail, is a position the market has already moved away from. An entry-anchored stop can sit behind the current price, or inside the broker's minimum stop distance, and sending it anyway just harvests an error 130. This script checks every candidate level against the stop level and the freeze level, on the correct side of the market - the Bid for a buy, the Ask for a sell - and skips the ones that cannot be placed, with the reason and the numbers printed per ticket. When only one level of the pair is placeable the other is still applied: half a protection is better than none, as long as the journal says which half, and it does. Pip distances are converted per symbol, so a 3 or 5 digit quote gets its ten points per pip and a 2 or 4 digit one does not. Run it across a book that mixes FX pairs, gold and indices and each symbol gets the arithmetic it deserves. The summary at the end separates protected, already protected, unplaceable, frozen and refused, so the number you read is the number that happened. Notes and limitations - The same pip distances are applied to every symbol in the run. 50 pips on EURUSD and 50 pips on gold are very different risks per lot. Run the script per symbol with suitable distances, or use the symbol filter, when the book is mixed and that matters to you. - A level that cannot be placed is skipped, not approximated. The script never moves a stop to "the closest allowed price" - that would silently change your risk and call it protection. - Existing levels are never overwritten, which also means a wrong existing level is never corrected. That is deliberate. Correcting levels is a different script. - Pending orders are not touched on either platform. - Brokers with a zero stop level are not necessarily permissive. Several use dynamic, spread-linked minimums the terminal does not publish; those rejections come back from the server and are reported as refusals. - If an EA manages the same positions it may move or remove the applied levels immediately. The script does not fight it.
Script · MT4 · v1.0 · Free
About Apply Missing Stops And Targets
Apply Missing Stops And Targets is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Stop pips, Target pips and From entry. MQL source code included.
Files in the download: ApplyMissingStops.ex4, ApplyMissingStops.mq4, ApplyMissingStops.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Stop pips | 50.0 | Stop distance, in pips (0 = leave stops alone) |
| Target pips | 100.0 | Target distance, in pips (0 = leave targets alone) |
| From entry | true | Measure from the open price (false: from current market) |
| Current symbol only | false | Restrict to this chart's symbol |
| Magic filter | -1 | Only this magic (-1 means every magic) |
| Max retries | 5 | Attempts per position before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
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: Alerts · MT4 Script · MQL4 Source Code