MT4 Version: Ea TrailingStop BreakEven MT4
MT5 Version: Ea TrailingStop BreakEven MT5
Complete User Documentation — MT4 & MT5
1. OVERVIEW
The Ea TrailingStop BreakEven is a dedicated trade management Expert Advisor that automatically adjusts stop-loss levels on your existing positions. It moves the stop to breakeven once a profit threshold is hit, then applies a trailing stop — either fixed-pip or ATR-based — to lock in gains as the market moves in your favor. This EA solves the problem of manual trade babysitting, letting you step away from the screen while your risk management runs on autopilot.
Who Should Use It: Retail forex traders who already have a reliable entry strategy but want to eliminate emotional stop-loss decisions and ensure consistent profit protection across multiple open trades.
Main Benefit: You get hands-free, systematic stop management that turns winning trades into guaranteed winners and lets you scale your trading without staring at every tick.
2. INPUT PARAMETERS & SETTINGS
This product shares a common set of general input settings with all Expert Advisor products in this series. The following sections are covered in the common guide: General Settings (lot size, SL/TP modes, magic number, trade direction), Breakeven Settings, Trailing Stop Settings, News Filter Settings and News Action Settings, Martingale Settings, Grid Settings, Hedge Settings, Risk Settings, Position Sizing, Alert Settings, Display Settings, Trade Time Settings, Trade Days Settings, Safeguard Settings, and Trend Filter Settings (MA Filter, ADX Filter, RSI Filter, MACD Filter, Parabolic SAR Filter — each with their own strategy options). All of these are fully documented in the Common General Input Settings for Expert Advisors. The sections below cover only the product-specific inputs unique to this product.
General Settings
These three toggles control how the EA displays its virtual stop lines, whether swap costs factor into profit calculations, and whether historical data is loaded during backtests — small switches that can significantly affect both visual clarity and backtest accuracy.
| Setting Name | Type | Default Value | Description | Example |
|---|---|---|---|---|
| Chart lines for virtual SL/TP (never drawn during optimization) | bool | false | When enabled, the EA draws dashed lines on the chart showing where the hidden stop-loss and take-profit levels sit. Useful for visual confirmation during live trading, but the EA skips drawing during optimization runs to avoid slowing things down. | true — turn this on when you're monitoring live trades and want to see exactly where your virtual stops are placed. |
| Include Swap charges in Profit | bool | true | Controls whether overnight swap fees are added to the profit calculation that the EA uses to decide when to move stops. Set to true for a realistic view of net profit; set to false if you want the EA to ignore swap costs and only track price movement. | true — keep this on for standard accounts where swap costs matter; switch to false for swap-free Islamic accounts. |
| Enable history for backtests or optimization | bool | false | When true, the EA loads historical bar data into memory during backtests, which is required for indicators like ATR that need past price data. Leave false for faster optimization runs where you're only testing fixed-pip trailing logic. | true — enable this when you're running a backtest that uses the ATR trailing stop feature, since ATR needs historical data to calculate. |
ATR Trailingstop Settings
These six parameters configure an alternative trailing stop method that uses Average True Range (ATR) to dynamically adjust the stop distance based on market volatility — tighter in quiet markets, wider when volatility spikes.
| Setting Name | Type | Default Value | Description | Example |
|---|---|---|---|---|
| Use ATR Trailing Stop | bool | false | Switches the trailing stop mechanism from fixed-pip mode to a volatility-adaptive ATR-based mode. When enabled, all trailing distances are calculated as multiples of the current ATR value, making the stop responsive to changing market conditions. | true — turn this on when trading pairs like GBP/JPY that have erratic volatility; the ATR-based stop will widen automatically during news spikes. |
| ATR Timeframe | ENUM | PERIOD_CURRENT | Selects the chart timeframe from which the ATR value is calculated. Using a higher timeframe like H4 gives a smoother, more stable ATR that ignores intraday noise, while the current chart timeframe reacts faster to recent volatility changes. | PERIOD_H1 — use the 1-hour timeframe for ATR calculation even if you're trading on a 5-minute chart; this gives a medium-term volatility reading. |
| ATR Period | int | 14 | The number of bars used to calculate the ATR value. A shorter period like 7 makes the trailing stop more sensitive to recent price swings, while a longer period like 21 smooths out the ATR and produces a more consistent stop distance. | 14 — the standard period that works well for most major pairs; increase to 20 for slower, more reliable stops on EUR/USD. |
| Activation (ATR multiplier) | double | 2.0 | The profit threshold, expressed as a multiple of ATR, that must be reached before the trailing stop activates. A value of 2.0 means the trade must be up by 2 ATR units before the EA starts trailing — prevents premature tightening in choppy markets. | 1.5 — use this lower multiplier for scalping strategies where you want trailing to start quickly after a small move in your favor. |
| Trail distance (ATR multiplier) | double | 1.0 | The fixed distance the stop-loss is placed behind the current price, measured in ATR units. A value of 1.0 means the stop sits exactly one ATR away from price — tight enough to protect profits but wide enough to avoid being stopped out by normal noise. | 1.5 — increase to 1.5 for volatile pairs like Gold (XAU/USD) where you need extra breathing room to avoid premature exits. |
| Trail increment (ATR multiplier) | double | 0.5 | How much the stop-loss moves forward each time the price advances by the activation distance. A value of 0.5 means the stop moves up by half an ATR unit for every full ATR unit of price progress — a conservative approach that lets profits run. | 0.3 — use a smaller increment for trend-follow |
3. HOW IT WORKS
Core Calculation & Logic
This EA doesn't open trades — it's purely a trade manager that watches your open positions and adjusts stop-loss levels automatically. On every tick (or every bar, depending on your scan mode setting), it checks the current profit or loss of each position against your breakeven and trailing stop thresholds. The core logic is simple: once price moves far enough in your favor, the EA moves the stop-loss to breakeven (or a small buffer above it), then continues to trail the stop as price extends further.
Mathematically, it compares the current price to the average entry price of the position, calculates the distance in pips (or account currency, depending on your SL/TP mode), and triggers adjustments when those distances exceed your configured activation levels. There's no complex indicator math here — it's pure price-action-based risk management.
Entry Strategies Explained
Since this EA doesn't open trades, there are no entry strategies in the traditional sense. Instead, it responds to market conditions by adjusting stops on existing positions. The logic applies equally to both buy and sell positions, just mirrored.
Breakeven Activation
BUY Signal: When the current price rises above the entry price by the number of pips set in BREAKEVEN_ACTIVATION, the EA moves the stop-loss to entry price + BE_EXTRA_PIPS.
SELL Signal: When the current price falls below the entry price by the same activation distance, the stop-loss moves to entry price - BE_EXTRA_PIPS.
Best For: Any market where you want to eliminate risk on winning trades as soon as possible — especially useful in ranging or choppy conditions where profits can evaporate quickly.
Trailing Stop
BUY Signal: Once price exceeds the trailing activation distance from entry, the stop-loss is moved up to current price minus the trailing stop distance, and continues to follow price upward.
SELL Signal: Once price drops below entry by the activation distance, the stop-loss trails down to current price plus the trailing stop distance.
Best For: Strong trending markets where you want to capture as much of the move as possible without giving back profits on pullbacks.
Step-by-Step Workflow
Step 1: Attach to Chart Drag the EA onto any chart where you have open positions or plan to open them manually. Make sure AutoTrading is enabled in MetaTrader.
Step 2: Configure Parameters Set your breakeven activation distance (e.g., 10 pips), trailing stop distance (e.g., 20 pips), and decide whether to use the magic number filter to only manage trades opened by this EA.
Step 3: Monitor Positions The EA will scan all open positions on the chart's symbol (or all symbols if configured) and apply stop adjustments as conditions are met.
Step 4: Review Logs If SHOW_LOGS is enabled, check the Experts tab in the Terminal window to see exactly when and why each stop was moved.
Step 5: Adjust as Needed You can change parameters while the EA is running — new settings apply immediately to subsequent checks.
4. RISK MANAGEMENT FEATURES
This EA bundles several protective features that work together to safeguard your capital while letting profits run.
| Feature | Description |
|---|---|
| Breakeven Activation | Moves the stop-loss to your entry price (plus a small buffer) once a predefined profit level is reached. This eliminates the risk of a winning trade turning into a loser — a core principle of good risk management. |
| Trailing Stop | Once price moves beyond the activation distance, the stop-loss follows price at a fixed distance. This locks in profits as the trend extends, while still giving the trade room to breathe on minor retracements. |
| Hidden SL/TP | When enabled, the stop-loss and take-profit levels are not sent to the broker — they're managed virtually by the EA. This prevents brokers from seeing your stops and potentially hunting them. Useful for scalpers and those on dealing desk brokers. |
| Magic Number Filter | When enabled, the EA only manages trades with a specific magic number, leaving your manual trades untouched. This is critical if you run multiple EAs or trade manually alongside automated systems. |
| Risk/Reward Ratio | If set above zero, the EA automatically calculates a take-profit level based on your stop-loss distance multiplied by this ratio. For example, a 2:1 ratio with a 20-pip stop gives a 40-pip target. This enforces consistent risk management across all trades. |
Quick Start Guide
Follow these steps to get started in under 5 minutes:
- Download and Install: Purchase the EA from the MQL5 Market, then download and install it via the MetaTrader Navigator panel (drag to Charts folder).
- Attach to Chart: Open a chart for any symbol you trade (EURUSD, GBPJPY, etc.) and drag the EA onto it from the Navigator. A settings dialog will appear.
- Set Basic Parameters: Start with LOTS at 0.01 for testing, enable USE_BREAKEVEN, set BREAKEVEN_ACTIVATION to 10 pips, and BE_EXTRA_PIPS to 2.
- Configure Trailing Stop: Set your trailing stop distance (e.g., 20 pips) and activation distance (e.g., 15 pips). Leave USE_TRAILING_STOP enabled.
- Enable Logging: Set SHOW_LOGS to true for your first run so you can see what the EA is doing in the Experts tab.
- Test on Demo First: Run the EA on a demo account for at least a week with real market conditions. Watch how it adjusts stops on winning and losing trades.
- Go Live: Once you're comfortable with the behavior, switch to a live account. Start with small lot sizes and monitor closely for the first few days.
Installation Guide for MQL Products | Updating Purchased MQL Products on MT4/MT5 | General Troubleshooting Guide | Backtest and Set Files
Check all my products: https://www.mql5.com/en/users/biswait50/seller
Contact me for support: https://www.mql5.com/en/users/biswait50


