双线突破金叉死叉趋势追踪策略是一种同时利用支持阻力线和移动平均线作为备选信号的趋势追踪型量化交易策略。该策略综合考虑价格在不同时间段内的支持阻力位和移动平均线的金叉死叉信号,在捕捉到价格突破重要的支撑和阻力位时,结合趋势指标过滤做多做空机会,实现在趋势变化早期开仓,追踪中长线趋势的盈利目标。
该策略主要由四个部分组成:
具体来说,策略首先利用请求Security函数获取30日和30周内的最高价和最低价,分别划定动态的支撑线和阻力线。然后结合10日移动平均线的金叉和死叉信号来过滤突破交易机会。当价格高于30日内支撑位且高于10日均线时产生做多信号;当价格低于30周内阻力位且低于10日均线时产生做空信号。
该策略同时考虑中短线和长线的支撑阻力,能捕捉较大的趋势机会。同时结合移动平均线可有效过滤震荡趋势中的错误信号。
该策略具有以下几点优势:
该策略也存在一些风险需要注意:
对应解决方法:
该策略还有进一步优化的空间:
双线突破金叉死叉趋势追踪策略综合考虑中长线的支持阻力位和移动平均线指标作为交易信号,在大趋势背景下能够有效过滤噪声实现盈利,是一种较为成熟的量化交易策略。该策略优化空间还很大,可从止损机制、参数自适应等方面进行改进,也可尝试引入机器学习等新方法提高策略的稳健性。
/*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)