双轨道布林带动量交易策略


创建日期: 2023-11-16 17:36:00 最后修改: 2023-11-16 17:36:00
复制: 0 点击次数: 722
avatar of ChaoZhang ChaoZhang
1
关注
1617
关注者

双轨道布林带动量交易策略

概述

本策略基于布林带的概念,设置价格通道的上下轨,并以此进行趋势判断和交易信号产生。具体来说,是计算价格的平均绝对偏差作为通道带宽,通道中轨为价格的简单移动平均,上轨和下轨分别为中轨加减1倍或2倍的通道带宽。当价格突破上轨时做多,突破下轨时做空。

原理

该策略主要包含以下几个要点:

  1. 计算价格的中轨线,即价格的简单移动平均线。

  2. 计算价格绝对偏差的简单移动平均作为通道带宽。

  3. 根据中轨和带宽确定上下轨。上轨为中轨加1或2倍带宽,下轨为中轨减1或2倍带宽。

  4. 计算多空趋势判断指标。当价格高于上轨2时为多头,当价格低于下轨2时为空头。

  5. 产生交易信号。价格上穿上轨2时做多,下穿下轨2时做空。

  6. 设置止损线。多单止损线为下轨1,空单止损线为上轨1。

  7. 按照资金管理要求计算仓位。

该策略融合了移动平均线判断趋势、布林带判断超买超卖、突破做反转的思想。通过双轨差异判断趋势强弱,同时发挥布林带回归中轴的功能,整体形成一个较为稳定的交易系统。

优势分析

该策略主要具有以下优势:

  1. 使用双轨系统,可以较好地判断趋势的强弱。

  2. 布林带有较强的回归功能,可以有效避免假突破。

  3. 双轨差异配合布林带回归中轴,形成较稳定的交易信号。

  4. 有清晰的止损 Exit 逻辑,可以控制风险。

  5. 仓位设置符合资金管理要求,避免超级杠杆。

  6. 策略思路清晰,易于理解和优化。

  7. 可灵活设置参数,适合不同市场的优化。

风险分析

该策略也存在一些风险:

  1. 布林带参数设置不当可能导致护城河效应,无法有效跟踪价格。

  2. 双轨差异并不能完全避免趋势误判的情况。

  3. 在震荡市场中,可能产生较多无效信号。

  4. 假突破情况下会产生损失。

  5. 存在一定的时间滞后,可能错过周期转换点。

  6. 盈亏比受止损点限制,无法无限追踪趋势。

对应风险管理措施:

  1. 优化参数,使布林带能够适应不同周期。

  2. 组合其他指标进行確認,避免误判。

  3. 降低仓位,控制单笔损失。

  4. 优化止损点,保证盈亏比。

  5. 适当缩短周期,减少滞后。

  6. 风控要稳健,不能无限追涨杀跌。

优化方向

该策略可以从以下几个方向进行优化:

  1. 优化布林带参数,使其能更好跟踪价格。可以引入自适应参数。

  2. 尝试不同的移动平均线,如EMA、DWMA等。

  3. 增加趋势过滤,避免震荡市错交易。可以考虑MACD等。

  4. 增加激进出场 Exit,以获取更多趋势利润。可以考虑小止损、移动止损、离场指标等。

  5. 引入多个时间周期进行组合,不同周期适合不同市场情况。

  6. 增加附加条件逻辑,如交易量突增等,避免假突破。

  7. 可以考虑反向布林带,卖出上轨,买入下轨。

  8. 进行参数优化测试,寻找最优参数组合。

总结

本策略整体思路清晰,具有较强的稳定性。同时也存在一定改进空间,通过参数优化、逻辑优化、风险管理等方面进一步完善,可以成为一个非常实用的量化交易策略。本策略为量化交易的入门策略提供了一个很好的思路参考。

策略源码
/*backtest
start: 2022-11-09 00:00:00
end: 2023-11-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noro

//@version=4
strategy(title = "Noro's Bands Strategy", shorttitle = "Bands", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, commission_value = 0.1)

//Sattings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
lotsize = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
len = input(20, defval = 20, minval = 1, maxval = 1000, title = "Length")
src = input(ohlc4, title = "Source")
showbb = input(true, title = "Show Bands")
showof = input(true, title = "Show Offset")
showbg = input(false, title = "Show Background")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//PriceChannel
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2

//Distance
dist = abs(src - center)
distsma = sma(dist, len)
hd = center + distsma
ld = center - distsma
hd2 = center + distsma * 2
ld2 = center - distsma * 2

//Trend
trend = 0
trend := high > hd2 ? 1 : low < ld2 ? -1 : trend[1]
bgcol = showbg == false ? na : trend == 1 ? color.lime : color.red
bgcolor(bgcol, transp = 70)

//Lines
colo = showbb == false ? na : color.black
offset = showof ? 1 : 0
plot(hd2, color = colo, linewidth = 1, transp = 0, offset = offset, title = "High band 2")
plot(hd, color = colo, linewidth = 1, transp = 0, offset = offset, title = "High band 1")
plot(center, color = colo, linewidth = 1, transp = 0, offset = offset, title = "center")
plot(ld, color = colo, linewidth = 1, transp = 0, offset = offset, title = "Low band 1")
plot(ld2, color = colo, linewidth = 1, transp = 0, offset = offset, title = "Low band 2")

//Trading
size = strategy.position_size
needstop = needlong == false or needshort == false
truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
lot = 0.0
lot := size != size[1] ? strategy.equity / close * lotsize / 100 : lot[1]
if distsma > 0
    strategy.entry("Long", strategy.long, lot, stop = hd2, when = truetime and needlong)
    strategy.entry("Short", strategy.short, lot, stop = ld2, when = truetime and needshort)
sl = size > 0 ? ld2 : size < 0 ? hd2 : na
if size > 0 and needstop
    strategy.exit("Stop Long", "Long", stop = sl)
if size < 0 and needstop
    strategy.exit("Stop Short", "Short", stop = sl)
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    strategy.cancel("Long")
    strategy.cancel("Short")