Random Entry With Managed Exits
RISK WARNING: the entry has no edge whatsoever - it is a call to MathRand(). Any positive result this EA shows on a given run is sampling noise, not a discovered signal, and spread, commission and swap will drag a coin-flip entry towards a loss over enough trades even with a favourable reward-to-risk ratio. This EA exists to isolate and study exit management on a real account's order history, not to be traded for profit, and InpIUnderstandThisIsRandom defaults to false and has to be set true by hand before it will place anything. The point of the demonstration is that a system's risk and reward profile is set almost entirely by its exits and its position sizing, not by how the entry was chosen. Every trade risks the same percentage of account balance, converted to a lot size from the stop-loss distance using tick value and tick size rather than a hardcoded contract size, so the position is sized correctly on metals, indices and JPY crosses as well as plain forex. Every closed trade is scored in R-multiples - profit or loss divided by what that trade's own stop actually risked - and the EA keeps a running win rate and expectancy in R across the sample. Because the entry carries no information, a long enough sample should converge toward an expectancy driven almost entirely by InpRewardToRiskRatio and the account's trading costs, which is exactly the baseline a real signal needs to beat to be worth trading. Notes and limitations - One position at a time; a new random entry only opens once the previous trade under this magic number has closed. - The random seed is reset from the system clock on every OnInit, so results are not reproducible across reattaches - this is deliberate, it is meant to be sampled, not replayed. - R-multiple statistics reset to zero whenever the EA is reattached; they are not persisted across terminal restarts. - Requires AutoTrading enabled and IsTradeAllowed() true; if trading is disabled the EA logs it and places nothing. - This is a demonstration of exit management and expectancy arithmetic, not a strategy recommendation. The entry has no claimed edge, by design.
Expert advisor · MT5 · v1.0 · Free
About Random Entry With Managed Exits
Random Entry With Managed Exits is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent. It has 9 settings, such as I understand this is random, Entry chance percent and Risk percent. MQL source code included.
Files in the download: RandomEntryEa.ex5, RandomEntryEa.mq5, RandomEntryEa.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 |
|---|---|---|
| I understand this is random | false | Must be set true by hand before this EA will place any trade |
| Entry chance percent | 20 | Chance per new bar to open a trade when flat, 0-100 |
| Risk percent | 0.5 | Risk per trade, % of account balance, sized from the stop below |
| Stop loss pips | 30 | Stop loss per trade, in pips - also the risk unit (1R) |
| Reward to risk ratio | 1.5 | Take profit expressed as a multiple of the stop distance |
| Magic number | 20260824 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action 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: Buy/Sell Arrows · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code