该策略是一个基于SuperTrend指标的自动化交易系统,通过分析价格与SuperTrend线的交叉来生成交易信号。策略采用固定的ATR周期和乘数参数,结合价格穿越SuperTrend线的方向来确定市场趋势,实现趋势跟踪和资金管理的有机结合。
策略的核心是利用SuperTrend指标,该指标基于ATR(Average True Range)波动率指标构建。具体实现包括: 1. 设定ATR周期为10,乘数为2.0,用于计算SuperTrend线 2. 当收盘价向上穿越SuperTrend线时,触发做多信号 3. 当收盘价向下穿越SuperTrend线时,触发做空信号 4. 持仓期间通过SuperTrend线作为移动止损,实现动态风险控制
这是一个结构清晰、逻辑严密的趋势跟踪策略。通过SuperTrend指标的动态特性,实现了趋势捕捉和风险控制的统一。策略具有较强的实用性和扩展性,通过合理的参数设置和优化方向的实施,有望在实盘交易中取得稳定表现。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-09 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Commodity KIng", overlay=true)
// Supertrend Parameters
atr_period = 10 // Fixed ATR Period
atr_multiplier = 2.0 // Fixed ATR Multiplier
// Calculate Supertrend
[supertrend, direction] = ta.supertrend(atr_multiplier, atr_period)
// Plot Supertrend with reversed colors
plot(supertrend, color=direction > 0 ? color.red : color.green, title="Supertrend", linewidth=2)
// Buy and Sell Conditions
longCondition = ta.crossover(close, supertrend) // Buy when price crosses above Supertrend
shortCondition = ta.crossunder(close, supertrend) // Sell when price crosses below Supertrend
// Execute Buy and Sell Orders
if (longCondition)
strategy.entry("Buy", strategy.long)
if (shortCondition)
strategy.entry("Sell", strategy.short)
// Exit Conditions
if (shortCondition)
strategy.close("Buy") // Close long position if price crosses below Supertrend
if (longCondition)
strategy.close("Sell") // Close short position if price crosses above Supertrend
// Alerts
if (longCondition)
alert("Buy Signal: " + str.tostring(close), alert.freq_once_per_bar)
if (shortCondition)
alert("Sell Signal: " + str.tostring(close), alert.freq_once_per_bar)