0bps

Strategy vault / Breakout

fast EMA and slow EMA Momentum Breakthrough Strategy

This strategy generates buy and sell signals by calculating fast EMA and slow EMA, and going long when the fast EMA crosses above the slow EMA, and going short when the fast EMA crosses below the slow EMA to make…

Author
ChaoZhang
Complexity
Starter · 40 lines
Parameters
2
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy generates buy and sell signals by calculating fast EMA and slow EMA, and going long when the fast EMA crosses above the slow EMA, and going short when the fast EMA crosses below the slow EMA to make profits. This strategy belongs to momentum tracking strategy.

Strategy Principle

This strategy mainly utilizes the smoothing concept of the EMA indicator. EMA stands for Exponential Moving Average, which is a technical indicator that uses historical price trends to predict future price trends. The EMA indicator consists of a fast line and a slow line, where the fast line is more sensitive to recent price changes and the slow line is more sensitive to historical price changes. When short-term price fluctuations exceed a certain level, the fast line will cross above or below the slow line, generating buy or sell signals.

Specifically, this strategy chooses an EMA with a length of 37 as the fast line, and an EMA with a length of 175 as the slow line. It generates a buy signal when the fast line crosses above the slow line for going long, and it generates a sell signal when the fast line crosses below the slow line for going short. It realizes stop loss or take profit after going long by the slow line crossing below the fast line.

Strategy Advantages

This EMA crossover strategy has the following advantages:

  1. Simple principle, easy to understand and implement
  2. Can effectively capture short-term trends in the market
  3. Relatively low pullback risk contro
  4. The EMA periods can be adjusted to adapt to different products

Strategy Risks

This strategy also has some potential risks:

  1. Prone to generating false signals, may enter too early or too late
  2. EMA indicator lags, may miss key turning points
  3. Easy to be stopped out in range-bound markets
  4. Backtesting overfitting risk, questionable effect in live trading

To reduce these risks, we can consider optimizing the timing of entries, setting stop loss levels, combining with other indicators for filtration and so on.

Strategy Optimization Directions

There is room for further optimization of this strategy:

  1. Optimize EMA period parameters to adapt to different product characteristics
  2. Add volume indicator filters to avoid wrongly entering during market swings
  3. Set up moving stop loss, gradually adjust stop loss level according to the trend
  4. Combine with volatility indicators to dynamically adjust position size based on market volatility

Summary

In general, this simple EMA crossover strategy is easy for beginners to grasp. But its actual effect needs practical verification, and investors should also be aware of the risks of backtest overfitting when using it. By optimizing parameters, combining indicators, etc., the stability and practical effect of this strategy can be further enhanced.

Parameters

NameDefaultWhat it controls
v_input_137Fast EMA Length
v_input_2370Slow EMA Length

Source Pine Script

/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © umerhafeez37733

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

// Input for EMA lengths
fastEmaLength = input(37, title="Fast EMA Length")
slowEmaLength = input(370, title="Slow EMA Length")

// Calculate EMAs
fastEma = ta.ema(close, fastEmaLength)
slowEma = ta.ema(close, slowEmaLength)

// Plot EMAs on the chart
plot(fastEma, title="Fast EMA", color=color.blue)
plot(slowEma, title="Slow EMA", color=color.red)

// Buy condition: Fast EMA crosses above Slow EMA
buyCondition = ta.crossover(fastEma, slowEma)

// Sell condition: Fast EMA crosses below Slow EMA
sellCondition = ta.crossunder(fastEma, slowEma)

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

// Execute strategy
strategy.entry("Buy", strategy.long, when=buyCondition)
strategy.close("Buy", when=sellCondition)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-27. 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/fast-EMA-and-slow-EMA-Momentum-Breakthrough-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