0bps

Strategy vault / Trend following

Dynamic Filtering EMA Cross Strategy for Daily Trend Analysis

This strategy employs a dual moving average system for trend determination and trading decisions, utilizing the relative position of fast and slow exponential moving averages (EMAs) at specific time points to…

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

IMG

Overview

This strategy employs a dual moving average system for trend determination and trading decisions, utilizing the relative position of fast and slow exponential moving averages (EMAs) at specific time points to identify trend initiation, continuation, or termination. The strategy checks the relationship between fast and slow EMAs at a fixed time daily, establishing long positions when the fast line is above the slow line and short positions when it's below.

Strategy Principle

The core of the strategy is based on two EMAs with different periods for trend determination. The fast EMA (default period 10) is more sensitive to price changes, capable of capturing market movements quickly; the slow EMA (default period 50) reflects longer-term trends. The strategy checks the position relationship between these two lines at a specified time each trading day (default 9:00), using EMA crossover signals to determine market trend direction and execute trades. A long position is entered when the fast EMA crosses above the slow EMA, indicating strengthening upward momentum, while a short position is entered when the fast EMA crosses below the slow EMA, indicating strengthening downward momentum.

Strategy Advantages

  1. Clear and simple trading logic, easy to understand and execute
  2. Filters noise signals through daily fixed-time checks, reducing false trades
  3. Employs percentage-based position sizing for effective risk control
  4. Combines fast and slow moving averages to effectively capture trend initiation and reversal
  5. Highly adjustable strategy parameters, suitable for different market environments
  6. High degree of automation, requiring no manual intervention

Strategy Risks

  1. May generate frequent trades in choppy markets, increasing transaction costs
  2. Fixed entry timing might miss important price movements
  3. Moving average systems have inherent lag, potentially causing delayed entries or exits
  4. May experience significant drawdowns in highly volatile markets
  5. Improper parameter selection can affect strategy performance

Strategy Optimization Directions

  1. Incorporate volatility indicators to adjust position sizing during high volatility periods
  2. Add trend confirmation indicators like MACD or RSI to improve signal reliability
  3. Optimize entry timing mechanism, considering dynamic time checks based on market characteristics
  4. Add stop-loss and take-profit mechanisms for better risk control
  5. Consider incorporating volume analysis to improve signal quality
  6. Develop adaptive parameter mechanisms for increased flexibility

Summary

The strategy achieves a simple yet effective trend-following trading system by combining a dual EMA system with fixed-time check mechanisms. Its strengths lie in clear logic and high automation, though it faces limitations from moving average lag and fixed entry timing. There remains significant room for improvement through the introduction of additional technical indicators, optimization of parameter selection mechanisms, and enhanced risk control measures. Overall, this represents a practical basic strategy framework that can be further refined and optimized according to specific requirements.

Source Pine Script

/*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=5
strategy("Daily EMA Comparison Strategy", shorttitle="Daily EMA cros Comparison", overlay=true)

//------------------------------------------------------------------------------
// Inputs
//------------------------------------------------------------------------------
fastEmaLength = input.int(10, title="Fast EMA Length", minval=1)  // Fast EMA period
slowEmaLength = input.int(50, title="Slow EMA Length", minval=1)  // Slow EMA period
checkHour = input.int(9, title="Check Hour (24h format)", minval=0, maxval=23)  // Hour to check
checkMinute = input.int(0, title="Check Minute", minval=0, maxval=59)  // Minute to check

//------------------------------------------------------------------------------
// EMA Calculation
//------------------------------------------------------------------------------
fastEMA = ta.ema(close, fastEmaLength)
slowEMA = ta.ema(close, slowEmaLength)

//------------------------------------------------------------------------------
// Time Check
//------------------------------------------------------------------------------
// Get the current bar's time in the exchange's timezone
currentTime = timestamp("GMT-0", year, month, dayofmonth, checkHour, checkMinute)
// Check if the bar's time equals or passes the daily check time
isCheckTime = (time >= currentTime and time < currentTime + 60 * 1000)  // 1-minute tolerance

//------------------------------------------------------------------------------
// Entry Conditions
//------------------------------------------------------------------------------
// Buy if Fast EMA is above Slow EMA at the specified time
buyCondition = isCheckTime and fastEMA > slowEMA

// Sell if Fast EMA is below Slow EMA at the specified time
sellCondition = isCheckTime and fastEMA < slowEMA

//------------------------------------------------------------------------------
// Strategy Execution
//------------------------------------------------------------------------------
// Enter Long
if buyCondition
    strategy.entry("Long", strategy.long)

// Enter Short
if sellCondition
    strategy.entry("Short", strategy.short)

//------------------------------------------------------------------------------
// Plot EMAs
//------------------------------------------------------------------------------
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.orange, title="Slow EMA")

Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. 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/Dynamic-Filtering-EMA-Cross-Strategy-for-Daily-Trend-Analysis.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