This is a quantitative trading strategy based on the EMA indicator, which makes trading decisions by calculating the crossover signals of short-term (9-period) and long-term (21-period) exponential moving averages. The strategy includes stop-loss and take-profit conditions set at 2% and 4% respectively to control risk and lock in profits. The core idea is to capture market trend turning points through moving average crossovers, enabling timely buy and sell operations when market trends change.
The strategy employs two exponential moving averages (EMA) with different periods: 9-period and 21-period. A buy signal is generated when the short-term EMA crosses above the long-term EMA, while a sell signal is triggered when the short-term EMA crosses below the long-term EMA. The strategy incorporates risk management mechanisms through 2% stop-loss and 4% take-profit levels to protect capital and secure gains. The short-term moving average is more sensitive to price changes, while the long-term moving average reflects longer-term trends, making their crossovers effective in capturing market trend transitions.
This strategy is a classic trend-following approach that captures market trend changes through moving average crossovers. While relatively simple in design, it includes complete trading logic and risk control mechanisms. The strategy’s stability and profitability can be further enhanced through optimization measures such as dynamic parameter adjustment and market condition assessment. In practical application, it is recommended to optimize parameters based on specific trading instruments and market conditions while maintaining proper risk control.
/*backtest start: 2019-12-23 08:00:00 end: 2024-11-27 00:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ancour //@version=5 strategy("Moving Average Crossover", overlay=true) // Define the length for short-term and long-term EMAs shortEmaLength = 9 longEmaLength = 21 // Calculate EMAs shortEma = ta.ema(close, shortEmaLength) longEma = ta.ema(close, longEmaLength) // Plot EMAs on the chart plot(shortEma, title="Short-term EMA", color=color.green, linewidth=2) plot(longEma, title="Long-term EMA", color=color.red, linewidth=2) // Strategy conditions for crossovers longCondition = ta.crossover(shortEma, longEma) shortCondition = ta.crossunder(shortEma, longEma) // Enter long when short EMA crosses above long EMA if (longCondition) strategy.entry("Buy", strategy.long) // Exit long or enter short when short EMA crosses below long EMA if (shortCondition) strategy.entry("Sell", strategy.short) // Optional: Add stop-loss and take-profit levels for risk management stopLossPercent = 2 takeProfitPercent = 4 strategy.exit("Sell TP/SL", "Buy", stop=low * (1 - stopLossPercent/100), limit=high * (1 + takeProfitPercent/100))