carefulCamel61097

Trend Following based on Trend Confidence

This is a Trend Following strategy based on the Trend Confidence indicator.
The goal of this strategy is to be a simple Trend Following strategy, but also to be as precise as possible when it comes to the question 'how confident are we that a linear trend is ongoing?'. For this we calculate the 'confidence' of a linear trend in the past number of closing prices. The idea of this strategy is that past a certain confidence, the ongoing linear trend is more likely to continue than not.

Trend Confidence:
The Trend Confidence shows us how strong of a linear trend the price has made in the past number (given by Length parameter) of closing prices. The steepness of the price change makes the Trend Confidence more extreme (more positive for an uptrend or more negative for a downtrend), and the deviation from a straight line makes the Trend Confidence less extreme (brings the confidence closer to 0). This way we can filter out signals by wild/sudden price moves that don't follow a clear linear trend.
Math behind the Trend Confidence:
A linear fit is made on the past number of closing prices, using Ordinary Linear Regression. We have the steepness of the linear fit: b in y=a+bx. And we have the standard deviation of the distances from the closing prices to the linear fit: sd. The Trend Confidence is the ratio b/sd.

Entries and Exits:
For entry and exit points we look at how extreme the Trend Confidence is. The strategy is based on the assumption that past a certain confidence level, the ongoing linear trend is more likely to continue than not.
So when the Trend Confidence passes above the 'Long entry" threshold, we go Long. After that when the Trend Confidence passes under the 'Long exit' threshold, we exit. The Long entry should be a positive value so that we go Long once a linear uptrend with enough confidence has been detected.
When the Trend Confidence passes below the 'Short entry' threshold, we go Short. After that when the Trend Confidence passes above the 'Short exit' threshold, we exit. The Short entry should be a negative value so that we go Short once a linear downtrend with enough confidence has been detected.

Default Parameters:
  • The strategy is intended for BTC-USD market, 4 hour timeframe. The strategy also works on ETH-USD with similar parameters.
  • The Length is arbitrarily set at 30, this means we look at the past 30 closing prices to determine a linear trend. Note that changing the length will change the range of Trend Confidence values encountered.
  • The default entry and exit thresholds for Longs and Shorts do not mirror each other. This is because the BTC-USD market goes up more heavily and more often than it goes down. So the ideal parameters for Longs and Shorts are not the same.
  • The positive results of the strategy remain when the parameters are slightly changed (robustness check).
  • The strategy uses 100% equity per trade, but has a 10% stop loss so that a maximum of 10% is risked per trade.
  • Commission is set at 0.1% as is the highest commission for most crypto exchanges.
  • Slippage is set at 5 ticks, source for this is theblock.co.

开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?