Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Break-Even and Trailing Stop Manager for Open Positions - expert for MetaTrader 5

Kenichiro Sakamoto
Kenichiro Sakamoto
5 (2)
I'm Kenichiro Sakamoto, the developer behind FXEA365 — a studio building transparent, rule-based Expert Advisors for MetaTrader 5.
Views:
42
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

This Expert Advisor does not open any trades. It watches the positions that are already open on the account, whether they were opened manually, from the mobile terminal or by another Expert Advisor, and manages only their stop loss. The take profit of each position is kept unchanged.

The logic has two stages. When a position gains the number of pips set in the break-even trigger, its stop loss is moved to the open price plus a small locked profit. After that the trailing stop follows the price at a fixed distance in pips or at a multiple of ATR, and the stop loss is moved only in the direction of profit.

Fig. 1. The manager attached to a EURUSD H1 chart

Input parameters

  • InpAllSymbols - manage positions of all symbols (true) or only of the chart symbol (false).
  • InpMagic - manage only positions with this magic number; 0 means all positions.
  • InpUseBreakEven - enable the break-even stage.
  • InpBETriggerPips - profit in pips that moves the stop loss to break-even.
  • InpBELockPips - profit in pips locked in when the stop loss is moved to break-even.
  • InpUseTrailing - enable the trailing stop.
  • InpTrailMode - trailing distance as fixed pips or as an ATR multiple.
  • InpTrailPips - trailing distance in pips for the fixed mode.
  • InpATRPeriod and InpATRMultiplier - ATR period and multiplier for the ATR mode (the ATR is read on the chart timeframe).
  • InpStepPips - the stop loss is moved only when it improves by at least this many pips, which reduces the number of modification requests.

How to use it

Attach the Expert Advisor to one chart and allow algorithmic trading. For a single symbol keep InpAllSymbols set to false. To protect positions on several symbols from one chart, set it to true; the timer runs every second, so positions on other symbols are managed even when the chart symbol has no new ticks.

One pip is 10 points on 3 and 5 digit quotes and 1 point on other symbols. Before each modification the new stop loss is checked against the stops level of the symbol, so requests that the server would reject are not sent. The trailing stop starts only when the new stop loss is beyond the open price.

Symbol Specification Probe - tick size, tick value, money value of a stop Symbol Specification Probe - tick size, tick value, money value of a stop

The probe prints the values a symbol specification supplies: digits, point, trade tick size, trade tick value, contract size, volume minimum, volume maximum, volume step and the stops level. Trade tick size is the smallest price change the instrument can make, trade tick value is the money one tick is worth for one lot, and the stops level is the minimum distance in points the reference gives for a stop away from the current price. It then prices a stop at the volume you enter, taking the pip as ten points on a 3- or 5-digit symbol and one point on every other symbol: the pip count times the pip gives a price distance, the distance over the trade tick size gives ticks, and ticks times trade tick value times volume gives the money.

Gaussian Auto EA Gaussian Auto EA

Trend-following breakout EA using a Gaussian-filtered channel, ATR bands, risk-based lot sizing, and an R-multiple trailing stop.

Equity Drawdown and Daily Loss Guard Equity Drawdown and Daily Loss Guard

Utility Expert Advisor that closes all open positions when equity falls a set percentage below its peak or when today's loss reaches a limit. It never opens trades.

One-Click Buy Sell Close Panel with Pip Stops One-Click Buy Sell Close Panel with Pip Stops

Chart panel Expert Advisor with BUY, SELL and CLOSE buttons. Market orders use a fixed lot with stop loss and take profit in pips, and the panel shows the floating profit of its trades.