Repeat Last Trade
Sometimes a trade closes and you want it straight back on: the stop was clipped by a wick, the take profit hit and the move keeps going, or you closed by hand and changed your mind. Re-entering by hand means re-reading the old ticket, re-typing four numbers and getting one of them wrong. This script reads the most recent closed trade from history and rebuilds it at the current market: the direction and volume are copied exactly, and the stop loss and take profit are placed at the same PIP DISTANCES from the new entry that the original had from its entry - the geometry of the trade, re- anchored at today's price. The search covers the last 30 days by default, as an input. The limit exists because "the most recent trade ever" on a dormant account is usually an accident - six months later you do not want last winter's position size re-appearing because you double-clicked the wrong script. Set the window to 0 to search everything, deliberately. The confirmation dialog is the heart of it: original and new, side by side - ticket, close time, entry, stop and target with their pip distances, next to the prices the repeat will use. Nothing is sent until those two columns look like the same trade. What it refuses to do matters as much as what it does. If the original's symbol is no longer offered, gives no quotes, or has trading disabled, the script says so and stops - it never trades a "similar" symbol. If the original's volume no longer fits the broker's current minimum, maximum or lot step, it stops - resizing would be a different trade. If the original's stop distance is inside the broker's current stop level, it stops rather than quietly widening it. A repeat that cannot be exact is not a repeat. Notes and limitations - The repeat opens at the current market, so entry, stop and target prices all differ from the original; only direction, volume and pip geometry are preserved. If the market has moved against the idea, the repeat does not know that. - A trade closed with no stop loss repeats with no stop loss. The script copies the trade you actually made, not the trade you should have made. - MQL5 pending orders that never filled, balance operations and cancelled orders are never candidates; only real market trades are. - The MQL5 closing-deal SL/TP fields can be empty on some older servers; the script then falls back to the stops the position was opened with. - The script does not check margin against other open positions beyond the broker's free-margin figure at run time.
Script · MT4 · v1.0 · Free
About Repeat Last Trade
Repeat Last Trade is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent and has a news filter. It has 6 settings, such as History days, Magic and Slippage pips. MQL source code included.
Files in the download: RepeatLastTrade.ex4, RepeatLastTrade.mq4, RepeatLastTrade.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| History days | 30 | Search window, days back (0 = no time limit) |
| Magic | 0 | Magic number for the new order |
| Slippage pips | 3 | Slippage tolerance, pips |
| Max retries | 5 | Attempts before giving up |
| Retry wait ms | 500 | Pause between attempts, ms |
| Confirm first | true | Ask for confirmation first |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Volume · Risk & Lot Size · News Trading · MT4 Script · MQL4 Source Code