Dual EMA Stochastic Oscillator System: A Quantitative Trading Model Combining Trend Following and Momentum

FMZQuant - Feb 11 - - Dev Community

Image description

Overview
This strategy is a quantitative trading system that combines a double exponential moving average (EMA) and a stochastic oscillator. The market trend is determined by the 20-period and 50-period EMAs, and the stochastic oscillator is used to find trading opportunities in the overbought and oversold areas, achieving a perfect combination of trend and momentum. The strategy adopts strict risk management measures, including fixed stop loss and profit target settings.

Strategy Principle
The core logic of the strategy is divided into three parts: trend judgment, entry timing and risk control. Trend judgment mainly relies on the relative position of the fast EMA (20 periods) and the slow EMA (50 periods). When the fast line is above the slow line, it is judged as an upward trend, and vice versa, it is a downward trend. The entry signal is confirmed by the crossover of the stochastic oscillator, and high-win trading opportunities are sought in the overbought and oversold areas. Risk control uses a fixed percentage stop loss and a 2x take profit ratio setting to ensure that each transaction has a clear risk-return ratio.

Strategy Advantages

  1. Combining trend tracking and momentum indicators can achieve stable returns in trending markets
  2. Adopt scientific fund management methods to control the loss of each transaction by fixing the risk ratio
  3. Indicator parameters can be flexibly adjusted according to different market characteristics
  4. The strategy logic is clear, easy to understand and implement
  5. Suitable for trading in multiple time frames

Strategy Risks

  1. Frequent false signals may occur in volatile markets
  2. The choice of EMA parameters affects strategy performance
  3. The overbought and oversold settings of the Stochastic Oscillator need to be adjusted for specific markets
  4. Stops may be too wide in fast-moving markets
  5. Need to consider the impact of transaction costs on strategy returns

Strategy Optimization Direction

  1. Add volume indicator as auxiliary confirmation
  2. Introducing the ATR indicator to dynamically adjust the stop loss position
  3. Adaptive adjustment of indicator parameters according to market volatility
  4. Add trend strength filter to reduce false signals
  5. Developing an adaptive profit target calculation method

Summary
The strategy combines trend and momentum indicators to establish a complete trading system. The core advantage of the strategy lies in its clear logical framework and strict risk control, but in actual application, parameter optimization is still required according to specific market conditions. Through continuous improvement and optimization, the strategy is expected to maintain stable performance in various market environments.

Strategy source code

/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy("EMA + Stochastic Strategy", overlay=true)

// Inputs for EMA
emaShortLength = input.int(20, title="Short EMA Length")
emaLongLength = input.int(50, title="Long EMA Length")

// Inputs for Stochastic
stochK = input.int(14, title="Stochastic %K Length")
stochD = input.int(3, title="Stochastic %D Smoothing")
stochOverbought = input.int(85, title="Stochastic Overbought Level")
stochOversold = input.int(15, title="Stochastic Oversold Level")

// Inputs for Risk Management
riskRewardRatio = input.float(2.0, title="Risk-Reward Ratio")
stopLossPercent = input.float(1.0, title="Stop Loss (%)")

// EMA Calculation
emaShort = ta.ema(close, emaShortLength)
emaLong = ta.ema(close, emaLongLength)

// Stochastic Calculation
k = ta.stoch(high, low, close, stochK)
d = ta.sma(k, stochD)

// Trend Condition
isUptrend = emaShort > emaLong
isDowntrend = emaShort < emaLong

// Stochastic Signals
stochBuyCrossover = ta.crossover(k, d)
stochBuySignal = k < stochOversold and stochBuyCrossover
stochSellCrossunder = ta.crossunder(k, d)
stochSellSignal = k > stochOverbought and stochSellCrossunder

// Entry Signals
buySignal = isUptrend and stochBuySignal
sellSignal = isDowntrend and stochSellSignal

// Strategy Execution
if buySignal
    strategy.entry("Buy", strategy.long)
    stopLoss = close * (1 - stopLossPercent / 100)
    takeProfit = close * (1 + stopLossPercent * riskRewardRatio / 100)
    strategy.exit("Take Profit/Stop Loss", from_entry="Buy", stop=stopLoss, limit=takeProfit)

if sellSignal
    strategy.entry("Sell", strategy.short)
    stopLoss = close * (1 + stopLossPercent / 100)
    takeProfit = close * (1 - stopLossPercent * riskRewardRatio / 100)
    strategy.exit("Take Profit/Stop Loss", from_entry="Sell", stop=stopLoss, limit=takeProfit)

// Plotting
plot(emaShort, color=color.blue, title="Short EMA")
plot(emaLong, color=color.red, title="Long EMA")
Enter fullscreen mode Exit fullscreen mode

Strategy Parameters

Image description

The original address: Dual EMA Stochastic Oscillator System: A Quantitative Trading Model Combining Trend Following and Momentum

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .