该策略是一个基于双均线交叉的趋势跟踪系统,通过短期和长期移动平均线的交叉来捕捉市场趋势,并采用1:3的风险收益比来管理交易风险。策略使用固定的止损和获利目标,同时结合了移动止损机制来保护盈利。
策略使用74周期的短期移动平均线(Short SMA)和70周期的长期移动平均线(Long SMA)作为主要指标。当短期均线向上穿越长期均线时,系统产生做多信号;当短期均线向下穿越长期均线时,系统产生做空信号。每次交易的仓位大小固定为0.002,止损设置为353美元,获利目标为止损的3倍(1059美元)。策略还包含了日期范围限制,只在指定的回测期间(2025年2月13日至2025年3月31日)内执行交易。
这是一个结构完整、逻辑清晰的趋势跟踪策略。通过均线交叉捕捉趋势,采用严格的风险管理和仓位控制,适合中长期交易。虽然存在均线滞后等固有缺陷,但通过建议的优化方向,特别是引入动态参数调整和市场环境过滤,策略的稳定性和盈利能力有望得到进一步提升。
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-17 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Bitcoin Strategy by Jag", overlay=true)
// Input Parameters
shortSMALength = input.int(74, title="Short SMA Length")
longSMALength = input.int(70, title="Long SMA Length")
trailStopOffset = input.float(353, title="Trailing Stop Offset (USD)") // Trailing Stop Loss Offset in USD
tradeSize = input.float(1, title="Trade Size")
// Automatically set Take Profit as 3 times Stop Loss
fixedTakeProfit = trailStopOffset * 3
// Backtesting Date Range
startDate = timestamp(2025, 02,13, 0, 0)
endDate = timestamp(2025, 03, 31, 23, 59)
withinDateRange = true
// Indicators
shortSMA = ta.sma(close, shortSMALength)
longSMA = ta.sma(close, longSMALength)
// Crossover Conditions
longCondition = withinDateRange and ta.crossover(shortSMA, longSMA)
shortCondition = withinDateRange and ta.crossunder(shortSMA, longSMA)
// Entry Logic
if (strategy.position_size == 0) // Only allow new trades if no position is open
if (longCondition)
strategy.entry("Long", strategy.long, tradeSize)
if (shortCondition)
strategy.entry("Short", strategy.short, tradeSize)
// Exit Logic for Long Position
if (strategy.position_size > 0)
strategy.exit("Long exit", "Long", stop=strategy.position_avg_price - trailStopOffset, limit=strategy.position_avg_price + fixedTakeProfit) // Using stop and limit
// Exit Logic for Short Position
if (strategy.position_size < 0)
strategy.exit("Short Exit", "Short", stop=strategy.position_avg_price + trailStopOffset, limit=strategy.position_avg_price - fixedTakeProfit) // Using stop and limit
// Plot Moving Averages
plot(shortSMA, color=color.blue, title="Short SMA")
plot(longSMA, color=color.black, title="Long SMA")
// Visual Signals
plotshape(series=longCondition and strategy.position_size == 0, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=shortCondition and strategy.position_size == 0, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)