A trailing stop-loss is a type of stop-loss order used in trading and investing to protect profits and limit potential losses, it is a dynamic form of a stop-loss order that automatically adjusts as the price of a symbol moves in a favourable direction. The trailing stop-loss "trails" or follows the price movement of the symbol at a specified distance or percentage.
The key benefit of using a trailing stop-loss is that it allows traders or an automated trading system to protect the profits in a trending market while giving the position room to grow. As long as the price continues to move in a favourable direction, the trailing stop-loss will continue to adjust and lock in gains. It is important to note that in a volatile market, a trailing stop-loss might get triggered prematurely due to short-term price fluctuations, leading to a potential exit before the asset reaches its full potential. Therefore, setting an appropriate trailing distance is essential to strike a balance between protecting gains and giving the position enough room to grow.
How Does the Trailing Stop Loss Work?
The code provided works differently from the default cTrader Trailing Stop Loss (TSL), below is an explanation.
TSL Trigger: this is the value in pips that a position must be in profit before the trailing stop is activated.
- TSL Step: this is the value in pips that the stop loss will move behind the price when the trigger is activated and will continue to trail behind the price as the price moves in favour.
The trailing stop feature activates once the position gains 20 pips (considering the spread for accuracy). The stop loss is initially set 5 pips behind the price. As the price moves in your favour, the stop loss adjusts accordingly. With each 5-pip gain, the stop loss is moved 5 pips further, maintaining a 5-pip distance from the price.
This dynamic trailing stop ensures that profits are locked in as the position gains pips, and if the price reverses and drops by 5 pips, hitting the stop loss, the position will be closed to prevent further losses. As long as the position continues to accumulate pips, the trailing stop will continuously adjust, securing profits at every 5-pip increment.
Additional Features
Some of these additional features included in this cBot are the option to turn on or off the TSL as well as a setting to adjust the stop loss on each price change or at the close of each candle (bar).
OnBar TSL? - If set to YES, the trailing stop loss will be adjusted only when the candle (bar) is closed, if set to NO, than it will use the OnTick method, so the trailing stop loss will be adjusted on each price change for the symbol.
How To View The Source Code
To view the source code for this cBot, you will first need to make sure you have downloaded and installed cTrader Desktop, you can also scroll to the bottom of this page for instructions on how to install the cBot. Once installed you will have the cTrader application open, next you need to navigate to the Automate application and click on the name of the cBot, the source should show in the right-hand window.
If you need more help watch a video tutorial on how to use cTrader Automate.
Learn Algorithmic Trading
In this instructional guide, we aim to assist you in acquiring the necessary skills to engage in market trading through automated trading strategies (cBots) using the cTrader Desktop trading platform. By the conclusion of this tutorial, you will gain the confidence to employ a cTrader cBot alongside the Algo application of cTrader, enabling you to automatically execute and handle your market orders. This course is designed to familiarize novice traders with the fundamental principles of algorithmic trading utilizing the cTrader platform.
Learn Microsoft C# for Algo Trading
If you are new to coding your cTrader cBot for automated trading the following Microsoft C# course will help you modify the starter kit cBot in this download to add new features for your own personal trading strategy.
Algorithmic Trading Facts
A significant number of traders venture into algorithmic trading with the misconception that they have discovered a foolproof strategy that guarantees effortless wealth. However, this notion is far from reality. It is crucial to read this article, as it can save you valuable time and money.
How To Install & Remove
First, make sure you have the cTrader trading platform installed and then simply unzip the file and double-click on it to automatically install it onto the platform.
Any Questions?
If you have any questions, please first search our coding help forum for the answer, if you cannot find it, post a new question.
Need Coding Help?
We can help you modify this cBot for your own personal trading strategy, contact our team for a quote.
Need a Broker
If you are still looking for a broker you can trust, take a look at our best cTrader broker site.