
This strategy is a trend following system based on multiple Exponential Moving Average (EMA) crossover signals. By combining EMAs of 20, 50, and 150 periods, it creates a comprehensive framework for trend identification and trade execution. The strategy utilizes crossover relationships between different period EMAs to determine market trend changes and specific trading opportunities.
The strategy employs three EMAs of different periods: EMA20 for short-term trend, EMA50 for medium-term trend, and EMA150 for long-term trend. A golden cross forms when EMA50 crosses above EMA150, indicating a long-term uptrend formation; a death cross forms when EMA50 crosses below EMA150, indicating a long-term downtrend formation. Specific trading signals are generated by EMA20 and EMA50 crossovers: buy signals when EMA20 crosses above EMA50, and sell signals when EMA20 crosses below EMA50.
This strategy constructs a complete trend following trading system through the coordinated use of multiple exponential moving averages. The strategy logic is clear, implementation is simple, and it has good scalability. Through the suggested optimization directions, the strategy’s stability and adaptability can be further enhanced. The strategy is suitable for tracking medium to long-term trends, but attention must be paid to market environment selection and risk control when using it.
/*backtest
start: 2024-02-20 00:00:00
end: 2025-01-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("EMA2050150 Crossover Strategy#ganges", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.1, slippage=3)
// EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema150 = ta.ema(close, 150)
// Cross conditions
longCondition = ta.crossover(ema20, ema50)
flatCondition = ta.crossunder(ema20, ema50)
deathCross = ta.crossunder(ema50, ema150)
goldenCross = ta.crossover(ema50, ema150)
// // Trade execution
// if longCondition and time >= startDate and time <= endDate and strategy.position_size == 0
// strategy.entry("Long", strategy.long)
// if flatCondition and time >= startDate and time <= endDate and strategy.position_size > 0
// strategy.close("Long")
// Plot EMAs
plot(ema20, title="EMA 20", color=color.blue)
plot(ema50, title="EMA 50", color=color.orange)
plot(ema150, title="EMA 150", color=color.red)
// Plot cross signals
plotshape(series=goldenCross, location=location.belowbar, color=color.green, style=shape.labelup, title="Golden Cross", size=size.small, text="Golden Cross")
plotshape(series=deathCross, location=location.abovebar, color=color.red, style=shape.labeldown, title="Death Cross", size=size.small, text="Death Cross")
// Plot buy and sell signals
plotshape(series=longCondition, location=location.belowbar, color=color.blue, style=shape.triangleup, title="Buy Signal", size=size.small, text="Buy")
plotshape(series=flatCondition, location=location.abovebar, color=color.orange, style=shape.triangledown, title="Sell Signal", size=size.small, text="Sell")
// Trade execution
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
if flatCondition and strategy.position_size > 0
strategy.close("Long")