资源加载中... loading...

EMA Channel and MACD Based Short-term Trading Strategy

Author: ChaoZhang, Date: 2024-01-23 14:30:02
Tags:

img

Overview

The strategy is named “EMA Channel and MACD Based Short-term Trading Strategy”. It combines EMA channel and MACD indicator to identify trends and generate trading signals.

Principles

The strategy uses 5-day EMA and 21-day EMA to form an EMA channel. When 5-day EMA crosses above 21-day EMA, it is considered a bullish sign. When 5-day EMA crosses below 21-day EMA, it is considered a bearish sign. The MACD histogram can filter out false signals. Buy signals are only generated when MACD histogram is above 0. Sell signals are only generated when MACD histogram is below 0. Once signals are triggered, orders are placed with fixed stop loss and take profit. If price comes back into the EMA channel, signals will be triggered again to follow the trend.

Advantage Analysis

The strategy combines trend identification and indicator filtering, which can effectively identify short-term trend directions. Using EMA channel to determine major trend direction and MACD histogram to filter out false signals can greatly improve profitability. The fixed stop loss and take profit mechanism also ensures good risk-reward ratio. Overall, this strategy is suitable for short-term trading, especially for stocks and forex with strong momentum.

Risk Analysis

The strategy is mainly suitable for short-term trading and performs poorly in long-term and ranging markets. In long-term sideways markets, EMA channel crossovers happen frequently but most are false signals. Although MACD histogram can play a role in filtering, its effectiveness is still limited. Also, the fixed stop loss and take profit makes it hard to capture incremental gains from long-term trends. So these are the main risks of this strategy. The solutions are to flexibly adjust parameters based on market conditions, or switch to other strategies more suitable for current market conditions.

Optimization Directions

The strategy can be optimized in the following aspects:

  1. Optimize EMA parameters to find parameter combinations that maximize returns for specific trading instruments.

  2. Optimize MACD parameters to improve filtering effectiveness.

  3. Incorporate volatility indicators to widen stop loss range when market volatility rises.

  4. Add trailing stop loss mechanism to make stop loss closer to price, reducing unnecessary stop loss trigger while ensuring profitability.

Conclusion

The strategy has relatively high profitability and is especially suitable for short-term trading. It is a good choice among high frequency quantitative trading strategies. But traders need to adjust parameters reasonably based on market conditions when using it, to maximize strategy returns while controlling trading risks.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 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/
// © moondevonyt

//@version=5
strategy("Scalping with EMA channel and MACD", overlay=true)

// Exponential moving average inputs
ema21 = ta.ema(close, 21)
ema5 = ta.ema(close, 5)

// MACD inputs
fastLength = 18
slowLength = 34
signalSmoothing = 12

[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
macdHistogram = macdLine - signalLine

// Buy and sell conditions
buyCondition = ta.crossover(ema5, ema21) and macdHistogram > 0
sellCondition = ta.crossunder(ema5, ema21) and macdHistogram < 0

// Re-entry conditions
reEntryBuyCondition = close > ema21
reEntrySellCondition = close < ema21

// Set stop loss and take profit
stopLoss = 8
takeProfit = 15

// Execute Strategy
if buyCondition
    strategy.entry("Buy", strategy.long)
    strategy.exit("Take Profit/Stop Loss", "Buy", stop=close - stopLoss, limit=close + takeProfit)
if reEntryBuyCondition
    strategy.entry("Re-Enter Buy", strategy.long)
    strategy.exit("Take Profit/Stop Loss", "Re-Enter Buy", stop=close - stopLoss, limit=close + takeProfit)

if sellCondition
    strategy.entry("Sell", strategy.short)
    strategy.exit("Take Profit/Stop Loss", "Sell", stop=close + stopLoss, limit=close - takeProfit)
if reEntrySellCondition
    strategy.entry("Re-Enter Sell", strategy.short)
    strategy.exit("Take Profit/Stop Loss", "Re-Enter Sell", stop=close + stopLoss, limit=close - takeProfit)

// Plotting EMAs and MACD
plot(ema21, color=color.blue, title="21 EMA")
plot(ema5, color=color.orange, title="5 EMA")
plot(macdHistogram, color=color.red, title="MACD Histogram")

// Plot buy and sell signals
plotshape(series=buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(series=sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")

More