I have been using several different trading styles based on the recommendations I have seen for using Trailing Stops. This discussion is intended to be strategy validation and programming based on the strategies. The discussion is focused on limitations and functions in MetaTrader 4.
There are a few philosophies when people explain Trailing Stops. The first main concept is "locking in profits". The idea is that as your position becomes more and more profitable, you want to keep those profits in case the market reverses. A trailing stop of 15 would keep your profits - minus 15 pips.
The second philosophy is "don't leave profits on the table". If you enter a trade and it is winning that is great! but we often kick ourselves to enter a trade, take our profit at 30 pips and watch the charts keep zooming along. Sometimes we take 30 pips when we could have had 100+ by using trailing stops.
A third philosophy does not use the trailing stop signal/menu in MetaTrader. In Hendrick's code for Phoenix 5.3 mode 3 trading, he slowly moves the trailing stop up to the open price, ensuring that trades moving in the right direction don't turn into losses. I haven't seen this in discussions anymore, so I will call it, "If I'm winning, don't loose."
Trailing stops have 3 main weaknesses I see.
#1 The client is very limited on the types of executions it will do for you. Minimum 15pip, must be profitable, conflicts with set TP levels (trade exits at TP), ...
#2 Trailing stops in the client only work on profitable trades, excluding "If I'm winning, don't loose" or the option of "loosing less" as time goes on strategy.
#3 Small variations in the market can lead to early exit. By default, a TS of 15pip means that at 15 pip profit, the SL kicks in at your entry price, and slowly climbs up pip by pip as the profits increase. If you know a trade is good for 50 pips (or your strategy requires it), a TS15 may exit at 0pip profit, or 12 pip profit and then continue up to your intended TP level.
#4 You are limited to a minimum of 15 pips under peak value, there are no tighter trailing stop options available in the client. Brokers I have tested will allow SL as close as 5 pip (IBFX and MIG) to market price. (NorthFinance is 10 pip from market.)
Code proposals:
Mode1: The first and most obvious code is trying to overcome issue #4, the 15 pip minimum. If a broker supports 5 pip under market SL, then we should be able to modify open trades to use 5 pip TS. Smaller values are more susceptible to issue #3.
Mode2: The second solution is to prevent issue #3 from happening, by letting TS kick in at a specific price. A StartTS value of 30pip with a TS of 5pip would guarantee a 25pip profit if the 30pip mark is hit. This would still be enough room for straight line runs in news events, etc. Entering a news event with a SL10, TP50 is probably more risky than SL10, StartTS15 TS5. This would also be useful many other situations and will likely result in more winning trades, while keeping most all or more of the profit that a static TP level offered.
Mode3: The third code proposal is based on what Hendrick already accomplished - preventing losses once the signal moves your way. This may also be additionally useful when trading based on Support/Resistance styles, moving SL to support resist after a quick pivot. The timing should be based on a minimum 'safe zone' to ensure price will keep going beyond support/resist instead of hovering near it, and possibly an optional maximum 'no fly zone' where you don't want SL to be configured.
These should all be Expert Agents or a script tied to a hot key for button mashing manual trading. For example, different settings could be loaded into different hotkeys, like CTRL-ALT-X "Mode2: erase TP if exists and set SL(price-5pip) now" or CTRL-ALT-Z "mode3: obey safety settings, set SL" vs CTRL-SHIFT-Z "mode3: ignore safety settings, set SL". One time saver would probably be, "mode3: set SL=BuyPrice" for the "If I'm winning, don't loose" philosophy.
An EA without a magic number could automatically modify all trades for the currency that the EA is active for. This would allow similar functionality to the client side Trailing Stops, but automatically set for all trades in the currency. This may also be a helper EA, by loading 2 EA in 2 charts of the same currency. Similar results to manual trading assistance, but running alongside any EA and modifying the other EA's trades.
Any code posted here (by author) is assumed to be copyright free and available for all to use unless explicitly stated otherwise. (Keyphrase: "I retain copyright") If you post code for reference and are not the author, please tell us that you are not the author. (Keyphrase: "I am not the author") Alternatively, you can retain copyright but grant a specific license. If you do choose a license, please pick one of the standard OSI approved licenses (GPL, QPL, Mozilla, etc). A list is available at
http://www.opensource.org/licenses/