0bps

Strategy vault / Trend following

Dynamic Dual Moving Average Crossover Strategy with Single Trade Execution System using Exponential Moving Averages

This strategy is a trading system based on dual moving average crossover, monitoring the crossing of 9-period and 21-period Exponential Moving Averages (EMA) for trade execution. The strategy operates on a 10-minute…

Author
ianzeng123
Complexity
Starter · 52 lines
Parameters
0
Backtest bar
1h · intraday
Tested on
SOL/USDT · spot

IMG IMG

Overview

This strategy is a trading system based on dual moving average crossover, monitoring the crossing of 9-period and 21-period Exponential Moving Averages (EMA) for trade execution. The strategy operates on a 10-minute timeframe with a single trade mode, preventing multiple position entries while holding a position. The system utilizes an initial capital of 100,000 and trades with 10% of account equity per transaction.

Strategy Principle

The core principle leverages the characteristic that shorter-period EMAs are more sensitive to price changes than longer-period EMAs. When the short-period EMA (9-period) crosses above the long-period EMA (21-period), indicating strengthening upward momentum, the system generates a long signal. When the short-period EMA crosses below the long-period EMA, indicating strengthening downward momentum, the system generates a position closure signal. The strategy uses the position_size parameter to ensure only one trade at a time, effectively controlling risk.

Strategy Advantages

  1. Signal Clarity: Using EMA crossovers as trading signals provides objective and clear criteria, avoiding subjective interference.
  2. Risk Control: Single trade mode prevents risk accumulation from multiple position entries.
  3. Money Management: Position sizing based on account equity percentage dynamically adjusts trade size with account performance.
  4. Visual Support: System provides trade signal labels and moving average trend charts for intuitive judgment.
  5. Real-time Alerts: Integrated trade signal notification ensures traders don't miss important opportunities.

Strategy Risks

  1. Choppy Market Risk: Frequent EMA crossovers in sideways markets may lead to multiple false breakouts.
  2. Lag Risk: EMAs are inherently lagging indicators, potentially missing optimal entry points in fast-moving markets.
  3. Single Dimension: Relying solely on moving average crossovers may ignore other important market information.
  4. Fixed Timeframe Risk: 10-minute timeframe may not be suitable for all market conditions.

Strategy Optimization Directions

  1. Multi-dimensional Verification: Recommend adding volume, volatility, and other auxiliary indicators to improve signal reliability.
  2. Dynamic Parameters: EMA periods could be set as dynamic parameters, adapting to market volatility conditions.
  3. Position Management: Introduce more sophisticated position management systems, such as volatility-based dynamic adjustment.
  4. Market Environment Recognition: Add market condition identification module to adopt different trading parameters under various market conditions.
  5. Stop Loss Optimization: Incorporate dynamic stop-loss mechanisms to enhance risk control flexibility.

Summary

This is a well-designed moving average crossover strategy with clear logic. It captures market trends through EMA crossovers, combined with single trade mode and percentage-based position management to achieve a balance between risk and return. While there are some inherent limitations, the strategy's stability and adaptability can be further enhanced through the suggested optimization directions. In practical application, traders should make appropriate adjustments based on specific market characteristics and individual risk preferences.

Source Pine Script

/*backtest
start: 2024-02-25 00:00:00
end: 2025-02-22 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/

//@version=6
strategy("EMA Crossover Labels (One Trade at a Time)", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// ==== User Inputs ====
// Set the testing timeframe (ensure the chart is on a 10-min timeframe)
testTimeFrame = input.timeframe("10", "Strategy Timeframe")

// EMA period inputs
emaPeriod9  = input.int(9, "EMA 9 Period", minval=1)
emaPeriod21 = input.int(21, "EMA 2q Period", minval=1)

// ==== Retrieve Price Data ====
// For simplicity, we use the chart's timeframe (should be 10-min)
price = close

// ==== Calculate EMAs ====
ema9  = ta.ema(price, emaPeriod9)
ema21 = ta.ema(price, emaPeriod21)

// ==== Define Crossover Conditions ====
// Buy signal: when EMA9 crosses above EMA21 AND no current position is open
buySignal = ta.crossover(ema9, ema21) and strategy.position_size == 0
// Sell signal: when EMA9 crosses below EMA21 AND a long position is active
sellSignal = ta.crossunder(ema9, ema21) and strategy.position_size > 0

// ==== Strategy Orders ====
// Enter a long position when a valid buy signal occurs
if buySignal
    strategy.entry("Long", strategy.long)
    alert("Long Signal: " + syminfo.tickerid + " - EMA9 crossed above EMA21", alert.freq_once_per_bar_close)
// Exit the long position when a valid sell signal occurs
if sellSignal
    strategy.close("Long")
    alert("Sell Long Signal: " + syminfo.tickerid + " - EMA9 crossed below EMA21", alert.freq_once_per_bar_close)

// ==== Plot Buy/Sell Labels ====
// Only plot a "Buy" label if there's no open position
plotshape(buySignal, title="Buy Label", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", textcolor=color.white)
// Only plot a "Sell" label if a position is active
plotshape(sellSignal, title="Sell Label", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", textcolor=color.white)

// ==== Plot EMAs for Visualization ====
plot(ema9, color=color.blue, title="EMA 21")
plot(ema21, color=color.orange, title="EMA 21")

Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-24. 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-Dual-Moving-Average-Crossover-Strategy-with-Single-Trade-Execution-System-using-Exponential-Moving-Averages.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