该策略是一个适用于比特币和其他加密货币15分钟时间周期的综合交易策略。它整合多个指标生成买入卖出信号,包括三重指数移动平均线、平均真实波动幅度、以及平衡线蜡烛图形,同时具有止盈止损等风险管理机制。
该策略使用以下多个指标:
三重指数移动平均线(TEMA):使用不同长度和源的3个TEMA,分别基于高点、低点和收盘价计算。
平均真实波动幅度(ATR):使用EMA平滑的自定义ATR计算市场波动率。
超趋指标:基于ATR和倍数确定趋势方向。
简单移动平均线(SMA):对短周期TEMA进行SMA计算以平滑值。
平衡线收盘价:用于额外确认趋势。
当短周期TEMA高于两个长周期TEMA,超趋指标看涨,短周期TEMA高于其SMA,且平衡线收盘价高于前一日时,产生买入信号。
当短周期TEMA低于两个长周期TEMA,超趋指标看跌,短周期TEMA低于其SMA,且平衡线收盘价低于前一日时,产生卖出信号。
止盈止损分别设置为入场价格的1%和3%。同时考虑手续费因素。
结合趋势、波动率、形态等多个因子指标,可以提高判断准确性,避免假信号。
合理的止盈止损设置可以锁定利润,也可有效限制单笔损失。
指标参数可以灵活调整,适应市场的变化,寻找最佳组合。
加入手续费因子,可以使回测结果更接近实际交易表现。
过多指标组合也可能出现误判,需要仔细评估指标的实效性。
相比长周期,15分钟操作更受突发事件影响,存在更大的偶发风险。
该策略尚需在更长周期和多市场中进行验证,以确保稳定性。
多指标组合带来大量参数,优化所有参数组合需要较长时间。
回测检验各个指标的实际提升效果,避免使用冗余指标。
在更多市场中测试参数优化结果,确保稳定可靠。
如移动止损、挂单止损等方式进一步控制风险。
如滑点成本等使回测更实盘化。
该策略综合多个指标和风险控制机制,对比特币15分钟周期交易进行设计。其优化空间还很大,需要深入回测评估指标效果,广泛市场稳定性测试,以及加入更多实盘考虑因素,以求在多因子策略中找到最优参数组合。如果持续优化和验证,该策略可成为加密货币高频交易的有效工具。
/*backtest
start: 2023-08-25 00:00:00
end: 2023-09-09 00:00:00
period: 10m
basePeriod: 1m
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/
// © deperp
//@version=5
strategy('3kilos', shorttitle='3kilos BTC 15m', overlay=true, initial_capital=100000, max_bars_back=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.07, pyramiding=0)
short = input.int(50, minval=1)
srcShort = input(high, title='TEMA short')
long = input.int(100, minval=1)
srcLong = input(low, title='TEMA long 2')
long2 = input.int(350, minval=1)
srcLong2 = input(close, title='TEMA long 3')
atrLength = input.int(550, title='ATR Length', minval=1)
mult = input.float(3, title="Multiplier", minval=0.5, step=1)
smaPeriod = input.int(100, title="SMA Period", minval=1)
takeProfitPercent = input.float(1, title="Take Profit (%)", minval=0.1) / 100
stopLossPercent = input.float(3, title="Stop Loss (%)", minval=0.1) / 100
tema(src, length) =>
ema1 = ta.ema(src, length)
ema2 = ta.ema(ema1, length)
ema3 = ta.ema(ema2, length)
3 * (ema1 - ema2) + ema3
tema1 = tema(srcShort, short)
plot(tema1, color=color.new(color.red, 0), linewidth=2)
tema2 = tema(srcLong, long)
plot(tema2, color=color.new(color.blue, 0), linewidth=2)
tema3 = tema(srcLong2, long2)
plot(tema3, color=color.new(color.green, 0), linewidth=2)
// Custom ATR calculation with EMA smoothing
atr_ema(src, length) =>
trueRange = math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
emaTrueRange = ta.ema(trueRange, length)
emaTrueRange
// Calculate ATR with EMA smoothing
atr = atr_ema(close, atrLength)
// Calculate Supertrend
var float up = na
var float dn = na
var bool uptrend = na
up := na(up[1]) ? hl2 - (mult * atr) : uptrend[1] ? math.max(hl2 - (mult * atr), up[1]) : hl2 - (mult * atr)
dn := na(dn[1]) ? hl2 + (mult * atr) : uptrend[1] ? hl2 + (mult * atr) : math.min(hl2 + (mult * atr), dn[1])
uptrend := na(uptrend[1]) ? true : close[1] > dn[1] ? true : close[1] < up[1] ? false : uptrend[1]
// Calculate SMA
sma = ta.sma(tema1, smaPeriod)
// Heikin-Ashi Close
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, timeframe.period, close)
// Trend determination using Heikin-Ashi Close
longC = tema1 > tema2 and tema1 > tema3 and uptrend and tema1 > sma and haClose > haClose[1]
shortC = tema1 < tema2 and tema1 < tema3 and not uptrend and tema1 < sma and haClose < haClose[1]
alertlong = longC and not longC[1]
alertshort = shortC and not shortC[1]
useDateFilter = input.bool(true, title="Begin Backtest at Start Date",
group="Backtest Time Period")
backtestStartDate = input(timestamp("1 Jan 2023"),
title="Start Date", group="Backtest Time Period",
tooltip="This start date is in the time zone of the exchange " +
"where the chart's instrument trades. It doesn't use the time " +
"zone of the chart or of your computer.")
inTradeWindow = true
stopLossLevelLong = close - atr * mult
stopLossLevelShort = close + atr * mult
longTakeProfitLevel = close * (1 + takeProfitPercent)
longStopLossLevel = close * (1 - stopLossPercent)
shortTakeProfitLevel = close * (1 - takeProfitPercent)
shortStopLossLevel = close * (1 + stopLossPercent)
if inTradeWindow and longC
strategy.entry('Long', strategy.long, comment='Long')
strategy.exit("TP Long", "Long", limit=longTakeProfitLevel, stop=longStopLossLevel, comment="TP/SL Long")
if inTradeWindow and shortC
strategy.entry('Short', strategy.short, comment='Short')
strategy.exit("TP Short", "Short", limit=shortTakeProfitLevel, stop=shortStopLossLevel, comment="TP/SL Short")
// Alerts
alertcondition(longC, title='Long', message=' Buy Signal ')
alertcondition(shortC, title='Short', message=' Sell Signal ')