This strategy generates trading signals by calculating the crossovers between 5-day exponential moving average (EMA) and 20-day simple moving average (SMA). It goes long when 5-day EMA crosses above 20-day SMA and closes position when price change reaches 5% or -5%. It also incorporates Trading Index Index (TII) as an auxiliary indicator.
Double exponential moving averages are widely used technical indicators. 5-day EMA represents recent price trends while 20-day SMA shows medium-term price moves. When shorter-term MA crosses above longer-term MA, it signals an upside breakout and upward price trend, indicating good timing to go long. On the contrary, downward crossover implies potential price reversal and should consider exiting positions.
This strategy sets 5-day EMA and 20-day SMA as trading signals. It goes long when 5-day EMA crosses over 20-day SMA and closes position when price change hits 5% or -5%. It also checks if TII is positive and rising to confirm the signal reliability.
The detailed steps are:
This strategy utilizes the golden crossover between two MAs and has following pros:
In general, this strategy has straightforward rules, utilizes mature technical indicators like MA crossovers, and has relatively comprehensive risk control measurements. It is suitable for beginners to learn and use in quantitative trading field.
There are still some risks within this strategy:
Suggested improvements are:
So there is room for further optimization.
This strategy can be improved from the following aspects:
Optimize MA parameters by testing shorter/longer EMA and SMA combinations to find the optimal pair.
Add other indicators like MACD, KDJ to filter false signals.
Employ machine learning algorithms to find better parameters through historical data modeling and statistics.
Set dynamic stop loss/take profit based on market volatility and instrument characteristics to better control risks.
Expand this strategy to other products like forex, cryptocurrencies.
Through above enhancements, the stability and profitability of this strategy can be substantially improved.
In conclusion, this is an easy-to-understand and implement dual MA crossover strategy. It takes advantage of MA signals and uses TII to filter errors. It controls risks by stop loss/take profit. The strategy suits beginners to learn and also has large room for optimizations. Further improvements on parameter tuning, signal filtering and dynamic stop loss can transform it into a practical and powerful trading strategy.
/*backtest start: 2024-01-02 00:00:00 end: 2024-02-01 00:00:00 period: 2h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("EMA-SMA Crossover Strategy", shorttitle="EMA-SMA Cross", overlay=true) // Define the moving averages ema5 = ta.ema(close, 5) sma20 = ta.sma(close, 20) smaVolume10 = ta.sma(volume, 50) majorLength = input(60, title="Major Length") minorLength = input(30, title="Minor Length") src = input(close, title="Source") smaValue = ta.sma(src, majorLength) positiveSum = 0.0 negativeSum = 0.0 for i = 0 to minorLength - 1 price = na(src[i]) ? 0 : src[i] avg = na(smaValue[i]) ? 0 : smaValue[i] positiveSum := positiveSum + (price > avg ? price - avg : 0) negativeSum := negativeSum + (price > avg ? 0 : avg - price) tii = 100 * positiveSum / (positiveSum + negativeSum) // Buy condition: 5 EMA crosses above 20 SMA buyCondition = ta.crossover(ema5, sma20) and tii > 0 and tii >= tii[1] //and volume > smaVolume10 // // Track entry price var entryPrice = 0.0 if (buyCondition) entryPrice := close // Calculate percentage change from entry price priceChange = close / entryPrice - 1 // Plotting the moving averages on the chart plot(ema5, color=color.blue, title="5 EMA") plot(sma20, color=color.red, title="20 SMA") // Highlighting buy signals and exit signals on the chart // plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, size=size.small, style=shape.labelup, text="Buy") // Strategy entry and exit if (buyCondition) strategy.entry("Buy", strategy.long) // Exit conditions if (strategy.opentrades > 0) if (priceChange >= 0.05 or priceChange <= -0.05) strategy.close("Buy")