0bps

Strategy vault / Trend following

Multi EMA Crossover with Time Interval Integration Strategy

This strategy is a quantitative trading system based on multiple Exponential Moving Average (EMA) crossovers and time interval control. It utilizes crossover signals between the 50-period EMA and both 5-period and…

Author
ChaoZhang
Complexity
Starter · 55 lines
Parameters
0
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a quantitative trading system based on multiple Exponential Moving Average (EMA) crossovers and time interval control. It utilizes crossover signals between the 50-period EMA and both 5-period and 10-period EMAs to generate buy and sell decisions. The strategy also incorporates a 30-candle time interval mechanism to avoid overtrading and sets fixed take-profit and stop-loss levels for risk management. This approach aims to capture medium to long-term trends while improving trade quality through time filters and risk management measures.

Strategy Principles

  1. Moving Average System: The strategy uses three EMAs - 50-period (slow), 10-period (medium), and 5-period (fast).

  2. Entry Signals:

    • Buy Signal: Triggered when both 5-period and 10-period EMAs cross above the 50-period EMA.
    • Sell Signal: Triggered when both 5-period and 10-period EMAs cross below the 50-period EMA.
  3. Time Interval Control: The strategy ensures at least 30 candle periods have passed since the last trade before executing a new one. This helps reduce noisy trades and focus on more significant trend changes.

  4. Risk Management:

    • Take Profit is set at 50 pips.
    • Stop Loss is set at 30 pips.
  5. Trade Execution:

    • All existing positions are closed before opening new ones.
    • Buy and sell orders are executed using market orders.
  6. Visualization: The strategy plots the three EMA lines and trade signal markers on the chart for analysis and backtesting purposes.

Strategy Advantages

  1. Multiple Confirmations: Using two fast EMAs (5 and 10-period) crossing the slow EMA (50-period) simultaneously provides stronger trend confirmation signals, reducing false breakouts.

  2. Trend Following: The 50-period EMA serves as the main trend indicator, helping to capture medium to long-term market movements.

  3. Time Filtering: The 30-candle period interval requirement effectively reduces overtrading and improves signal quality.

  4. Risk Control: Fixed take-profit and stop-loss levels provide a clear risk-reward ratio for each trade.

  5. Automation: The strategy is fully automated, eliminating human emotional interference.

  6. Adaptability: While the strategy uses fixed parameters, its logic can be easily adapted to different markets and timeframes.

  7. Visual Assistance: Graphical representation of EMA lines and trade signals aids in intuitive assessment of strategy performance.

Strategy Risks

  1. Lag: EMAs are inherently lagging indicators and may react slowly in highly volatile markets.

  2. Performance in Ranging Markets: The strategy may produce frequent false signals in sideways or choppy markets.

  3. Fixed Take-Profit and Stop-Loss: While providing stable risk management, these may not be suitable for all market conditions.

  4. Parameter Sensitivity: The choice of EMA periods and time interval can significantly affect strategy performance.

  5. Over-reliance on Technical Indicators: The strategy does not consider fundamental factors and may underperform during major news events.

  6. Drawdown Risk: The strategy may face significant drawdowns during strong trend reversals.

  7. Execution Slippage: In fast markets, there may be a risk of high execution slippage.

Strategy Optimization Directions

  1. Dynamic Parameter Adjustment: Consider dynamically adjusting EMA periods and trade intervals based on market volatility.

  2. Incorporate Volume Indicators: Combine volume or other momentum indicators to enhance signal reliability.

  3. Adaptive Take-Profit and Stop-Loss: Set dynamic take-profit and stop-loss levels based on market volatility or ATR.

  4. Market State Classification: Add logic to determine market state (trending/ranging) and apply different trading strategies accordingly.

  5. Timeframe Fusion: Consider signal confirmation across multiple timeframes to improve trade quality.

  6. Risk Exposure Management: Introduce position sizing logic to adjust trade volume based on account risk and market volatility.

  7. Add Filters: Such as trend strength indicators or volatility filters to reduce false signals.

  8. Backtesting Optimization: Conduct more extensive parameter optimization and out-of-sample testing to improve strategy robustness.

Conclusion

The Multi-EMA Crossover with Time Interval Integration Strategy is a quantitative trading system that combines technical analysis with risk management. It captures trends through multiple EMA crossovers, uses a time filter to improve signal quality, and manages risk through fixed take-profit and stop-loss levels. While the strategy shows potential for capturing medium to long-term trends, it also faces some inherent limitations of technical indicators. Through the suggested optimization directions, such as dynamic parameter adjustment, multi-indicator integration, and adaptive risk management, the strategy has the potential to further enhance its performance and adaptability. In practical application, comprehensive backtesting and forward testing are necessary, with fine-tuning based on specific market conditions and risk preferences.

Source Pine Script

/*backtest
start: 2024-06-01 00:00:00
end: 2024-06-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("EMA Cross Strategy", overlay=true)

// Define the EMAs
ema50 = ta.ema(close, 50)
ema5 = ta.ema(close, 5)
ema10 = ta.ema(close, 10)

// Define crossover and crossunder conditions
buyCondition = ta.crossover(ema5, ema50) and ta.crossover(ema10, ema50)
sellCondition = ta.crossunder(ema5, ema50) and ta.crossunder(ema10, ema50)

// Calculate pip values
pip = syminfo.mintick * 10
takeProfitPips = 50 * pip
stopLossPips = 30 * pip

// Track the last order time to ensure 30 candle gap
var float lastOrderTime = na
timeElapsed = (na(lastOrderTime) ? na : (time - lastOrderTime) / (1000 * syminfo.mintick))

// Close previous orders before opening new ones
if (buyCondition or sellCondition) and (na(timeElapsed) or timeElapsed >= 30)
    strategy.close_all()
    lastOrderTime := time

// Open buy orders
if buyCondition and (na(timeElapsed) or timeElapsed >= 30)
    strategy.entry("Buy", strategy.long)
    strategy.exit("Take Profit/Stop Loss", from_entry="Buy", limit=takeProfitPips, stop=stopLossPips)
    lastOrderTime := time

// Open sell orders
if sellCondition and (na(timeElapsed) or timeElapsed >= 30)
    strategy.entry("Sell", strategy.short)
    strategy.exit("Take Profit/Stop Loss", from_entry="Sell", limit=takeProfitPips, stop=stopLossPips)
    lastOrderTime := time

// Plot signals
plotshape(series=buyCondition and (na(timeElapsed) or timeElapsed >= 30), location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition and (na(timeElapsed) or timeElapsed >= 30), location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Plot EMAs for visualization
plot(ema50, color=color.blue, title="EMA 50")
plot(ema5, color=color.orange, title="EMA 5")
plot(ema10, color=color.purple, title="EMA 10")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-07-30. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Multi-EMA-Crossover-with-Time-Interval-Integration-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open