本策略是一个结合了趋势跟踪、动量指标和自适应止损的多维度交易系统。策略通过SuperTrend指标识别市场趋势方向,同时结合RSI动量指标和均线系统进行交易确认,并利用ATR波动率指标实现动态止损管理。这种多维度的分析方法能够有效地捕捉市场趋势,同时对风险进行合理控制。
策略的核心逻辑基于以下三个维度: 1. 趋势识别:使用SuperTrend指标(参数:ATR长度14,乘数3.0)作为主要趋势判断工具。当SuperTrend转为绿色时,表明市场可能处于上升趋势。 2. 动量确认:使用RSI指标(参数:长度14)避免在过度买入区域开仓。RSI低于65时认为市场未处于超买状态。 3. 趋势验证:使用50周期简单移动平均线(SMA)作为额外的趋势确认工具。价格需要位于均线之上才考虑开仓。
买入条件需同时满足:SuperTrend看涨(绿色)+RSI<65+价格在50周期均线之上。 卖出条件:当SuperTrend转为看跌时平仓。 止损管理:使用基于ATR的追踪止损,止损距离为ATR值的1.5倍。
该策略通过综合运用趋势跟踪、动量和均线系统,构建了一个逻辑完整的交易系统。策略的优势在于多维度的信号确认机制和完善的风险控制体系。通过提供的优化方向,策略还有进一步提升的空间。重点是要在保持策略核心逻辑的同时,增强其在不同市场环境下的适应性。
/*backtest
start: 2025-01-08 00:00:00
end: 2025-02-07 00:00:00
period: 3h
basePeriod: 3h
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/
// © Gladston_J_G
//@version=5
strategy("Trend Strategy with Stop Loss", overlay=true, margin_long=100, margin_short=100)
// ———— Inputs ———— //
atrLength = input(14, "ATR Length")
supertrendMultiplier = input(3.0, "Supertrend Multiplier")
rsiLength = input(14, "RSI Length")
maLength = input(50, "MA Length")
trailOffset = input(1.5, "Trailing Stop ATR Multiplier")
// ———— Indicators ———— //
// Supertrend for trend direction
[supertrend, direction] = ta.supertrend(supertrendMultiplier, atrLength)
// RSI for momentum filter
rsi = ta.rsi(close, rsiLength)
// Moving Average for trend confirmation
ma = ta.sma(close, maLength)
// ATR for volatility-based stop loss
atr = ta.atr(atrLength)
// ———— Strategy Logic ———— //
// Buy Signal: Supertrend bullish + RSI not overbought + Price above MA
buyCondition = direction < 0 and rsi < 65 and close > ma
// Sell Signal: Supertrend turns bearish
sellCondition = direction > 0
// ———— Stop Loss & Trailing ———— //
stopPrice = close - (atr * trailOffset)
var float trail = na
if buyCondition and strategy.position_size == 0
trail := stopPrice
else
trail := math.max(stopPrice, nz(trail[1]))
// ———— Execute Orders ———— //
strategy.entry("Long", strategy.long, when=buyCondition)
strategy.close("Long", when=sellCondition)
strategy.exit("Trail Exit", "Long", stop=trail)
// ———— Visuals ———— //
plot(supertrend, "Supertrend", color=direction < 0 ? color.green : color.red)
plot(ma, "MA", color=color.blue)
plot(strategy.position_size > 0 ? trail : na, "Trailing Stop", color=color.orange, style=plot.style_linebr)
// ———— Alerts ———— //
plotshape(buyCondition, "Buy", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(sellCondition, "Sell", shape.triangledown, location.abovebar, color.red, size=size.small)
plot(close)