Different kinds of Trailing Stop in ProOrder

 

Managing stop loss and risk with opened positions in an automated strategy is primordial. While we secure profit, we also limiting risk of bad win/loss ratio in a long run, with the help of “moving stop loss” aka trailing stop.

The ProOrder language embed different kinds of trailing stop and i describe them all in this article.

Trailing stop definition

A trailing stop is a stop loss price that moves with the market. For instance, if you are buying an asset and the price goes up, the stop loss will move according to the trailing setup you have defined (percentage of loss, amount of points).

In that specific case, if the price goes down, your stop loss will be executed with profit, but only if the price have moved enough for the stop loss to be set above your entry price.

trailing-stop-picture

For a short position, the price has to move south enough for the stop loss to be set below the entry price.

While it is a great way to secure profit in an automated trading strategy, it is also a very valuable way to set a loss limit with false trading signals (e.g. : buy an asset that is too close of a big resistance area).

 

Price related trailing stop setup

In ProBuilder language, there is 2 different kinds of trailing stop for setting up a price related moving stop loss :

SET STOP TRAILING y
Sets a trailing stop y units from average position price.

and

SET STOP pTRAILING y
Sets a trailing stop y points from average position price.

Units and points are different between instruments, because units depends on price digits and points is a constant value.
Example : (from the ProBacktest documentation)

On the EuroDollar (EUR/USD), 1 point =0.0001 units on the chart
On index Futures (DAX, FCE), 1 point = 1 unit on the chart
On futures on european interest rates,1 point = 0.01 units on the chart

 

Simple long only strategy on GBPUSD code example :

The result of using trailing stop on this little strategy on a daily basis talk by itself :

Without a trailing stop :

GBPUSD_no trailing stop

With a trailing stop :

GBPUSD_with trailing stop

 

Using “units” based for this forex pair would be :

Because GBPUSD has 4 digits and 50 points is 0.0050 units for this instrument. Of course result would be the same as the first example, but the units stop loss and trailing stop is useful for dynamic calculation of its value.

For instance, you could use ATR which returns only units values and not point ones :

 

Percentage from price trailing stop

Another way of moving the stop loss is to set a percentage of variation of the price in the direction of the opened positions.

 

SET STOP %TRAILING y
Sets a trailing stop y% percent(s) from average position price.

 

In this example, if the price has moved +1% since inception of the trade, then the stop loss will move +1% higher than its last placement :

 

Risk related trailing stop

The other kind of trailing stop that are embed in ProBuilder language is risk related one. It sets the stop loss according to an amount of money that the strategy have won with the average of the currently opened positions prices.

 

SET STOP $TRAILING y
Sets a trailing stop y €,$ (currency of the instrument) from average position price. Brokerage fees not included.

 

Example :

 

Setting up stop loss and trailing stop at once

Within ProBuilder, we can setup the stop loss and the trailing stop parameters in a single line of code. In the documentation it is described as the picture below :

trailing stop prorealtime

It does not affect in any way the ProBacktest/ProOrder behaviour in any way, it is only a more convenient way to code these 2 important instructions.

Examples of use : (from the ProBacktest documentation)

A stop loss is placed at x units from entry price and it becomes a trailing stop of y units if the trailing stop level becomes closer to current price than the stop loss level (when price varies favourably by y units – x units).

 

A stop loss is placed at x units from average position price and it becomes a trailing stop of y points if the trailing stop level becomes closer to current price than the stop loss level (when price varies favourably by
y points – x units).

 

A stop loss is placed at x units from average position price and it becomes a trailing stop of y$ or € (currency of the instrument) if the trailing stop level becomes closer to the current price than the stop loss level.

 

A stop loss is placed at x units from average position price and it becomes a trailing stop of y% if the trailing stop level becomes closer to the current price than the stop loss level.

 

A stop loss is placed at x points from average position price and it becomes a trailing stop of y units if the trailing stop level becomes closer to current price than the stop loss level (this occurs when price varies favourably by y units – x points).

 

A stop loss is placed at x points from average position price and it becomes a trailing stop of y points if the trailing stop level becomes closer to current price than the stop loss level (this occurs price varies favourably by
y points – x points).

 

A stop loss is placed at x points from average position price and it becomes a trailing stop of y $ or € (currency of the instrument) if the trailing stop level becomes closer to the current price than the stop loss level.

 

A stop loss is placed at x points from average position price and it becomes a trailing stop of y% if the trailing stop level becomes closer to the current price than the stop loss level.

 

A stop loss of x $ or € (currency of the instrument) is placed and it becomes a trailing stop of y units if the trailing stop level becomes closer to current price than the stop loss level.

 

A stop loss of x $ or € (currency of the instrument) is placed and it becomes a trailing stop of y points if the trailing stop level becomes closer to current price than the stop loss level.

 

A stop loss of x $ or € (currency of the instrument) is placed and it becomes a trailing stop of y $ or € (currency of the instrument) if the trailing stop level is closer to the current price than the stop loss level.

 

A stop loss of x $ or € (currency of the instrument) is placed and it becomes a trailing stop of y% if the trailing stop level becomes closer to the current price than the stop loss level.

 

A stop loss of x% is placed and it becomes a trailing stop of y units if the trailing stop level becomes closer to current price than the stop loss level.

 

A stop loss of x% is placed and it becomes a trailing stop of y points if the trailing stop level becomes closer to current price than the stop loss level.

 

A stop loss of x% is placed and it becomes a trailing stop of y $ or € (currency of the instrument) if the trailing stop level is closer to the current price than the stop loss level.

 

A stop loss of x% is placed and it becomes a trailing stop of y% if the trailing stop level becomes closer to the current price than the stop loss level.

 

Managing existing positions

Using a trailing stop on a single or a basket of positions is always a good option and would be use only accordingly to a strategy that  needs it. If you do not stop and reverse positions or if you are working on percentage price movement only, i think it is the better way to manage opened positions. While every paths lead to Rome, everyone will find utilities or not to trailing stop. Setting them up with the ease of ProBuilder will not exhaust anyone, so let’s give a try in all your automated strategies !

Share this

  1. MikeGC • 01/02/2016 #

    Thanks Nicolas, these are of great assistance.  However I have posted a query on the ProOrder Support forum relating to an indicator based stop loss (Super Trend) and a chart based stop loss (Swing Highs or Lows).  I trust you will be able to assist. 

    • Nicolas • 01/02/2016 #

      Hello Mike, I’ll have a look at your query.

  2. Bob • 01/02/2016 #

    Hi Nicholas. How should I code a trailing stop on FX instrument in order to be 5 pips below the 50 exponential moving average if I am buying or vice versa if I am short as an example? Thanks

    • Nicolas • 01/02/2016 #

      Hello Bob, in order to do that you should first know the pips difference between the bar open and the moving average and then add or subtract 5 pips to the result. Then use the “pTrailing” if the result is an absolute number with an IF conditional statement.

  3. jayvee • 01/02/2016 #

    Hi Nicolas, i find that my trailing stop moves backwards sometimes. For example, if the price goes up initially, the trialing stop will move up too (as expected), then if price starts to come down, the trailing stop will move down to where it was before. I thought the trailing stop gets locked once it moves in a particular direction? Code is below. Can you help – i’m stumped…

    //REM INDICATOR
    atr= averagetruerange[10](close)
    // Stops and targets
    set stop loss 3*atr
    set stop trailing 4*atr

    • Nicolas • 01/02/2016 #

      You are using the ATR value which is not fixed and calculated on each bar, that’s why your trailing stop is moving that way. You can use ATR, but better to save its value when you open an order for instance and use it as a fixed value.

    • jayvee • 01/02/2016 #

      Ahh I see, thank you Nicolas that makes sense! How would I fix the value of the atr so it’s only based on the entry bar in the coding?

    • Nicolas • 01/02/2016 #

      store its value in a variable when you enter the market.

    • jayvee • 01/02/2016 #

      Thanks Nicolas. So there’s no way of actually coding it so it’s automated? I.e. a code to determine a fixed atr value based on the opening bar?

    • Nicolas • 01/02/2016 #

      What I told you is a way to automate it, anyway here is how you should code it:
      if buycondition then
      atr = averagetruerange[14]
      buy at market
      endif
      set stop trailing atr

    • jayvee • 01/02/2016 #

      Cheerio Nicolas, I’m new to this so appreciate it

  4. Pascal W • 01/02/2016 #

    Bonjour,

    Je viens d’ouvrir un compte avec IG et lorsque je lance ProOrder avec un STOP suiveur, je reçois le message d’erreur suivant:

    Les changement suivants doivent être appliqués avant d’envoyer le code à ProOrder ”les stops suiveurs ne sont pas autorisés sur les comptes à risque limité”. La compilation est ainsi pas possible. Quelle solution faut-il appliqué pour utiliser la fonction ‘STOP suiveur’? Merci d’avance pour votre réponse. Pascal

    • Nicolas • 01/02/2016 #

      En effet, les comptes à risque limité ne peuvent pas avoir de trailing stop. L’idée c’est d’utiliser un trailing stop en version codée, comme tu pourras en trouver énormément sur les forums. Une simple recherche avec le terme “trailing stop” devrait aider 🙂

  5. SB-FO • 01/02/2016 #

    Nicolas et. al,

    Is there a way to specify stop loss, say %Trailing, for specific security? Example, %Trailing 10 for TQQQ but %Trailing 5 for SQQQ with is the inverse to TQQQ. In building a long only strategy using inverse ETF’s I cannot find how to specify

    As always, thank you for your help.

    Stuart

    • Nicolas • 01/02/2016 #

      There is no way to identify the current instrument. You can test a precise price at a specific date, or price range for instance, this is what is commonly used by coders.

  6. SB-FO • 01/02/2016 #

    Okay but disappointing. For an algo, calculating a price range would have to me modified regularly since price is dynamic.

    Thanks for the help.

  7. SB-FO • 01/02/2016 #

    Nicolas,

    I have coded and back tested the two tickers independently, as opposed to long /short together, and now have two independent trading systems. While they are both technically long, one is an inverse of the other. Is there a way to tell PRT Autotrader to not trade the inverse strategy unless the long strategy is not long? So If Not LongOnMarket (Strategy A?) Then (BUY Equity SHARES AT MARKET) perhaps?

    Also, is there a way to tell PRT to buy at the midpoint of current BId/Ask of current price, as opposed to at “Buy Equity SHARES at Market”, when a condition is met? So perhaps “Buy Equity SHARES at midpoint of current price”?

    As always, thank you for your help.

    Stuart

    • Nicolas • 01/02/2016 #

      Each strategy is independent and can’t interact with another one.

  8. SB-FO • 01/02/2016 #

    I thought that might be the case.

    How about the second question above on mid-price of current bid/ask?

    Stuart

  9. SB-FO • 01/02/2016 #

    NIcolas, on my back-tests, I get the best results with a 4% %stop and 1% %Trailing. My question is how PRT handles when the stock trades down in the first bar, which for me is a 4H bar? An example is today. My back-test indicators this morning went short at the open, market rallied and my lines retracted and did not cross, thus no cross of lines as an exit. Would PRT use the 4% Loss or the 1% Trailing to exit the position as stock rallies 5% from the short buy? If the %Trailing kicks in, why does one need the %Loss?

    In a rising market, easy to understand, but a day like today I am trying to understand the mechanics.

    I should also ask, since the signal lines retracted as opposed to cross, what is the reentry signal that PRT will see? I presume the next signal cross short and the system misses the last part of the upside and stays un-invested.

    As always, thanks for your help.

    • Nicolas • 01/02/2016 #

      The set stop trailing instruction is a trailing stop attached to your order and handle by him. PRT doesn’t control at all the way the stoploss are managed by the broker.

  10. SB-FO • 01/02/2016 #

    NIcolas, please define him above? Not asking about the broker, I am asking how the PRT backtest handles the %Loss and %Trailing loss as questioned above. Once I how how the backtest handles it, I can adapt for the broker if necessary. Main question, after entering a trade, market goes south, which one get triggered first, %Loss or %Trailing. If %Trailing, what is the purpose of the %Loss?

    Cheers, Stuart

    • Nicolas • 01/02/2016 #

      You can’t use both %Loss or %Trailing in the same strategy. While it works in backtest, IG will refuse it.

  11. SB-FO • 01/02/2016 #

    Ah ha, even though it is listed as an option above. I’m in the US so broker IB. So when running a back-test to simulate real world trading, perhaps best to use %Trailing?

    • Nicolas • 01/02/2016 #

      Better to use soft coded trailing stop, there are many examples in the forums and library. BTW, automatic trading is not yet possible with IB.

  12. guitarrocker • 01/02/2016 #

    Hello Everybody! Is there a way to deal with the “jumping” minimum stop distances regarding the Trailing Stop Loss? The “regular” Trading time ws over (>22h / US) and TSL was supposed to be set underneath the minimum distance – so the system stopped. I am thinking of something like If new SL is < minimum stop distance then new SL = SL else newSL = whatever coded… Or are there other ways, I am not thinking of? ;o) Thanks in advance & cheers!

  13. guitarrocker • 01/02/2016 #

    I’ve seen the button in the new Version – if someone’s searching for me, I#m in my chamber… blaming myself & be ashamed ;o)

avatar
Register or

Top