该策略是一个基于多周期均线的趋势跟踪交易系统。策略利用89周期和21周期简单移动平均线(SMA)确定市场总体趋势方向,同时结合5周期指数移动平均线(EMA)的高点和低点来寻找具体的交易信号。策略采用双重仓位管理方式,并结合固定止损和追踪止盈来控制风险。
策略的核心逻辑包含以下几个关键要素: 1. 趋势判断:使用89周期和21周期SMA的相对位置以及价格位置来确定趋势。当价格和5周期EMA都位于21周期SMA之上,且21周期SMA位于89周期SMA之上时,判定为上升趋势;反之则为下降趋势。 2. 入场信号:在上升趋势中,当价格回调至5周期EMA低点时入场做多;在下降趋势中,当价格反弹至5周期EMA高点时入场做空。 3. 仓位管理:每次信号触发时开立两个相同数量的合约仓位。 4. 风险控制:对第一个仓位采用固定止损和获利目标,对第二个仓位采用追踪止损方式管理。
该策略是一个结构完整的趋势跟踪系统,通过多周期均线组合捕捉市场趋势,并采用灵活的仓位管理和止盈止损方式控制风险。虽然存在一定的优化空间,但策略的基本框架具有较好的实用性和可扩展性。针对不同的交易品种和市场环境,可以通过调整参数和增加过滤条件来提升策略的稳定性。
/*backtest
start: 2024-11-12 00:00:00
end: 2024-12-11 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tobiashartemink2
//@version=5
strategy("High 5 Trading Technique", overlay=true)
// --- Input parameters ---
sma89Length = input.int(title="SMA 89 Length", defval=89)
sma21Length = input.int(title="SMA 21 Length", defval=21)
ema5HighLength = input.int(title="EMA 5 High Length", defval=5)
ema5LowLength = input.int(title="EMA 5 Low Length", defval=5)
contracts = input.int(title="Aantal Contracten", defval=1)
stopLossPoints = input.int(title="Stop Loss Points per Contract", defval=25)
takeProfitPoints = input.int(title="Take Profit Points per Contract", defval=25)
// --- Calculate moving averages ---
sma89 = ta.sma(close, sma89Length)
sma21 = ta.sma(close, sma21Length)
ema5High = ta.ema(high, ema5HighLength)
ema5Low = ta.ema(low, ema5LowLength)
// --- Identify trend and order of moving averages ---
longSetup = close > sma89 and close > sma21 and ema5High > sma21 and sma21 > sma89
shortSetup = close < sma89 and close < sma21 and ema5Low < sma21 and sma21 < sma89
// --- Entry signals ---
longTrigger = longSetup and close <= ema5Low
shortTrigger = shortSetup and close >= ema5High
// --- Entry orders ---
if (longTrigger)
strategy.entry("Long 1", strategy.long, qty=contracts)
strategy.entry("Long 2", strategy.long, qty=contracts)
if (shortTrigger)
strategy.entry("Short 1", strategy.short, qty=contracts)
strategy.entry("Short 2", strategy.short, qty=contracts)
// --- Stop-loss and take-profit for long positions ---
if (strategy.position_size > 0)
strategy.exit("Exit Long 1", "Long 1", stop=strategy.position_avg_price - stopLossPoints, limit=strategy.position_avg_price + takeProfitPoints)
strategy.exit("Exit Long 2", "Long 2", stop=strategy.position_avg_price - stopLossPoints, trail_offset=takeProfitPoints, trail_points=takeProfitPoints)
// --- Stop-loss and take-profit for short positions ---
if (strategy.position_size < 0)
strategy.exit("Exit Short 1", "Short 1", stop=strategy.position_avg_price + stopLossPoints, limit=strategy.position_avg_price - takeProfitPoints)
strategy.exit("Exit Short 2", "Short 2", stop=strategy.position_avg_price + stopLossPoints, trail_offset=takeProfitPoints, trail_points=takeProfitPoints)
// --- Plot moving averages ---
plot(sma89, color=color.blue, linewidth=2)
plot(sma21, color=color.red, linewidth=2)
plot(ema5High, color=color.green, linewidth=2)
plot(ema5Low, color=color.orange, linewidth=2)