The Dual Trendlines Breakout Golden Cross Death Cross Trend Following Strategy is a quantitative trading strategy that utilizes both support/resistance trendlines and moving averages as alternative signals for trend following. This strategy takes into account the price levels at different timeframes, combining the breakout signals through major support and resistance levels with the golden cross and death cross signals from the trend indicator, in order to open positions during early trend changes for the profit target of tracking mid-to-long term trends.
This strategy consists of four main components:
Specifically, the strategy firstly uses the Security request functions to obtain the highest highs and lowest lows over the past 30 days and 30 weeks respectively, plotting dynamic support and resistance lines. It then combines the golden cross and death cross signals from the 10-period SMA to filter breakout opportunities. Long signals are generated when price breaks above the 30-day support level and the 10-period SMA, while short signals are generated when price breaks below the 30-week resistance level and the 10-period SMA.
This strategy considers both medium-term and long-term support/resistance levels, allowing it to capture larger trend opportunities. Using the moving average filter also avoids false signals effectively during ranging trends.
The main advantages of this strategy include:
There are also some risks to note for this strategy:
Solutions:
There is room for further improvements:
The Dual Trendlines Breakout Golden Cross Death Cross Trend Following Strategy effectively combines medium-to-long term support/resistance and moving average indicators for filtering profitable signals during major trends, making it a relatively mature quantitative trading strategy. There is still large room for optimization via stop loss mechanisms, adaptive parameters etc. Incorporating machine learning can also enhance its robustness.
/*backtest start: 2024-01-22 00:00:00 end: 2024-02-21 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © neosaid //@version=5 strategy("Support and resistant Strategy", overlay=true) // Function to check for breakout f_breakoutCondition(closingPrice, highestHigh, lowestLow) => closingPrice > highestHigh or closingPrice < lowestLow // Step 1: 30 Days Trend Line (Lower Lows) low30Days = request.security(syminfo.tickerid, "D", low) // Step 2: 30 Weeks Upper Trend Line (Higher Highs) high30Weeks = request.security(syminfo.tickerid, "W", high) // Step 3: Trend Line for Lowest Low within the Last Month var float lowestLowLastMonth = na for i = 0 to 29 lowestLowLastMonth := na(lowestLowLastMonth) ? low[i] : math.min(lowestLowLastMonth, low[i]) lowestLowLastMonthValue = lowestLowLastMonth[1] // Breakout Strategy highestHighLast3Candles = request.security(syminfo.tickerid, "D", ta.highest(close, 3)) lowestLowLast3Candles = request.security(syminfo.tickerid, "D", ta.lowest(close, 3)) // Additional conditions to filter signals buyCondition = f_breakoutCondition(close, highestHighLast3Candles, lowestLowLast3Candles) and close > low30Days sellCondition = f_breakoutCondition(close, highestHighLast3Candles, lowestLowLast3Candles) and close < high30Weeks // Additional filters to reduce the number of orders buyFilter = ta.crossover(close, ta.sma(close, 10)) // Buy only when price crosses above a 10-period SMA sellFilter = ta.crossunder(close, ta.sma(close, 10)) // Sell only when price crosses below a 10-period SMA buyCondition := buyCondition and buyFilter sellCondition := sellCondition and sellFilter // Plot Buy and Sell signals on the chart plotshape(series=buyCondition, title="Buy Signal", color=color.green, style=shape.triangleup, location=location.belowbar) plotshape(series=sellCondition, title="Sell Signal", color=color.red, style=shape.triangledown, location=location.abovebar) // Strategy entries strategy.entry("Buy", strategy.long, when = buyCondition) strategy.entry("Sell", strategy.short, when = sellCondition)