Capital SL Defender
- Utilitaires
- Version: 1.2
Capital SL Defender is a free position manager for MetaTrader 5. It does not open trades. You open them, and Capital SL Defender protects them: it gives every trade a stop loss and take profit, moves the stop to break-even once the trade is in profit, locks in part of the profit as the trade grows, limits how many trades you can open in a day, and shows it all on a black and orange panel on the chart. It runs on its own, with no outside service.
For profit locks by % of TP, the TP runner, trailing stops, loss caps, sessions and news, see Capital SL Defender Pro.
1.What it does
| Feature | What it does |
|---|---|
| Auto SL/TP | Gives every trade opened without an SL and TP both. By default the SL risks 1% of your balance and the TP targets 3%, at that trade's lot size, so it works the same on forex, gold, indices and crypto. % of price or pips with a reward:risk are also available. |
| Break-even | Once a trade has made $5 (or 15 pips), the SL moves to entry + 1 pip. |
| Profit lock | Once a trade's best profit reaches $25, the SL moves so you keep at least 50% of that best profit, and it follows each new best. |
| Daily entry lock | Up to 10 new trades a day. A trade opened after that, or while you've switched trading to INACTIVE, is closed straight away. |
| Dashboard | Balance, equity, today's P/L, what a trade of your lot size risks, the protections, and each open trade with its SL. A SETTINGS button changes the SL/TP on the chart. |
The stop loss only ever moves forward, never back, including across timeframe changes and MT5 restarts.
2.Requirements
- MetaTrader 5 (any broker, demo or live).
- Algo Trading turned on in the MT5 toolbar.
Nothing else: no web address to allow, no token, no DLLs.
3.Installation
From the MQL5 Market: Capital SL Defender Free appears in the Navigator under Expert Advisors → Market once downloaded. Go to step 3 below.
From the source file ( CapitalSLDefenderFree.mq5 ):
- In MT5, open File → Open Data Folder and copy the file into MQL5/Experts/ .
- Open it in MetaEditor (F4) and compile (F7). The result should read 0 errors, 0 warnings .
- Turn on Algo Trading in the toolbar (the button must be green).
- Drag CapitalSLDefender Free onto the chart of the symbol you trade.
- In the Common tab tick Allow Algo Trading, then click OK.
By default it manages the trades you open by hand on that chart's symbol. To protect every symbol from one chart, set ManageScope to every symbol.
4.Quick start
The defaults are ready to use. The inputs most traders change (the Inputs tab shows a short label for each; section 10 lists them):
- StopLossPercent and TakeProfitPercent : what a stop-out may cost and what the TP should make, as % of your balance. Default 1 and 3.
- SetLotSize : the lot size you usually trade, so the dashboard shows what such a trade risks.
- MaxEntriesPerDay : how many trades a day (default 10, 0 = no limit).
- ManageScope and MagicNumberFilter if you trade several symbols or want it to manage another EA's trades (section 10).
Then open a small trade on a demo account with no SL/TP. Within a second the EA adds them, and the trade's line on the dashboard shows the SL and how far it is to TP.
5.The dashboard
The panel sits at the top-left of the chart, below MT5's one-click Buy/Sell panel, or at the top-right. It updates once a second.
Status line: PROTECTING (green) while algo trading is allowed, ALGO TRADING OFF (red) when it isn't. On the right: what it manages (for example XAUUSD, manual trades ) and the server time.
| Section | Rows |
|---|---|
| Account | A SETTINGS button (section 6.3), balance, equity, floating P/L of the managed trades, today's P/L (closed and open managed trades; deposits are not counted), entries today against your limit. |
| Risk setup | What a trade of your lot size would risk: lot size, how the SL/TP is set, Risk at SL in dollars and % of balance, SL distance in points and % of price, Target at TP and TP distance the same way, reward:risk, and the Auto SL/TP switch. |
| Protection | Break-even and profit lock plans (or OFF), and the Trading switch. |
| Positions | Up to 5 trades, two lines each: symbol, side, lots and P/L; then progress to TP and where the SL sits ( SL +$12.40 locked , SL at break-even , or the dollars and % of balance at risk). |
Switches. Two rows are buttons you can click:
| Switch | On | Off |
|---|---|---|
| Auto SL/TP | Orange ON : trades opened without SL/TP get them | Grey OFF : new trades are left as they are |
| Trading | Green ACTIVE (orange when the daily limit is reached) | Grey INACTIVE : new trades are closed as they open (section 8) |
A click is remembered through timeframe changes and MT5 restarts. Changing the inputs resets Auto SL/TP to EnableAutoSLTP . Removing the EA from the chart forgets both.
DashboardSize Tiny shows only the status, SETTINGS, balance, equity, today's P/L, open trades and the Trading switch.
6.Stop loss and take profit
Any managed trade that opens without an SL and TP gets them within a second. A trade that already has an SL or a TP is left as it is. If the broker refuses the request (a busy server, a requote, a stop too close to price), the EA tries again on every tick until it is placed and writes the reason to the Experts log once. Once placed, it is never applied again to that trade.
SLTPMode (a dropdown) picks how the SL and TP are set.
6.1% of balance (default)
The SL goes where the trade would lose StopLossPercent (1%) of your balance, and the TP where it would make TakeProfitPercent (3%), at that trade's own lot size.
Example: $500 balance, 1% / 3%, gold at 2 decimals:
| Lot size | Risk at SL | SL distance | Target at TP | TP distance |
|---|---|---|---|---|
| 0.02 | $5.00 | 2.50 (250 points) | $15.00 | 7.50 (750 points) |
| 0.10 | $5.00 | 0.50 (50 points) | $15.00 | 1.50 (150 points) |
The bigger the lot, the closer the stop, so the dollar risk stays the same. 0 means no SL or no TP. If a very small lot would put a buy's SL below zero, the SL is left off and the Experts log says so.
6.2% of price, or pips
- % of price: the SL sits StopLossPercent of the entry price away and the TP TakeProfitPercent , whatever the lot size.
- Pips + R:R: the SL sits AutoSLPips (200) away and the TP RiskRewardRatio (2.0) times that. A pip is 10 points on 3- and 5-digit prices and 1 point otherwise, so on gold or BTCUSD at 2 decimals 200 pips is just 2.00. That is too close on BTCUSD, where the broker refuses it: use % of balance or % of price for crypto.
6.3The settings panel
Click SETTINGS on the ACCOUNT row and a panel opens beside the dashboard:
| Row | How to change it |
|---|---|
| SL / TP set as | Click to step through % of balance, % of price, Pips + R:R. |
| SL % / TP % | Type a number and press Enter. |
| SL (pips) / Reward : risk | Shown in pips mode. Type and press Enter. |
| Lot size (risk view) | The lot size the RISK SETUP figures are worked out for. |
| RESET TO INPUTS | Go back to the values in the Inputs window. |
Changes apply at once to the RISK SETUP rows and to the next trade without SL/TP; stops already placed are not moved. A value that isn't a number or is negative is refused. The panel's values survive timeframe changes and restarts; changing the Inputs window or RESET TO INPUTS goes back to the inputs. Click X to close it.
7.Break-even and profit lock
Break-even
Once a trade has made BreakEvenTriggerUSD ($5), or BreakEvenTriggerPips (15) when the dollar trigger is 0, the SL moves to entry + BreakEvenBufferPips (1). It happens once per trade. If the SL is already past that level, nothing changes.
Profit lock
Once a trade's best profit reaches ProfitLockTriggerUSD ($25), the SL moves so you keep ProfitLockPercent (50%) of that best profit, plus ProfitLockCushionPips (5 pips). As the best profit grows, the SL follows in steps.
Example: best profit $40 → the SL locks $20 plus 5 pips. If the trade then reaches $60, the SL moves to lock $30.
Both only move the SL forward, and only to a level your broker accepts.
8.Daily entry lock
MT5 can't stop a trade from being opened, so Capital SL Defender Free closes it instead. With EnforceEntryLock = true (default), a new managed trade is closed straight away when:
- today's MaxEntriesPerDay (10) trades have already been opened, or
- the dashboard's Trading switch is INACTIVE .
Every other new managed trade counts toward today's entries. Trades already open are never closed by the lock. The day starts at DayResetTime (00:00, broker server time). Set EnforceEntryLock = false to only count, or MaxEntriesPerDay = 0 for no limit.
9.Recommended setups
Standard (1% risk, 1:3)
SLTPMode = % of balance StopLossPercent = 1 TakeProfitPercent = 3 EnableBreakEven = true ($5, +1 pip) EnableProfitLock = true (from $25, keep 50%) MaxEntriesPerDay = 5
Careful (half a percent, 1:2)
StopLossPercent = 0.5 TakeProfitPercent = 1 BreakEvenTriggerUSD = 3 ProfitLockTriggerUSD = 15 MaxEntriesPerDay = 3
Forex in pips
SLTPMode = Pips + R:R AutoSLPips = 25 RiskRewardRatio = 2.0
10.Input reference
MT5's Inputs tab shows each input's label (the left column). The input name is what a saved .set file, this manual and the Experts log use. Labels changed in 1.01, names did not, so saved settings still load.
Which trades to manage
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Symbols to manage | ManageScope | This chart's symbol | This chart's symbol only, or every symbol on the account. |
| Trades: 0 manual, -1 all, or a magic | MagicNumberFilter | 0 | 0 = trades you open by hand, -1 = every trade, or one EA's magic number. |
Auto SL/TP: trades opened without one
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Add SL/TP to trades without them | EnableAutoSLTP | true | Give trades opened without SL/TP an SL and TP. Starting state of the Auto SL/TP switch. |
| How the SL/TP is set | SLTPMode | % of balance | % of balance, % of price, or Pips + R:R (section 6). |
| % modes: SL % (0 = no SL) | StopLossPercent | 1.0 | SL: % of balance lost if it is hit (% of price in that mode, 0 = no SL). |
| % modes: TP % (0 = no TP) | TakeProfitPercent | 3.0 | TP: % of balance gained if it is hit (% of price in that mode, 0 = no TP). |
| Pips mode: SL in pips | AutoSLPips | 200 | Pips mode: SL distance in pips. |
| Pips mode: TP = SL x this (2 = 1:2) | RiskRewardRatio | 2.0 | Pips mode: TP = SL distance × this (2.0 = 1:2). |
| Lot for the panel's risk figures | SetLotSize | 0.02 | Lot size the dashboard's RISK SETUP is worked out for. |
Break-even
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Break-even once in profit | EnableBreakEven | true | Move the SL to entry once the trade is in profit. |
| BE at profit, USD (0 = use pips) | BreakEvenTriggerUSD | 5.0 | At this profit (0 = use the pips below). |
| BE at pips of profit | BreakEvenTriggerPips | 15 | Or at this many pips. |
| Break-even buffer, pips | BreakEvenBufferPips | 1 | The SL goes this many pips past entry. |
Profit lock
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Keep a share of the best profit | EnableProfitLock | true | Once profit reaches the trigger, never give back more than set. |
| Starts at best profit, USD | ProfitLockTriggerUSD | 25.0 | Starts when the trade's best profit reaches this. |
| Share of the best profit kept, % | ProfitLockPercent | 50.0 | Keeps this % of the best profit. |
| Extra cushion, pips | ProfitLockCushionPips | 5 | Plus this many pips. |
Daily entry lock
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| New trades per day (0 = no limit) | MaxEntriesPerDay | 10 | New trades allowed per day (0 = no limit). |
| New day starts at (server time) | DayResetTime | 00:00 | When the day starts (server time, HH:MM). |
| Close trades opened while locked | EnforceEntryLock | true | Close a new trade opened while entries are locked. |
Dashboard
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Show the panel | ShowDashboard | true | Show the panel. |
| Side of the chart | DashboardSide | Left | Left or right side of the chart. |
| Panel size | DashboardSize | Large | Tiny, Small or Large. |
| Pixels from the chart edge | DashboardX | 10 | Pixels from the chart edge. |
| Pixels from the top (0 = auto) | DashboardTopY | 0 | Pixels from the top; 0 = automatic, below the Buy/Sell panel. |
| Accent colour | DashboardAccentColor | orange | Header and highlights. |
| Background colour | DashboardBackColor | black | Panel background. |
Strategy Tester
| Label in MT5 | Input | Default | What it does |
|---|---|---|---|
| Tester: open demo trades to manage | TesterDemoTrades | true | In the Strategy Tester only: while no managed trade is open, open a minimum-lot trade so the protections have something to manage. Never on a live or demo chart. |
| Minutes between demo trades | TesterDemoEveryMinutes | 240 | Minutes between those tester trades. |
11.Experts log messages
Every action is written to the Experts tab, starting ProfitGuardFree: .
| Text | Meaning |
|---|---|
| initialized, managing ... | Started; shows which trades it manages. |
| entry n/10 for today | A new trade was counted. |
| ENTRY LOCK | A new trade was closed because entries were locked; the reason is in brackets. |
| auto SL/TP - ticket ... | SL and TP added to a trade. |
| auto SL/TP not placed on ticket ... | The broker refused it, or it was too close to price; the EA keeps trying. |
| BE - ticket ... | SL moved to break-even. |
| LOCK - ticket ... | Profit lock moved the SL. |
| daily entry count reset | A new trading day started. |
| ... switched ... from the panel | Auto SL/TP or Trading was clicked. |
| setting ... from the panel / settings reset to the inputs | A value was changed on the settings panel, or reset. |
| tester demo buy/sell | A Strategy Tester demo trade (tester only). |
12.Troubleshooting
The panel says ALGO TRADING OFF. Turn on Algo Trading in the toolbar and tick Allow Algo Trading in the EA's Common tab.
Trades get no SL/TP.
- Check that the Auto SL/TP switch is ON.
- The trade must be in scope: on the chart's symbol, and opened by hand while MagicNumberFilter = 0 . The dashboard shows POSITIONS (0) when it isn't.
- A trade that already has an SL or a TP is left alone.
- On crypto in pips mode the SL is too close for the broker; use % of balance (section 6.2). The Experts log line auto SL/TP not placed gives the reason.
The SL is very far away (or very close). In % of balance mode the distance depends on the lot size: a small lot needs a wide stop to lose 1%. Check the RISK SETUP rows with your usual lot size.
My new trade closed straight away. Entries were locked: today's limit was reached or Trading is INACTIVE. The Experts log line ENTRY LOCK says which.
Break-even or profit lock doesn't move the SL. The trade hasn't reached the trigger yet, or the SL is already past that level. In the profit lock the SL moves in steps, not on every tick.
