Trailing Stop in MetaTrader 4
Trailing stop allows you to automatically protect the profits with your positions. It adjusts itself according to the current market rate and the amount of pips you give it to trail behind. Trailing stop is a great tool for the conservative and long term traders as it easily creates protective «airbag» for the trades. There are two basic ways to set the trailing stop in your MetaTrader 4 platform — use the
- It should go into the action only when the position is in profit (or at a break even point).
- It should apply itself only when the difference between the current
stop-loss and the current market price is greater than the trailing stop value. - Trailing stop should never «decrease» the
stop-loss level. - If used without the initial
stop-loss , trailing stop doesn’t protect your position from the excess losses; it only provides a goodprofit-following tool.
Here are the details on these two ways:
The most easy and convenient way to set the trailing

This way of setting your trailing
The second method is to add a special expert advisor to some chart in your MetaTrader 4 platform and it will follow all open orders trying to apply the trailing stop value you give it in the input parameter. This is a very simple expert advisor that doesn’t load up your system resources and can be turned on and off anytime. Here is its code:
#property copyright "Copyright © 2009, EarnForex.com"
#property link "http://www.earnforex.com"
extern double TrailingStop = 5;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double PointValue;
for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
//Calculate the point value in case there are extra digits in the quotes
if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001;
else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01;
else PointValue = MarketInfo(OrderSymbol(), MODE_POINT);
//Normalize trailing stop value to the point value
double TSTP = TrailingStop * PointValue;
if (OrderType() == OP_BUY)
{ if ((Bid — OrderOpenPrice()) > TSTP)
{ if (OrderStopLoss() < (Bid — TSTP))
{ OrderModify(OrderTicket(), OrderOpenPrice(), Bid — TSTP, OrderTakeProfit(), Red); } } }
else if (OrderType() == OP_SELL)
{ if ((OrderOpenPrice() — Ask) > TrailingStop * PointValue)
{ if ((OrderStopLoss() > (Ask + TrailingStop * PointValue)) || (OrderStopLoss() == 0))
{ OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TSTP, OrderTakeProfit(), Red); } } } }
return(0);}
As you see, the code is really simple. You can also download this trailing stop EA and use it freely with your orders.
While, it lacks the disadvantages of the first MetaTrader trailing stop method, unfortunately, it also has two of its own important disadvantages. First, it works for all currently open orders. So, if you want attach it to only one order and leave another one without a trailing stop this method is not for you (but, of course, you can alter this EA to work with some specific orders). Second, it utilizes the same trailing stop value for all orders, you can’t set 10 pips trailing stop for one position and 50 trailing stop for another one. In case you want to use different
Tags: MetaTrader expert advisors, MT4, stop-loss, tutorial



May 7th, 2009 at 6:15 pm
hi dear
how to use your trailling stop?
please send me more guidliine
thanks a lot
[Reply]
Andrei Reply:
May 7th, 2009 at 7:08 pm
Doesn’t this article explain exactly what you ask?
[Reply]
September 23rd, 2009 at 11:17 am
Great info you got here. It’s really been helpful. Thanks!
[Reply]