双阴影形态反转策略是一种基于K线形态的短线交易策略。该策略通过识别出现连续两根K线都不存在影线的特殊K线形态,来判断可能的反转机会。策略的优点是简单明了,易于实现,但同时也存在一定的风险需要注意。
该策略的核心逻辑是识别“双阴影”形态。具体来说,策略会判断当前K线是否满足“开盘价等于最低价,收盘价等于最高价”的条件,即没有下影线和上影线,这种K线称为阴影线。如果前一根K线也满足这个条件,就认为出现了连续两根阴影线,即“双阴影”形态。
根据技术分析理论,这种双阴影形态通常预示着当前趋势即将反转。因为连续两根K线价格都在一个很窄的区间内波动,说明买卖双方力量趋于平衡,预示着反转的可能。
判断到双阴影形态后,策略会在下一根K线开盘时按收盘价进入做多或做空方向。并在设定的bar数后平仓离场。
策略思路清晰易懂,简单的形态判断,容易实现。
利用了经典的双阴影反转形态,有一定的技术分析依据。
操作频率不高,有利于降低交易成本和风险。
可方便加入回测功能,优化参数。
形态交易依赖历史图形统计概率,不能完全避免乖离。
虽然双阴影预示反转,但反转未必会发生或维持。
设定固定的止盈区间难以对付行情快速运行的情况。
只看一两个K线信息,容易造成过于激进出入场。
可以结合趋势指标,避免逆势操作。
可以 Wait for Confirm 进场,等待反转确认信号。
停止盈亏可根据ATR动态设置,而不是固定天数。
可用机器学习判断哪些双阴影形态更可靠。
双阴影反转策略利用经典的形态交易理念,思路简单直观,既适合新手学习,也可作为机器人的模块之一。但仍需要注意风险控制,可通过优化进场timing和止盈方式来改进。整体来说,该策略优点和缺点都较为明显,可供参考借鉴。
/*backtest
start: 2023-10-30 00:00:00
end: 2023-11-06 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("No Shadow Candles", overlay=true)
//set inputs
bars_until_close_trade = input(1,"Bars Until Close", minval = 1)
backtest_option = input(true,"Backtest on Twice alert?", bool)
//set conditions
up = close > close[1] and low >= open and high <= close
down = close < close[1] and low >= close and high <= open
up2 = (close > close[1] and low >= open and high <= close) and (close[1] > close[2] and low[1] >= open[1] and high[1] <= close[1])
down2 = (close < close[1] and low >= close and high <= open) and (close[1] < close[2] and low[1] >= close[1] and high[1] <= open[1])
close_trade = barssince(up or down) == bars_until_close_trade
close_trade2 = barssince(up2 or down2) == bars_until_close_trade
//plot indicators
plotshape(up,"Up Marker", shape.triangleup, location.belowbar, color = olive, size = size.tiny, transp = 50)
plotshape(down,"Down Marker", shape.triangledown, location.abovebar, color = orange, size = size.tiny, transp = 50)
plotshape(up2,"Up Twice Marker", shape.triangleup, location.belowbar, color = white, size = size.small)
plotshape(down2,"Down Twice Marker", shape.triangledown, location.abovebar, color = white, size = size.small)
plotshape(close_trade,"Close Trigger", shape.circle, location.belowbar, color = fuchsia, size = size.tiny, transp = 50)
plotshape(close_trade2,"Close Trigger2 (After Twice Alert)", shape.circle, location.belowbar, color = red, size = size.small)
//Strategy Testing
// Component Code Start
// Example usage:
// if testPeriod()
// strategy.entry("LE", strategy.long)
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2019, "Backtest Stop Year")
testStopMonth = input(7, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() => true
// Component Code Stop
//Entry and Close settings
if testPeriod() and backtest_option == true
strategy.entry("up2", true, when = up2, limit = close)
strategy.close("up2", when = close_trade)
if testPeriod() and backtest_option == false
strategy.entry("up", true, when = up, limit = close)
strategy.close("up", when = close_trade)