
This strategy is a trading system based on dual moving average crossover, monitoring the crossing of 9-period and 21-period Exponential Moving Averages (EMA) for trade execution. The strategy operates on a 10-minute timeframe with a single trade mode, preventing multiple position entries while holding a position. The system utilizes an initial capital of 100,000 and trades with 10% of account equity per transaction.
The core principle leverages the characteristic that shorter-period EMAs are more sensitive to price changes than longer-period EMAs. When the short-period EMA (9-period) crosses above the long-period EMA (21-period), indicating strengthening upward momentum, the system generates a long signal. When the short-period EMA crosses below the long-period EMA, indicating strengthening downward momentum, the system generates a position closure signal. The strategy uses the position_size parameter to ensure only one trade at a time, effectively controlling risk.
This is a well-designed moving average crossover strategy with clear logic. It captures market trends through EMA crossovers, combined with single trade mode and percentage-based position management to achieve a balance between risk and return. While there are some inherent limitations, the strategy’s stability and adaptability can be further enhanced through the suggested optimization directions. In practical application, traders should make appropriate adjustments based on specific market characteristics and individual risk preferences.
/*backtest
start: 2024-02-25 00:00:00
end: 2025-02-22 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=6
strategy("EMA Crossover Labels (One Trade at a Time)", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ==== User Inputs ====
// Set the testing timeframe (ensure the chart is on a 10-min timeframe)
testTimeFrame = input.timeframe("10", "Strategy Timeframe")
// EMA period inputs
emaPeriod9 = input.int(9, "EMA 9 Period", minval=1)
emaPeriod21 = input.int(21, "EMA 2q Period", minval=1)
// ==== Retrieve Price Data ====
// For simplicity, we use the chart's timeframe (should be 10-min)
price = close
// ==== Calculate EMAs ====
ema9 = ta.ema(price, emaPeriod9)
ema21 = ta.ema(price, emaPeriod21)
// ==== Define Crossover Conditions ====
// Buy signal: when EMA9 crosses above EMA21 AND no current position is open
buySignal = ta.crossover(ema9, ema21) and strategy.position_size == 0
// Sell signal: when EMA9 crosses below EMA21 AND a long position is active
sellSignal = ta.crossunder(ema9, ema21) and strategy.position_size > 0
// ==== Strategy Orders ====
// Enter a long position when a valid buy signal occurs
if buySignal
strategy.entry("Long", strategy.long)
alert("Long Signal: " + syminfo.tickerid + " - EMA9 crossed above EMA21", alert.freq_once_per_bar_close)
// Exit the long position when a valid sell signal occurs
if sellSignal
strategy.close("Long")
alert("Sell Long Signal: " + syminfo.tickerid + " - EMA9 crossed below EMA21", alert.freq_once_per_bar_close)
// ==== Plot Buy/Sell Labels ====
// Only plot a "Buy" label if there's no open position
plotshape(buySignal, title="Buy Label", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", textcolor=color.white)
// Only plot a "Sell" label if a position is active
plotshape(sellSignal, title="Sell Label", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", textcolor=color.white)
// ==== Plot EMAs for Visualization ====
plot(ema9, color=color.blue, title="EMA 21")
plot(ema21, color=color.orange, title="EMA 21")