Understanding Trailing Stop Loss

shanmugapradeep

Active Trader
Dec 18, 2020
119
5
34
39
Hello,

I am finding little difficult in understanding Trailing Stop loss. How does it work, does it take value from Stop Limit, Trade Entry Price or Current Price or Highest Peak in Favorable direction.

After reading some blogs about Trailing Stop, This what i understand :-

  1. Condition: If the current price is greater than the entry price.
  2. Condition: If the difference between the current price and the entry price is greater than the trailing stop value.
  3. Action: Set a new stop loss level at the current highest price minus the trailing stop value.
  4. Additional Condition(favorable direction): If the difference between the new stop loss level and the current price is greater than the trailing stop value.
  5. Additional Action (favorable direction): Set a new stop loss level at the current price minus the trailing stop value.
Is this correct?
 
  • 👍
Reactions: penaltev

hayseed

Master Trader
Jul 27, 2010
1,170
276
149
usa
Hello,

I am finding little difficult in understanding Trailing Stop loss. How does it work, does it take value from Stop Limit, Trade Entry Price or Current Price or Highest Peak in Favorable direction.

After reading some blogs about Trailing Stop, This what i understand :-

  1. Condition: If the current price is greater than the entry price.
  2. Condition: If the difference between the current price and the entry price is greater than the trailing stop value.
  3. Action: Set a new stop loss level at the current highest price minus the trailing stop value.
  4. Additional Condition(favorable direction): If the difference between the new stop loss level and the current price is greater than the trailing stop value.
  5. Additional Action (favorable direction): Set a new stop loss level at the current price minus the trailing stop value.
Is this correct?
//------

it depends on how you code it...... traditionally the trailing stop is set by using ask or bid, not the current highest price......

modifying large numbers of orders at every tick can cause problems.....

occasionally the stoploss is set by other creative means..... such as, moving average, a trend line, zigzag points and similar.....

it all depends on how you want to code it......h
 

shanmugapradeep

Active Trader
Dec 18, 2020
119
5
34
39
it depends on how you code it...

Here is my code. it makes changes to every tick.

MQL4:
extern int Trailing = 5;
 
if(Digits == 3 || Digits == 5)
      Gd_376 = 10.0 * Point;
   else
      Gd_376 = Point;
 
double buyorderprice()
  {
   int cmd_16;
   double Ld_ret_0 = 0;
   double Ld_8 = 0;
   for(int pos_20 = OrdersTotal() - 1; pos_20 >= 0; pos_20--)
     {
      Sleep(1);
      if(OrderSelect(pos_20, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() != Symbol() || OrderMagicNumber() != BuyLimitMagic)
            continue;
         cmd_16 = OrderType();
         if(cmd_16 == OP_BUY)
           {
            Ld_ret_0 += OrderOpenPrice() * OrderLots();
            Ld_8 += OrderLots();
           }
        }
     }
   if(Ld_8 > 0.0)
      Ld_ret_0 = NormalizeDouble(Ld_ret_0 / Ld_8, MarketInfo(OrderSymbol(), MODE_DIGITS));
   return (Ld_ret_0);
  }
 
  void buytrailing()
  {
   double price_0 = buyorderprice();
   for(int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--)
     {
      OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == BuyLimitMagic)
        {
         if(OrderType() == OP_BUY)
           {
            if(Bid - price_0 > Gd_376 * Trailing)
              {
               if(OrderStopLoss() < Bid - Gd_376 * Trailing)
                 {
                  OrderModify(OrderTicket(), price_0, Bid - Gd_376 * Trailing, OrderTakeProfit(), 0, Blue);
                  return;
                 }
              }
           }
        }
     }
  }
 

hayseed

Master Trader
Jul 27, 2010
1,170
276
149
usa
Here is my code. it makes changes to every tick.
//------

the first function is returning the average lot weighted price...... average lot weighted price is the breakeven price of multiple orders with multiple open prices and multiple lot sizes.....

the second function uses that 'breakeven price to determine whether or not to modify the orders......

to me, that does not look feasible....... there might be some martingale type order setup where it would....... just shootin from the hip i'd say just use the tradition trailing stop logic......

try to use more ( ) to keep operation precedence clear......h

//------ i edited your code for clarity......

MQL4:
extern int Trailing = 5;
 
if(Digits == 3 || Digits == 5)
      point = 10.0 * Point;
   else
      point = Point;
 
 
 
double buyorderprice()
  {
   int type;
   double ave = 0;
   double lots = 0;
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      Sleep(1);
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() != Symbol() || OrderMagicNumber() != BuyLimitMagic)
            continue;
         type = OrderType();
         if(type == OP_BUY)
           {
            ave += OrderOpenPrice() * OrderLots();         // average lot weighted price
            lots += OrderLots();
           }
        }
     }
   if(lots > 0.0)
      ave = NormalizeDouble(ave / lots, MarketInfo(OrderSymbol(), MODE_DIGITS));
   return (ave);
  }
 
 
 
  void buytrailing()
  {
   double price = buyorderprice();
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == BuyLimitMagic)
        {
         if(OrderType() == OP_BUY)
           {
            if((Bid - price) > (point * Trailing))                      //  use (   )
              {
               if(OrderStopLoss() < (Bid - (point * Trailing)))         //  use (  )
                 {
                  OrderModify(OrderTicket(), price, Bid - (point * Trailing), OrderTakeProfit(), 0, Blue);    //  use (  )  and OrderOpenPrice() not price
                  return;
                 }
              }
           }
        }
     }
  }
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
19,270
1,515
144
Odesa
www.earnforex.com
Condition: If the current price is greater than the entry price.
If we are talking about buy order, yes.
Condition: If the difference between the current price and the entry price is greater than the trailing stop value.
That's an unnecessary condition for a classic trailing stop. This is a condition for "trailing stop on profit". So, if you want the TS to kick in only at a certain level of profit you could use such a condition. But it's best to use a separate value for checking there, not the actual trailing stop value. For example, you might want the TS to kick in only when you trade is in 20 pips of profit, but you want your TS distance to be 15 pips.
Action: Set a new stop loss level at the current highest price minus the trailing stop value.
That's almost like the classic TS works, but you don't want to use the High price, but rather Bid (for buy orders).
Additional Condition(favorable direction): If the difference between the new stop loss level and the current price is greater than the trailing stop value.
You mean the old stop-loss? Or rather the current stop-loss. That's the most important condition in the classic TS.
Additional Action (favorable direction): Set a new stop loss level at the current price minus the trailing stop value.
This should be the only action if we are talking about the classic TS.
 

fargana

Active Trader
Nov 14, 2022
223
29
39
34
Hello,

I am finding little difficult in understanding Trailing Stop loss. How does it work, does it take value from Stop Limit, Trade Entry Price or Current Price or Highest Peak in Favorable direction.

After reading some blogs about Trailing Stop, This what i understand :-

  1. Condition: If the current price is greater than the entry price.
  2. Condition: If the difference between the current price and the entry price is greater than the trailing stop value.
  3. Action: Set a new stop loss level at the current highest price minus the trailing stop value.
  4. Additional Condition(favorable direction): If the difference between the new stop loss level and the current price is greater than the trailing stop value.
  5. Additional Action (favorable direction): Set a new stop loss level at the current price minus the trailing stop value.
Is this correct?

Trailing stop loss is intended to maintain closing price on your position (stop loss price) as a function of a current price. Two cases:

If a price change is favourable , trailing stop loss adjusts closing price so it is equal (1-C)*current price where C is stop loss level in relative terms (%)

If price changes against you, stop loss level remains intact.

Closing price is updated after every new tick.
 
  • 👍
Reactions: penaltev

Nazzareno

Newbie
May 28, 2024
2
0
1
30
Trailing stop loss adjusts the stop loss level as the price moves favorably. Here's a simplified explanation:

1. If the current price exceeds the entry price by more than the trailing stop value, a new stop loss level is set.
2.This new level is typically below the highest price reached since the trade was opened.
3.As the price rises, the stop loss level moves up.
I4.f the price retraces and the difference exceeds the trailing stop value, the stop loss level moves down.

It's a tool to secure profits while allowing for potential gains.
 

fargana

Active Trader
Nov 14, 2022
223
29
39
34
Trailing stop loss adjusts the stop loss level as the price moves favorably. Here's a simplified explanation:

1. If the current price exceeds the entry price by more than the trailing stop value, a new stop loss level is set.
2.This new level is typically below the highest price reached since the trade was opened.
3.As the price rises, the stop loss level moves up.
I4.f the price retraces and the difference exceeds the trailing stop value, the stop loss level moves down.

It's a tool to secure profits while allowing for potential gains.
"Dumb" trailing stop with simple rules is unlikely to increase expected return, maybe a way to experiment is at least to adjust it considering near-term volatility level
 

Zerologic

Trader
Jul 17, 2024
198
8
19
As far as I know, a trailing stop is an automatic stop-loss modification, in MT4 we right-click on the ticket order and then select trailing stop, we can adjust the preferred trailing stop distance. However, the trailing stop in MT4 is only active if connected to the broker's server. So to use this feature MT4 must always be on.
 

fargana

Active Trader
Nov 14, 2022
223
29
39
34
As far as I know, a trailing stop is an automatic stop-loss modification, in MT4 we right-click on the ticket order and then select trailing stop, we can adjust the preferred trailing stop distance. However, the trailing stop in MT4 is only active if connected to the broker's server. So to use this feature MT4 must always be on.
I don't understand why it should be on, the broker got all necessary data like instructions when to close the trade...or client's trading platform like sending constant updates about how to change stop loss?
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,270
1,515
144
Odesa
www.earnforex.com
I don't understand why it should be on, the broker got all necessary data like instructions when to close the trade...or client's trading platform like sending constant updates about how to change stop loss?
MetaTrader servers work with orders. A trailing stop is not an order. It's a function set up in the platform and executed by the platform. And yes, it results in the platform sending order modification requests to the broker's server each time the stop-loss should be updated according to the chosen trailing distance.

Some platforms, like cTrader went the other way and made the trailing stop a server-side function. There, you can set it up and close the platform.