Tags:

This strategy uses the crossover of two exponential moving averages (EMAs) as buy and sell signals. When the shorter-period EMA crosses above the longer-period EMA from below, it generates a buy signal; conversely, when the shorter-period EMA crosses below the longer-period EMA from above, it generates a sell signal. Additionally, the strategy determines whether the crossover point is the highest or lowest price within the last 10 trading periods to confirm the strength of the trend. If the crossover point is the highest price, the background will be colored green; if it is the lowest price, it will be colored red. Furthermore, the strategy displays the price of the crossover point on the chart.

- Calculate two EMAs with different periods, with default periods of 5 and 10.
- Determine whether the two EMAs cross over. If the short-term EMA crosses above the long-term EMA from below, it generates a buy signal; if the short-term EMA crosses below the long-term EMA from above, it generates a sell signal.
- When a crossover signal occurs, determine whether the current crossover point is the highest or lowest price within the last 10 trading periods. If it is the highest price, the upward trend is considered strong; if it is the lowest price, the downward trend is considered strong.
- If a buy signal is generated and there is no current position, open a long position; if a sell signal is generated and there is no current position, open a short position.
- If a long position is held and the short-term EMA crosses below the long-term EMA from above, close the long position; if a short position is held and the short-term EMA crosses above the long-term EMA from below, close the short position.

- Exponential moving averages react faster to price changes compared to simple moving averages, thus generating more timely trading signals.
- By determining whether the crossover point is the recent highest or lowest price, it can filter out trading opportunities with greater trend strength and improve strategy profitability.
- Marking the crossover point price on the chart provides traders with more intuitive trading references.
- The code logic is clear and easy to understand and implement.

- The signals generated by EMA crossovers may have a delay, leading to missing the best trading opportunities.
- In a fluctuating market, EMA crossovers may occur frequently, resulting in excessive trading frequency and increased trading costs.
- The strategy lacks stop-loss measures, so if the judgment is wrong, it may face a greater drawdown risk.

- Introduce more technical indicators, such as RSI, MACD, etc., to assist in judging trend strength and direction, and improve signal accuracy.
- Set reasonable stop-loss and take-profit levels to control single-trade risk.
- Optimize trading parameters, such as EMA periods and crossover confirmation time windows, to improve strategy adaptability.
- Combine market sentiment indicators, such as VIX, to filter trading signals and reduce false signals.
- Consider adding position management and capital management modules to dynamically adjust the amount of funds for each trade and improve capital utilization efficiency.

This strategy uses exponential moving average crossovers as its core logic, while also considering the relative position of the crossover point price in the recent period to determine trend strength. Overall, the strategy logic is clear, and the advantages are obvious, but it also has certain limitations and risks. By introducing more auxiliary judgment indicators, setting reasonable risk control measures, and optimizing key parameters, the stability and profitability of this strategy can be further improved.

/*backtest start: 2024-02-01 00:00:00 end: 2024-02-29 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ZenAndTheArtOfTrading // @version=5 strategy("ema giao nhau", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100) // Get user input emaLength1 = input.int(title="EMA #1 Length", defval=5) emaLength2 = input.int(title="EMA #2 Length", defval=10) // Get MAs ema1 = ta.ema(close, emaLength1) ema2 = ta.ema(close, emaLength2) // Draw MAs plot(ema1, color=color.blue, title="EMA 1") plot(ema2, color=color.red, title="EMA 2") // Detect crossovers bool crossOver = ta.crossover(ema1, ema2) bool crossUnder = ta.crossunder(ema1, ema2) bool cross = crossOver or crossUnder //float crossPrice = ta.valuewhen(cross, close, 0) float crossPrice = cross ? close : na // Check if the crossover price is the highest price over the past 10 bars bool highestPrice = crossOver for i = 1 to 10 if crossPrice <= close[i] highestPrice := false break // Check if the crossover price is the lowest price over the past 10 bars bool lowestPrice = crossUnder for i = 1 to 10 if crossPrice >= close[i] lowestPrice := false break // Flag the bar if it is a high/low close bgcolor(highestPrice ? color.new(color.green, 50) : na) bgcolor(lowestPrice ? color.new(color.red, 50) : na) // Display crossover price if cross highestEmaPrice = ema1 > ema2 ? ema1 : ema2 label myLabel = label.new(bar_index, highestEmaPrice, "CrossPrice=" + str.tostring(crossPrice), color=color.white) if highestPrice and strategy.position_size == 0 strategy.entry(id="Buy", direction=strategy.long) if lowestPrice and strategy.position_size == 0 strategy.entry(id="Sell", direction=strategy.short) // Exit trades when short-term EMA is breached if strategy.position_size > 0 and crossUnder strategy.close("Buy") if strategy.position_size < 0 and crossOver strategy.close("Sell")

- Supertrend and Bollinger Bands Combination Strategy
- MACD Trend Following Strategy
- EMA Double Moving Average Crossover Strategy
- XAUUSD 1-Minute Scalping Strategy
- Vector Candle-based Channel Breakout and Custom ChoCH Strategy
- BreakHigh EMA Crossover Strategy
- Dynamic Trend Following Strategy
- Supertrend ATR Strategy
- Triple Exponential Moving Average Convergence Divergence and Relative Strength Index Combined 1-Minute Chart Cryptocurrency Quantitative Trading Strategy
- RSI and Dual Moving Average Based 1-Hour Trend Following Strategy
- SMA-based Trading Strategy for BankNifty Futures
- Bollinger Bands and RSI Trading Strategy
- Gaussian Channel Adaptive Moving Average Strategy
- EMA Crossover Strategy with Target/Stop-loss Ratio and Fixed Position Size
- Moving Average Pullback Tracking Strategy
- RSI Stop Loss Tracking Trading Strategy
- SMA Moving Average Crossover Strategy
- Bollinger 5-Minute Breakout Intraday Trading Strategy
- Variance and Moving Averages Based Volatility Strategy
- Moving Average Crossover Quantitative Strategy