本策略运用动量指标和均线的组合,识别市场趋势和回转点,在趋势发生转折的时候进行交易,属于趋势跟踪和逆势交易策略。主要由供需区、EMA均线、各类HH、LL、LH、HL多空区域标记、ATR止损等模块组成。
根据K线高低点范围区分供需关系,红色区域为供过于求的供给区,绿色区域为求大于供的需求区。
计算长度为200的EMA均线并绘制,通过价格与EMA的大小关系判断多空趋势,价格高于EMA视为上升趋势,价格低于EMA视为下降趋势。
根据最近2根K线高低点情况判断回转区域:
- HH区( Higher High区域) — 连续2根K线高点创新高
- LL区( Lower Low区域) — 连续2根K线低点创新低
- LH区(Lower High区域) — 最近1根K线高点创新高,次根K线高点反转,属回落高点
- HL区(Higher Low区域) — 最近1根K线低点创新低,次根K线低点反转,属回升低点
计算14周期的ATR值,乘以系数2成为本策略的止损位。
监测价格与前一日Kline的高低点关系。当价格高于前一日的高点则产生多头信号;当价格低于前一日的低点则产生空头信号。入场信号延迟到第3根K线确认,避免冲击波动带来的错误信号。采用ATR 止损追踪方式,价格回撤超过止损线则主动止损退出当前信号。
风险解决方法: 1. 结合重大经济数据与政策判断来决定操作。 2. 可适当扩大ATR 止损的系数,确保有足够空间。 3. 调整ATR 止损的周期参数,避免在震荡中过于敏感。
本策略综合运用供需分析、趋势判断、回转识别和止损管理模块,能有效识别市场在关键区域转折的机会,是一套行之有效的趋势跟踪与逆势交易策略。同时也需要不断测试与优化,辅以人工经验判断,方能取得长期稳定收益。
/*backtest start: 2023-12-01 00:00:00 end: 2023-12-20 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Supply and Demand Zones with EMA and Trailing Stop", shorttitle="SD Zones", overlay=true) showBuySignals = input(true, title="Show Buy Signals", group="Signals") showSellSignals = input(true, title="Show Sell Signals", group="Signals") showHLZone = input(true, title="Show HL Zone", group="Zones") showLHZone = input(true, title="Show LH Zone", group="Zones") showHHZone = input(true, title="Show HH Zone", group="Zones") showLLZone = input(true, title="Show LL Zone", group="Zones") emaLength = input(200, title="EMA Length", group="EMA Settings") atrLength = input(14, title="ATR Length", group="Trailing Stop") atrMultiplier = input(2, title="ATR Multiplier", group="Trailing Stop") // Function to identify supply and demand zones getZones(src, len, mult) => base = request.security(syminfo.tickerid, "D", close) upper = request.security(syminfo.tickerid, "D", high) lower = request.security(syminfo.tickerid, "D", low) multiplier = request.security(syminfo.tickerid, "D", mult) zonetype = base + multiplier * len zone = src >= zonetype [zone, upper, lower] // Identify supply and demand zones [supplyZone, _, _] = getZones(close, high[1] - low[1], 1) [demandZone, _, _] = getZones(close, high[1] - low[1], -1) // Plot supply and demand zones bgcolor(supplyZone ? color.new(color.red, 80) : na) bgcolor(demandZone ? color.new(color.green, 80) : na) // EMA with Linear Weighted method ema = ta.ema(close, emaLength) // Color code EMA based on its relation to candles emaColor = close > ema ? color.new(color.green, 0) : close < ema ? color.new(color.red, 0) : color.new(color.yellow, 0) // Plot EMA plot(ema, color=emaColor, title="EMA") // Entry Signal Conditions after the third candle longCondition = ta.crossover(close, high[1]) and (bar_index >= 2) shortCondition = ta.crossunder(close, low[1]) and (bar_index >= 2) // Trailing Stop using ATR atrValue = ta.atr(atrLength) trailStop = close - atrMultiplier * atrValue // Strategy Entry and Exit if (longCondition) strategy.entry("Buy", strategy.long) strategy.exit("TrailStop", from_entry="Buy", loss=trailStop) if (shortCondition) strategy.entry("Sell", strategy.short) strategy.exit("TrailStop", from_entry="Sell", loss=trailStop) // Plot Entry Signals plotshape(series=showBuySignals ? longCondition : na, title="Buy Signal", color=color.new(color.green, 0), style=shape.triangleup, location=location.belowbar) plotshape(series=showSellSignals ? shortCondition : na, title="Sell Signal", color=color.new(color.red, 0), style=shape.triangledown, location=location.abovebar) // Plot Trailing Stop plot(trailStop, color=color.new(color.red, 0), title="Trailing Stop") // Plot HH, LL, LH, and HL zones plotshape(series=showHHZone and ta.highest(high, 2)[1] and ta.highest(high, 2)[2] ? 1 : na, title="HH Zone", color=color.new(color.blue, 80), style=shape.triangleup, location=location.abovebar) plotshape(series=showLLZone and ta.lowest(low, 2)[1] and ta.lowest(low, 2)[2] ? 1 : na, title="LL Zone", color=color.new(color.blue, 80), style=shape.triangledown, location=location.belowbar) plotshape(series=showLHZone and ta.highest(high, 2)[1] and ta.lowest(low, 2)[2] ? 1 : na, title="LH Zone", color=color.new(color.orange, 80), style=shape.triangleup, location=location.abovebar) plotshape(series=showHLZone and ta.lowest(low, 2)[1] and ta.highest(high, 2)[2] ? 1 : na, title="HL Zone", color=color.new(color.orange, 80), style=shape.triangledown, location=location.belowbar)