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 built-in tool and attach a special EA that will apply a single trailing stop to all orders. But before going into describing these ways I’d like to tell you how the correct trailing stop should work:

  1. It should go into the action only when the position is in profit (or at a break even point).
  2. 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.
  3. Trailing stop should never «decrease» the stop-loss level.
  4. If used without the initial stop-loss, trailing stop doesn’t protect your position from the excess losses; it only provides a good profit-following tool.

Here are the details on these two ways:

The most easy and convenient way to set the trailing stop-loss is to click with the right mouse button on the order in the Terminal window and select the Trailing Stop submenu. There you’ll be able to either choose some of the preset amount of pips or enter a custom number:

Trailing Stop Order

Trailing Stop Select

This way of setting your trailing stop-loss is very convenient but it has two important disadvantages. The first con is that it doesn’t allow trailing stop lower than 15 pips. That’s probably not a problem for long-term traders, but it’s a great trouble for scalpers and short-term traders. And the second disadvantage of this method is that it doesn’t work properly with the brokers that provide extended quotes (5 and 3 digits after the dot instead of 4 and 2 digits). Trailing stop confuses the pips in this case and acts incorrectly.

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 stop-loss values for different orders you’ll have to heavily alter the code of this MT4 expert advisor.

Tags: , , ,

AddThis Social Bookmark Button

Similar Posts:

3 Responses to “Trailing Stop in MetaTrader 4”

  1. Saeid naghizad Says:

    hi dear
    how to use your trailling stop?
    please send me more guidliine
    thanks a lot

    [Reply]

    Andrei Reply:

    Doesn’t this article explain exactly what you ask?

    [Reply]

  2. Anton Peters Says:

    Great info you got here. It’s really been helpful. Thanks!

    [Reply]

Leave a Reply



Forex-Metal

Want more free resources on Forex? Visit FreeForexSites.com. Don't show me this offer ×