Trailing stop strategy TradingView
Warning: Declaration of ElementorPro\Modules\Posts\Skins\Skin_Content_Base::register_controls(Elementor\Widget_Base $widget) should be compatible with Elementor\Controls_Stack::register_controls() in /home/customer/www/backtest-rookies.com/public_html/wp-content/plugins/elementor-pro/modules/theme-builder/widgets/post-content.php on line 17 This week we are going to take a look at Tradingviewsbuilt-in trailing stop loss functionality. In particular, we are going to focus to the mechanics of how the trailing stop loss works and how this can cause some serious expectation issues. Show Disclaimer/Special Note: The issue discussed later in this article was present at the time of writing and in version 3 of pine script. Readers may wish to provide some counter arguments for why this may be a non-issue. If that is you, we would love to hear from you and will update the article accordingly if it is warranted. Setting Up A Trailing StoplossBefore we take a deeper look at the mechanics, we should first understand how to set up a trailing stop. Tradingviewstrailing stop functionality can be found within the strategy.exit() function. This functionhas 3 parameters that allow us to influence when the trailing stop shall start and the how far it will trail. Below is a snippet from the official docs:
Just as with stop loss and limit orders, we have two parameters that can be used to set the level at which the trailing stop loss activates. This is either an actual price you want to target or a number of ticks measured from the entry level. So what do we mean by activation level? Well, sometimes we dont want a trailing stop to trail immediately as soon as we open a position. We might only want to trail once a certainamount of profit has been met. Setting an activation level allows us to do this. Finally, we have the trailing offset, this is how far away from price we want to trail. This parameter must be specified in ticks. If ticks are a daunting subject for you, we are here to help! Check out the article:Tradingview: Working With Ticks Code ExampleThe following code example shows how to setup a trailing stop and provides some simple inputs which will allow you to play around with the various input parameters and subsequently, see how they affect the exits. Trailing Stop Example Code
The code simply starts buying as soon as the backtest date is reached. Once you enter a position it will setup a trailing stop loss based on the options you specify. Depending on when you copy this code and what instrument you test on, the start date and price levels shall need to be updated accordingly. Parameter TestingLets take some time to look at each individual parameter and how it affects our exits. The following examples are aimed to be as simple as possible. As such, the code and examples should be run on FX markets. Why? As we discovered in theworking with ticksarticle, a tick nicely equalsone pipette. This will make things easier to measure and verify on the lower FX timeframes. Trail Price + Trail OffsetIn our first example, we will take a look at using the trail_price parameter. As mentioned above, the trail price determines the level when the trailing stop becomes active. The trail_offset then determines how much the stop trails below price. As we can see in the chart, the trailing stop only becomes active once the trailing price is met. Following this, the trailing stop moves up with price following the highof each bar until it is eventually hit. Trail Points + Trail OffsetThe second example follows exactly the same example but instead this time we use trail_pointsto set our profit activation level. As we can see in the second example, trail points are used in exactly the same way. We are able to match the previous example by measuring to our desired activation level and setting the number of ticks appropriately. Next, try to adjust the offset. You will notice that the exit level moves up and down the wick as you adjust it. It will move up as you make the stop tighter and down as you loosen it off. Eventually, the exit will move to other bars if the settings are adjusted significantly. Trailing Stop Potential IssuesNext, we move onto take a look at some mechanical issues which can lead to unrealistic expectations. To be fair, these are not issues per se. They are limitations from working with historical data and receiving all of that data at the same time. However, as we will see, I would prefer to see Tradingview take an alternative approach when deciding how to deal with this limitation. Exaggerating ProfitsThe issue with the mechanics of the trailing stop is that Tradingview always assumes that price moved in your favour first during a bar. If you imagine we receive open,high,lowandclosedata all at the same time. We dont actually know if we hit the highs first or the lows. We also dont know how many times it bounced between the two. To help visualize this, see below. Tradingview always give you the benefit of the doubt. If you are in a long position, it will assume price hits the highs before the lows. If you are in a short position, it will assume it hit the lows before the highs. We can see this clearly in the following example: Worse still, if you set the trail to 0. You will exit at the top/bottom of each wick, giving you maximum profits! I think this example best demonstrates why this is a problem. Personally, I would prefer it to assume the opposite and take a pessimistic approach. If I am dealt the worst-case scenario and my strategy is still profitable, I know I am onto something. Instead, we can be lead to believe a strategy is very profitable when in fact, we would have very little chance replicating those results in the real world. Minimizing Drawdown In the same way that Tradingviews backtesting engine will exaggerate profits, it also minimizes losses and drawdown. If we never assume price moved against us first, our drawdown level may not look as bad as it actually would be if some trades go against us. One final point, these little extra profits add up to a huge return over the course of 100 + trades. To see just how much this can impact your results, use the commission parameter to add a small commission to your strategy and see how that impacts profitability. A small deduction (or addition in the case of trailing stops) can go a long long way! Find This Post Useful?If this post saved you time and effort, please consider support the site! There are many ways to support us and some wont even cost you a penny. Brave Tradingview PayPal BTC ETH LTC Brave Backtest Rookies is a registered with Brave publisher! Brave users can drop us a tip. Alternatively, support us by switching to Brave using this referral link and we will receive some BAT!
Tradingview Referral Link Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up! https://tradingview.go2cloud.org/SHpB PayPal
BTC 3HxNVyh5729ieTfPnTybrtK7J7QxJD9gjD ETH 0x9a2f88198224d59e5749bacfc23d79507da3d431 LTC M8iUBnb8KamHR18gpgi2sSG7jopddFJi8S Share this:
Related |