
This strategy is a trend following system based on multiple Simple Moving Averages (SMA) combined with precise tick cross detection technology. It determines market trends through the hierarchical relationship of 20, 50, 100, and 200-period moving averages, and triggers trading signals using real-time price crosses with moving averages. The strategy is designed to be universally applicable across different time zones and trading sessions, capable of running on charts of various timeframes.
The strategy employs a three-layer trend filtering mechanism, requiring the 50-period moving average to be above the 100-period moving average, which in turn must be above the 200-period moving average to confirm an uptrend, and vice versa for a downtrend. Entry signals are based on price crosses with the 50-period moving average, using tick data for precise cross detection by comparing current price action with the previous bar’s position. Exit signals are determined by the relationship between price and the 20-period moving average, triggering position closure when price breaks through the 20-period moving average.
This is a well-structured trend following strategy with clear logic that ensures signal reliability and effective trend tracking through the coordinated use of multiple moving averages. The strategy’s design considers practicality and universality, making it suitable for use in different market environments. Through further optimization and refinement, this strategy has the potential to achieve better performance in actual trading.
/*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)