Double Trailing Stop MT5
- Utilidades
- Francisco Manuel Vicente Berardo
- Versión: 1.2
- Actualizado: 5 octubre 2024
- Activaciones: 20
The Double Trailing Stop is a multi-symbol multi-timeframe Expert Advisor that allows the Stop Loss and Take Profit trailing of positions.
General Description
The Double Trailing Stop’s purpose is to secure profit and minimize losses of the opened positions. The Expert Advisor places stop orders (Stop Loss or Take Profit) at the Trailing Stop distance from the market price when the symbol's quote reaches/overcomes the Trailing Start distance from the position’s opening price (a single-time requirement) and the Trailing Step distance from the price where the previous stop order’s modification occurred (a continuous requirement). To select the positions whose stop orders are updated by the Expert Advisor, the symbol of the chart (to which the EA is attached) and the (EA's) magic number must match those of the positions.
Input Parameters
- Magic Number: Expert Advisor’s identifier.
- Trailing Stop – SL: Distance from the market price for placing a Stop Loss after a favourable price movement (pips).
- Trailing Start – SL: Distance from the position’s opening price that must be reached for the “Trailing Stop – SL” function’s activation (pips).
- Trailing Step – SL: Distance from the price where the previous Stop Loss modification occurred that must be reached before the placing of a new Stop Loss (pips).
- Trailing Stop – TP: Distance from the market price for placing a Take Profit after an unfavourable price movement (pips).
- Trailing Start – TP: Distance from the position’s opening price that must be reached for the “Trailing Stop – TP” function’s activation (pips).
- Trailing Step – TP: Distance from the price where the previous Take Profit modification occurred that must be reached before the placing of a new Take Profit (pips).
- Comment: Text message displayed in the chart window after a(n) (re)initialization of the EA.
Some of the available parameters accept values that lead to particular options.
- Magic Number: A null value means positions opened manually or automatically with the 0-default value.
- Trailing Stop – SL or Trailing Stop – TP: A null value means the parameter’s inactive function. Any value between 0 and the Stop Level is converted in this last.
- Trailing Start – SL or Trailing Start – TP: A null value means the “Trailing Stop – SL” or “Trailing Stop – TP” function’s immediate activation, respectively.
- Trailing Start – SL: The spread value means the “Trailing Stop – SL” function’s activation at breakeven, although such hasn't been guaranteed. The spread + “Trailing Stop – SL” values mean the “Trailing Stop – SL” function’s activation in a profit where breakeven has been guaranteed.
- Trailing Step – SL or Trailing Step – TP: A null value means the “Trailing Stop – SL” or “Trailing Stop – TP” function’s continuous operation, respectively.
Displayed Information
The Expert Advisor possesses a vast number of messages to inform the user about errors and conditions changes that might occur during its operation. The messages are shown through the Alert function (by a pop-up window), its content includes:
- The previous and current value of the symbol’s Stop Level when this is updated.
- The Trade Server Return Codes description.
- The symbol’s quotes (immediately) before the trade request’s formation, followed by the symbol’s quotes (immediately) after the trade server’s decision.
- The Runtime Errors description.
- The standard function in the include file where the runtime error was detected (only relevant to the programmer).
- The Uninitialization Reason Codes description.
Note: Some elements of the list are displayed simultaneously (in the same text line): 2, 3 and 4; 4 and 5.
During the EA’s operation, the messages displayed are grouped by kind of occurrence (related to each list’s element, except the 3 and 5) and counted. Immediately before the EA’s unloading, a final message containing those groups with the respective counts (if these were > 0) is presented.
Observations
In some cases, the quoting session might start before or end later than the corresponding trading session (with a five-minute difference, for instance). During the time interval when the quoting session is open, but the trading session is still/already closed, the Expert Advisor initiates/continues to process the available ticks, respectively. If the present conditions satisfy the EA's trading criteria, a trade request is formed and sent to the server. However, it won’t succeed, and an error message is displayed: “Trade request sending failed; Market is closed”.
During high activity periods, the trade server’s decision on whether a trade request is executed or rejected may suffer significant delays. Some data used in the request sent to the server might become incorrect, leading to the order’s rejection. When the server is evaluating a request and the symbol's quotes are updated, three cases might occur:
- Pending order placing – the pending order’s target price becomes an incorrect distance.
- Position opening/modifying – the position's Stop Loss or Take Profit intended level becomes an incorrect distance.
- Position modifying – the position's Stop Loss or Take Profit previous level takes to its closing.
The symbol’s quotes mentioned in the third element of the list in the Displayed Information section are especially useful here (since firsts usually differ from lasts). A careful analysis of these quotes, knowing the implication that certain quote changes have on the request’s evaluation, permits understanding the reason when these cases occur. To avoid the request’s rejection by the trade server due to “invalid stops” (cases 1 and 2), the prices/levels used should exceed the symbol’s Stop Level by a few pips.
Conclusion
The Double Trailing Stop is a helpful and effective tool regarding the automatic Stop Loss and Take Profit trailing of positions, enabling a simple and intuitive setting of the positions' stop orders to be trailed.