该策略是一个基于双均线交叉信号的量化交易系统,通过短期和长期移动平均线的交叉来识别市场趋势变化,并结合动态止盈止损管理来控制风险。策略采用市价单进行交易,在信号触发时自动平仓现有仓位并开立新仓位,通过设定止盈止损点位来保护资金安全。
策略使用两条不同周期的简单移动平均线(SMA)作为交易信号的主要依据。当短期均线上穿长期均线时,系统产生做多信号;当短期均线下穿长期均线时,系统产生做空信号。系统会在信号产生时先检查当前持仓状态,如有反向持仓则先平仓,然后按照信号方向开立新仓位。每笔交易都会根据预设的百分比自动设置止盈止损点位,实现风险收益比的动态管理。
这是一个结构完整、逻辑清晰的量化交易策略。通过双均线交叉捕捉趋势变化,配合动态止盈止损管理风险。策略的优势在于系统化程度高、风险可控,但在实盘中仍需注意应对各类市场风险。通过持续优化和完善,策略有望在不同市场环境下保持稳定表现。建议在实盘之前进行充分的回测验证,并根据实际情况调整参数设置。
/*backtest start: 2024-10-01 00:00:00 end: 2024-10-31 23:59:59 period: 1h basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("BTCUSD Daily Strategy - Market Orders Only", overlay=true, initial_capital=10000, currency=currency.USD) // Configurable Inputs stop_loss_percent = input.float(title="Stop Loss (%)", defval=1.0, minval=0.0, step=0.1) take_profit_percent = input.float(title="Take Profit (%)", defval=2.0, minval=0.0, step=0.1) short_ma_length = input.int(title="Short MA Length", defval=9, minval=1) long_ma_length = input.int(title="Long MA Length", defval=21, minval=1) // Moving Averages short_ma = ta.sma(close, short_ma_length) long_ma = ta.sma(close, long_ma_length) // Plotting Moving Averages plot(short_ma, color=color.blue, title="Short MA") plot(long_ma, color=color.red, title="Long MA") // Buy and Sell Signals buy_signal = ta.crossover(short_ma, long_ma) sell_signal = ta.crossunder(short_ma, long_ma) // Market Buy Logic if (buy_signal and strategy.position_size <= 0) // Close any existing short position if (strategy.position_size < 0) strategy.close(id="Market Sell") // Calculate Stop Loss and Take Profit Prices entry_price = close long_stop = entry_price * (1 - stop_loss_percent / 100) long_take_profit = entry_price * (1 + take_profit_percent / 100) // Enter Long Position strategy.entry(id="Market Buy", direction=strategy.long) strategy.exit(id="Exit Long", from_entry="Market Buy", stop=long_stop, limit=long_take_profit) // Alert for Market Buy alert("Market Buy Signal at price " + str.tostring(close) + ". Stop Loss: " + str.tostring(long_stop) + ", Take Profit: " + str.tostring(long_take_profit), alert.freq_once_per_bar_close) // Market Sell Logic if (sell_signal and strategy.position_size >= 0) // Close any existing long position if (strategy.position_size > 0) strategy.close(id="Market Buy") // Calculate Stop Loss and Take Profit Prices entry_price = close short_stop = entry_price * (1 + stop_loss_percent / 100) short_take_profit = entry_price * (1 - take_profit_percent / 100) // Enter Short Position strategy.entry(id="Market Sell", direction=strategy.short) strategy.exit(id="Exit Short", from_entry="Market Sell", stop=short_stop, limit=short_take_profit) // Alert for Market Sell alert("Market Sell Signal at price " + str.tostring(close) + ". Stop Loss: " + str.tostring(short_stop) + ", Take Profit: " + str.tostring(short_take_profit), alert.freq_once_per_bar_close)