该策略是一个基于多层移动平均线(SMA)的趋势跟踪系统,结合了精确的分笔交叉检测技术。它通过20、50、100和200周期移动平均线的层级关系来确定市场趋势,并使用实时价格与移动平均线的交叉来触发交易信号。策略设计充分考虑了不同时区和交易时段的普适性,能够在各种时间周期的图表上运行。
策略采用三层趋势过滤机制,要求50周期均线位于100周期均线之上,且100周期均线位于200周期均线之上才确认上升趋势,反之则确认下降趋势。入场信号基于价格与50周期均线的交叉,使用分笔数据实现精确的交叉检测,通过比较当前价格行为与前一根K线的位置关系来确定交叉发生的时机。出场信号则由价格与20周期均线的关系决定,当价格突破20周期均线时触发平仓信号。
这是一个结构完整、逻辑清晰的趋势跟踪策略,通过多层移动平均线的配合使用,既保证了信号的可靠性,又实现了对趋势的有效跟踪。策略的设计充分考虑了实用性和普适性,适合在不同市场环境下使用。通过进一步优化和完善,该策略有望在实际交易中取得更好的表现。
/*backtest
start: 2024-02-22 00:00:00
end: 2024-06-25 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Multi-SMA Strategy - Core Signals", overlay=true)
// ———— Universal Inputs ———— //
int smaPeriod1 = input(20, "Fast SMA")
int smaPeriod2 = input(50, "Medium SMA")
bool useTickCross = input(true, "Use Tick-Precise Crosses")
// ———— Timezone-Neutral Calculations ———— //
sma20 = ta.sma(close, smaPeriod1)
sma50 = ta.sma(close, smaPeriod2)
sma100 = ta.sma(close, 100)
sma200 = ta.sma(close, 200)
// ———— Tick-Precise Cross Detection ———— //
golden_cross = useTickCross ?
(high >= sma50 and low[1] < sma50[1]) :
ta.crossover(sma20, sma50)
death_cross = useTickCross ?
(low <= sma50 and high[1] > sma50[1]) :
ta.crossunder(sma20, sma50)
// ———— Trend Filter ———— //
uptrend = sma50 > sma100 and sma100 > sma200
downtrend = sma50 < sma100 and sma100 < sma200
// ———— Entry Conditions ———— //
longCondition = golden_cross and uptrend
shortCondition = death_cross and downtrend
// ———— Exit Conditions ———— //
exitLong = ta.crossunder(low, sma20)
exitShort = ta.crossover(high, sma20)
// ———— Strategy Execution ———— //
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
strategy.close("Long", when=exitLong)
strategy.close("Short", when=exitShort)
// ———— Clean Visualization ———— //
plot(sma20, "20 SMA", color.new(color.blue, 0))
plot(sma50, "50 SMA", color.new(color.red, 0))
plot(sma100, "100 SMA", color.new(#B000B0, 0), linewidth=2)
plot(sma200, "200 SMA", color.new(color.green, 0), linewidth=2)
// ———— Signal Markers ———— //
plotshape(longCondition, "Long Entry", shape.triangleup, location.belowbar, color.green, 0)
plotshape(shortCondition, "Short Entry", shape.triangledown, location.abovebar, color.red, 0)
plotshape(exitLong, "Long Exit", shape.xcross, location.abovebar, color.blue, 0)
plotshape(exitShort, "Short Exit", shape.xcross, location.belowbar, color.orange, 0)