本策略融合了多时间框架EMA指标与K线形态判断,实现了较为灵敏的长线信号捕捉与止损退出。
本策略主要基于以下几个指标进行判断:
EMA均线:采用13周期、21周期2组EMA,判断价格突破形成交易信号。
K线形态:判断K线实体方向,与EMA指标联合使用,过滤假突破。
支持阻力:采用近期10周期 highest高点构建,判断突破通过该区域增强信号可靠性。
上升分时:120周期close收盘价在open开盘价之上判断为上升分时,作为辅助判断。
交易信号生成规则为:
多头信号:快速EMA向上突破慢速EMA,并且为阳线K线,关闭空仓开多。
空头信号:快速EMA向下跌破慢速EMA,并且为阴线K线,平掉多仓。
止损退出:反手信号发出时止损退出当前头寸。
以上风险可以通过避免过度优化,审慎选择参数,严格把控仓位规模等方法加以缓解。
本策略整合多时间框架EMA指标与K线实体判断,实现了较为可靠的趋势判断。同时结合支持阻力与分时情况进行辅助,确保信号质量。通过反手信号机制止损,可以有效控制单笔止损。未来可通过引入机器学习模型、自适应止损、情绪面分析和仓位管理模块等进行优化,使策略更为稳健。
/*backtest start: 2023-02-14 00:00:00 end: 2024-02-20 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy(title='ck - CryptoSniper Longs Only (Strategy)', shorttitle='ck - CryptoSniper Longs (S) v1', overlay=true, precision=2, commission_value=0.25, default_qty_type=strategy.percent_of_equity, pyramiding=0, default_qty_value=100, initial_capital=100) open_long = 0 close_position = 0 last_long=close last_short=close //Candle body resistance Channel-----------------------------// len = 34 src = input(close, title="Candle body resistance Channel") out = sma(src, len) last8h = highest(close, 13) lastl8 = lowest(close, 13) bearish = cross(close,out) == 1 and falling(close, 1) bullish = cross(close,out) == 1 and rising(close, 1) channel2=false //-----------------Support and Resistance RST = input(title='Support / Resistance length:', defval=10) RSTT = valuewhen(high >= highest(high, RST), high, 0) RSTB = valuewhen(low <= lowest(low, RST), low, 0) //--------------------Trend colour ema------------------------------------------------// src0 = close, len0 = input(13, minval=1, title="EMA 1") ema0 = ema(src0, len0) direction = rising(ema0, 2) ? +1 : falling(ema0, 2) ? -1 : 0 //-------------------- ema 2------------------------------------------------// src02 = close, len02 = input(21, minval=1, title="EMA 2") ema02 = ema(src02, len02) direction2 = rising(ema02, 2) ? +1 : falling(ema02, 2) ? -1 : 0 //=============Hull MA// show_hma = false hma_src = input(close, title="HullMA Source:") hma_base_length = input(8, minval=1, title="HullMA Base Length:") hma_length_scalar = input(5, minval=0, title="HullMA Length Scalar:") hullma(src, length)=>wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length))) //============ signal Generator ==================================// Period=input(title='Period', defval='120') ch1 = request.security(syminfo.tickerid, Period, open) ch2 = request.security(syminfo.tickerid, Period, close) // Signals// long = crossover(request.security(syminfo.tickerid, Period, close),request.security(syminfo.tickerid, Period, open)) short = crossunder(request.security(syminfo.tickerid, Period, close),request.security(syminfo.tickerid, Period, open)) last_long := long ? time : nz(last_long[1]) last_short := short ? time : nz(last_short[1]) long_signal = crossover(last_long, last_short) ? 1 : -1 short_signal = crossover(last_short, last_long) ? -1 : 1 if (long_signal == 1) strategy.entry("Long Open", strategy.long) if (short_signal == -1) strategy.close("Long Open") if (long_signal[1] == 1 and short_signal[1] == 1) open_long := 1 close_position := 0 if (short_signal[1] == -1 and long_signal[1] == -1) open_long := 0 close_position := 1 plotshape(open_long == 1, title="Open Long", location=location.belowbar, style=shape.triangleup, size=size.small, color=green, transp=10) plotshape(close_position == 1, title="Close Long", location=location.abovebar, style=shape.triangledown, size=size.small, color=red, transp=10) //plot(0, title="Trigger", color=white) ///////////////////////////////////////////////////////////////////////////////////////////