Set Target At R Multiple
Traders who think in R express every outcome as a multiple of the initial risk: a trade that risked 40 pips and made 80 was a 2R winner, whatever the symbol, the lot size or the account currency. Setting targets in R keeps the whole book speaking that one language. This script does the arithmetic per position: it reads the distance from the entry to the stop, multiplies it by the input, and places the take profit that far beyond the entry - above for a buy, below for a sell. The rule that keeps the output honest is that R only exists where a stop does. A position without a stop loss has no measurable risk, and any target the script placed on it would be a number pulled from the air. Those positions are skipped and reported per ticket, never given an invented figure. The same discipline applies to a subtler case most implementations miss: a stop that has already been trailed to or beyond the entry price. The distance it measures now is locked-in profit, not risk - multiplying it gives a target with no relationship to the trade's original stake, so those positions are skipped too, with their own count in the summary. If you want R targets, the time to set them is while the initial stop still stands. Every candidate target is validated before sending, on the side of the market the server actually measures - the Bid for a buy, the Ask for a sell. A market that has already run past the R multiple, or sits within the broker's minimum stop distance of it, makes the target unplaceable; the script reports that with the numbers rather than approximating "the closest allowed price", which would quietly change the trade's reward without saying so. Positions inside the freeze level are reported as unmodifiable, and a target already sitting at the computed level from an earlier run is recognised and left alone, so the script is safe to repeat. The stop loss is never touched. The summary separates placed, no stop, stop past entry, kept existing, already there, unplaceable, frozen and refused, so the number you read is the number that happened. Notes and limitations - R is measured from the current stop, not from the stop the trade opened with. If a stop has been tightened since entry but is still on the losing side, the computed R is smaller than the original risk and the target lands closer. The script cannot know a stop's history, only its present. - A stop at or beyond the entry makes R unreadable and the position is skipped. That is deliberate, not a missing feature - see the description. - Costs are not part of the arithmetic. A 2R target measured in price is slightly less than 2R in money once spread, commission and swap are paid. If that matters, compensate in the multiple. - The market can be beyond the computed target already. The script reports it and leaves the position alone rather than closing it - taking profit is a different instruction from placing a target. - The stop loss is never touched. Neither are pending orders. - 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.
Script · MT5 · v1.0 · Free
About Set Target At R Multiple
Set Target At R Multiple is an expert advisor (trading robot) for MetaTrader 5. It has 6 settings, such as R multiple, Overwrite existing and Current symbol only. MQL source code included.
Files in the download: SetTargetAtRMultiple.ex5, SetTargetAtRMultiple.mq5, SetTargetAtRMultiple.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 |
|---|---|---|
| R multiple | 2.0 | Target as a multiple of the stop distance |
| Overwrite existing | true | Replace targets that already exist |
| 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: Risk & Lot Size · MT5 Script · MQL5 Source Code