该策略结合相对成交量指标和价格行情判断的趋势指标,实现了一个融合趋势跟踪和突破的自动化交易系统。当成交量增加且波动较小时买入,根据止损点和价格行情判断止盈或止损。
使用 Bollinger Bands 判断价格是否波动较小。具体实现是比较ATR和BOLL通道带宽。
计算过去N天的平均成交量,和当前Volume比较判断成交量是否增加。
当价格低位运行,成交量增加,波动较小时买入。
设置止损点,跟踪最低价更新。
当价格向下突破止损点时止损。
当价格形成多头吞噬模式时止盈。
结合成交量和波动性指标,可以有效过滤假突破。
采用趋势跟踪止损方法,可以最大限度锁定利润。
利用多头吞噬等形态判断作为止盈信号,可以在趋势反转前夕及时止盈。
策略较为直观简单,容易理解和跟踪。
止损和止盈规则比较明确,降低了闭市antisipate带来的不确定性。
成交量指标存在滞后,可能错过最佳入场点。
多头吞噬等形态判断作为止盈信号可能不足够可靠,存在过早止盈的风险。
止损点靠后的策略,存在单笔损失可能较大的风险。
需要合理参数调整,如ATR和成交量周期等,否则可能出现频繁交易。
需要关注和优化止盈止损规则,降低不必要平仓的可能。
尝试结合其他指标过滤入场信号,如MACD等。
优化ATR和成交量周期参数,降低频繁交易风险。
尝试其他止盈信号,如价格突破下轨等Exit机制。
研究通过动态调整止损位来锁定更多利润的可能性。
测试不同持仓时间对绩效的影响,寻找最优持仓周期。
回测不同品种合约效果,找到最佳适用品种。
该策略整体较为简单直观,通过结合成交量指标和价格行情判断,实现了趋势跟踪型策略。优点是信号生成较为清晰,跟踪容易,降低反向操作风险。但仍需优化过滤信号的质量和止盈止损规则,使策略更稳定可靠。通过继续改进参数设定、进场退出机制等,有望产生更加优异的绩效表现。
/*backtest
start: 2022-10-10 00:00:00
end: 2023-10-16 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/
// © DojiEmoji (kevinhhl)
//@version=4
strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)
ENUM_LONG = "Long"
VERBOSE_MODE = false
opened_position = false
// Timeframe {
backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)
USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")
backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)
within_timeframe = true
// }
// Volatility Indicators {
// BOLL:
BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)
BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2
plot(SMA20, "Basis", color=#872323, offset = 0)
BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)
BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)
//fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)
// ATR v. sDev of prices
ATR_x2 = atr(input(10,title="Length of ATR [Trailing Stop Loss] (x2)"))*2
//plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)
//plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)
//plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)
is_low_volat = ATR_x2 > BOLL_sDEV_x2
// }
// Trailing stop loss {
TSL_source = low
var entry_price = float(0), var stop_loss_price = float(0)
TSL_line_color = color.green
if strategy.position_size == 0 or not within_timeframe
TSL_line_color := color.black
stop_loss_price := TSL_source - ATR_x2
else if strategy.position_size > 0
stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)
plot(stop_loss_price, color=TSL_line_color)
// }
// Relative volume indicator {
LEN_RELATIVE_VOL = input(5, title="SMA(volume) length (for relative comparison)")
relative_vol = sma(volume,LEN_RELATIVE_VOL)
// }
// price actions {
bar_range_ratio = abs(close-open)/(high-low)
engulfing = low < low[1] and high > high[1] and abs(close-open) > abs(close-open)[1]
// }
// MAIN:
if within_timeframe
entry_msg = "", exit_msg = close <= entry_price ? "stop loss" : "take profit"
// ENTRY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if close > open and volume > relative_vol and is_low_volat
if strategy.position_size > 0
entry_msg := "adding"
else if strategy.position_size == 0
entry_msg := "initial"
if strategy.position_size == 0
entry_price := close
stop_loss_price := TSL_source - ATR_x2
ATR_x2 := ATR_x2
strategy.entry(ENUM_LONG, strategy.long, comment=entry_msg)
// EXIT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if strategy.position_size > 0
bExit = false
// EXIT: Case (A) touches trailing stop loss
if TSL_source <= stop_loss_price
exit_msg := exit_msg + "[TSL]"
bExit := true
// EXIT: Case (B)
else if close < open and not is_low_volat and engulfing and (high-low) > ATR_x2
exit_msg := VERBOSE_MODE ? exit_msg + "[engulfing bearish]" : exit_msg
bExit := true
strategy.close(ENUM_LONG, when=bExit, comment=exit_msg)
// CLEAN UP:
if strategy.position_size == 0
entry_price := 0
stop_loss_price := float(0)