这是一个基于吞没形态的量化交易策略,通过识别市场中出现的多周期趋势线性吞没形态进行交易。策略核心是捕捉价格反转信号,结合持仓周期和风险控制,实现稳健的交易效果。策略适用于所有市场和时间周期,具有较强的普适性。
策略基于K线形态中的吞没形态进行交易。当出现看涨吞没形态时(较小阴线后跟较大阳线完全吞没前者),在下跌趋势中产生买入信号;当出现看跌吞没形态时(较小阳线后跟较大阴线完全吞没前者),在上涨趋势中产生卖出信号。策略通过参数化设置持仓周期,在指定周期后自动平仓,避免过度持仓带来的风险。
该策略通过系统化方法捕捉市场中的吞没形态机会,结合参数化的持仓管理实现风险可控的交易。策略具有较强的实用性和适应性,但仍需要交易者根据具体市场特征进行优化调整。建议结合其他技术指标和风险控制手段,提高策略的稳定性和可靠性。
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Engulfing Candlestick Strategy", overlay=true)
// Input parameters
bull_color = input.color(color.new(color.green, 0), title="Bullish Engulfing Highlight")
bear_color = input.color(color.new(color.red, 0), title="Bearish Engulfing Highlight")
hold_periods = input.int(17, title="Hold Periods", minval=1) // How many bars to hold the position
// Input for selecting the pattern (Bullish or Bearish Engulfing)
pattern_type = input.string("Bullish Engulfing", title="Engulfing Pattern", options=["Bullish Engulfing", "Bearish Engulfing"])
// Input for selecting the trade type (Long or Short)
trade_type = input.string("Long", title="Trade Type", options=["Long", "Short"])
// Conditions for Bullish Engulfing
bullish_engulfing = close > open and open < close[1] and close > open[1] and open[1] > close[1]
// Conditions for Bearish Engulfing
bearish_engulfing = close < open and open > close[1] and close < open[1] and open[1] < close[1]
// Declare the entry condition variable
var bool entry_condition = false // Set initial value to 'false'
// Entry logic based on selected pattern and trade type
if pattern_type == "Bullish Engulfing"
entry_condition := bullish_engulfing
else
entry_condition := bearish_engulfing
// Execute the entry based on the selected trade type
if entry_condition
if trade_type == "Long"
strategy.entry("Long", strategy.long)
else
strategy.entry("Short", strategy.short)
// Close position after specified number of bars
if strategy.position_size != 0 and bar_index - strategy.opentrades.entry_bar_index(0) >= hold_periods
strategy.close("Long")
strategy.close("Short")
// Highlight Bullish Engulfing Candles (Background Color)
bgcolor(bullish_engulfing and pattern_type == "Bullish Engulfing" ? color.new(bull_color, 80) : na, title="Bullish Engulfing Background")
// Highlight Bearish Engulfing Candles (Background Color)
bgcolor(bearish_engulfing and pattern_type == "Bearish Engulfing" ? color.new(bear_color, 80) : na, title="Bearish Engulfing Background")