Position Manager Breakeven Partial Trailing
- Utilità
-
Cristian Bodisteanu
Sviluppatore MQL5 – Expert Advisor, indicatori e gestione del rischio per MetaTrader 5
Sviluppo e testo Expert Advisor, indicatori e script in MQL5 per MetaTrader 5.
Cosa ho realizzato per la mia ricerca di trading: - Versione: 1.0
- Attivazioni: 5
Position Manager Breakeven Partial Trailing takes care of positions that are already open: trades you opened by hand, from your phone, or by any other Expert Advisor. It does not open trades on your account. It only moves stop losses, closes part of a position once, and (if you want) closes everything at a set time.
Main features
- Break-even with lock offset. When the trade has moved far enough in your favour, the stop loss is moved to the open price plus a small offset (for example +10 points), so a few points are locked in.
- One-time partial close. At a profit level of your choice, a percentage of the position (for example 50%) is closed. This happens only once per position, even after a terminal or VPS restart: the utility remembers it in terminal global variables and also checks the deal history of the position.
- Trailing stop, three modes:
- Fixed points: the stop follows the price at a fixed distance.
- ATR: distance = ATR(period) x multiplier on the timeframe you choose, so the stop adapts to volatility.
- Candles: the stop sits below the lowest low (buy) or above the highest high (sell) of the last N closed candles, plus a buffer.
- Trailing starts only after a profit threshold and only moves the stop when the improvement is at least the step you set. The stop is never moved backwards.
- Triggers in points or in R. Break-even, partial close and trailing start can each use points of profit or R-multiples of the initial risk (distance from the open price to the first stop loss). R-based triggers are skipped for positions without a stop loss; points-based triggers still work.
- Time close (optional, off by default). Close all managed positions at a set server time on a chosen day (for example Friday 21:45), or every day.
- Filters. Manage only the chart symbol or all symbols; all positions, only manual positions (magic 0), or only one magic number.
- On-chart dashboard. Shows the number of managed positions, which features are on, the connection and Algo Trading status, and the last action. The panel can sit in any chart corner.
Built to respect broker rules
- Every stop loss change respects the symbol's stops level and freeze level, is rounded to the tick size, and is skipped when nothing would change.
- Volumes respect the minimum volume and volume step. If the partial volume would be below the minimum volume, the partial close is skipped and a message is printed once.
- Requests are throttled: the same stop loss is never sent twice in a row, and after a rejected request the utility waits before trying again for that position.
- Nothing is sent while the market of the symbol is closed, while Algo Trading is disabled, or while there is no connection.
- Every rejected request is printed in the Experts journal with the server return code.
- Works on hedging and netting accounts.
Inputs
Position filters
- Symbols to manage: Current chart symbol only or All symbols.
- Magic filter: -1 = every position, 0 = only manual positions, any positive number = only positions with that magic number.
Break-even
- Enable break-even: on/off.
- Break-even trigger type: points of profit, or R-multiple of the initial risk.
- Break-even trigger: profit in points: profit needed (points mode).
- Break-even trigger: profit in R: profit needed in R (R mode), for example 1.0 = profit equal to the initial risk.
- Lock offset beyond the open price (points): the new stop is placed this many points beyond the open price in the profit direction. Keep the trigger larger than this offset plus the broker's stops level.
Partial close
- Enable one-time partial close: on/off.
- Partial close trigger type: points or R.
- Partial close trigger: profit in points / profit in R: profit needed for the partial close.
- Volume to close (% of the current volume): for example 50. The volume is rounded down to the volume step, and at least the minimum volume is left open. 100 closes the whole position.
Trailing stop
- Enable trailing stop: on/off.
- Trailing mode: fixed distance, ATR x multiplier, or low/high of the previous N candles.
- Trailing start type: points or R.
- Start trailing after profit in points / in R: trailing begins only after this profit.
- Fixed mode: distance from price (points): distance of the stop from the current price.
- Minimum SL improvement per move (points): the stop is moved only when it improves by at least this amount (also used in ATR and candle modes).
- ATR / candle mode: timeframe: timeframe for the ATR and candle calculations (current chart timeframe by default).
- ATR mode: ATR period and ATR multiplier: distance = ATR x multiplier.
- Candle mode: number of closed candles: how many closed candles are used.
- Candle mode: buffer beyond low/high (points): extra distance beyond the candle low or high. For sell positions the current spread is also added.
Time close
- Close managed positions at a server time: on/off (off by default).
- Day: a weekday or Every day (server time).
- Hour and Minute: from this time until the end of that server day, all managed positions are closed, including positions opened after that time.
Execution
- Maximum slippage for closing deals (points): used for partial and time closes.
Dashboard
- Show dashboard, Dashboard corner, Horizontal / vertical distance from the corner (px), Font size, Background color, Text color, Title and border color.
Strategy Tester demo (ignored on live charts)
- Open demo trades in the Strategy Tester: in the tester, the utility opens small demo trades by itself so you can watch break-even, partial close and trailing work. It never does this on a live or demo account.
- Open a demo trade every N bars (when flat), Demo volume = minimum volume x this, Demo stop loss type (ATR or fixed points), Demo ATR period, Demo SL = ATR x this, Demo SL in points, Demo TP = SL distance x this.
How to use
1. Attach the utility to one chart. With Current chart symbol only, attach one copy per symbol you want to manage. With All symbols, one chart is enough. Do not let two copies manage the same positions.
2. Turn on Algo Trading in the terminal.
3. Set the filters and the features you want, then open your trades as usual (by hand, from the mobile app, or with another EA).
4. Keep the terminal running (a VPS is recommended): stop losses are moved by the terminal and then held by the broker's server.
Good to know
- The initial risk for R-multiples is taken from the stop loss of the opening order. If the position had no stop loss, it is taken from the first stop loss added later.
- If a position was already partially closed (by this utility, by hand or by another EA), no further partial close is made for it.
- Default values are in points, which mean different price distances on different symbols (for example forex vs gold vs indices). Check the values for every symbol you trade, or use the R-based triggers.
- This is a trade management tool. It does not predict the market and does not guarantee profit; results depend on your own trading decisions, your settings and market conditions. Test your settings on a demo account first.
