0bps

Strategy vault / Trend following

Fast and Slow EMA Crossover Trend Trading Strategy

This strategy trades the crossover of fast and slow EMAs to determine and track price trends. It aims to capture intermediate-term trends. Strategy Logic: 1. Calculate fast and slow EMAs, typically 13 and 48 periods…

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

This strategy trades the crossover of fast and slow EMAs to determine and track price trends. It aims to capture intermediate-term trends.

Strategy Logic:

  1. Calculate fast and slow EMAs, typically 13 and 48 periods.

  2. Enter long when fast EMA crosses above slow EMA.

  3. Exit long when price crosses below fast EMA.

  4. Option to add short side rules for two-way trading.

Advantages:

  1. Fast/slow EMA combo effectively identifies intermediate trends.

  2. Breakout trading allows timely trend entries.

  3. Simple stop loss mechanism controls loss per trade.

Risks:

  1. EMA lag causes missed best entry points.

  2. Loosen stops to avoid excessive whipsaws.

  3. Hard to determine clear trend direction during ranges.

In summary, this strategy uses EMA crosses for trend identification and tracking. Optimization on parameters and risk controls can further improve performance for a wide range of markets.

Parameters

NameDefaultWhat it controls
v_input_1_close0Fast MA Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_213Fast MA Period
v_input_3_close0Slow MA Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_448Slow MA Period

Source Pine Script

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

//@version=3

// strategy("EMA Strategy 13 48", shorttitle = "EMA Strategy 13 48", overlay=true, pyramiding = 3,default_qty_type = strategy.percent_of_equity, default_qty_value = 1000)


// === Inputs ===
// short ma
maFastSource   = input(defval = close, title = "Fast MA Source")
maFastLength   = input(defval = 13, title = "Fast MA Period", minval = 1)

// long ma
maSlowSource   = input(defval = close, title = "Slow MA Source")
maSlowLength   = input(defval = 48, title = "Slow MA Period", minval = 1)


// === Vars and Series ===
fastMA = ema(maFastSource, maFastLength)
slowMA = ema(maSlowSource, maSlowLength)

plot(fastMA, color=blue)
plot(slowMA, color=purple)

goLong() => crossover(fastMA, slowMA)
killLong() => crossunder(close, fastMA)
strategy.entry("Buy", strategy.long, when = goLong())
strategy.close("Buy", when = killLong())

// Shorting if using
goShort() => crossunder (fastMA, slowMA)
killShort() => crossover(fastMA, slowMA)
//strategy.entry("Sell", strategy.short, when = goShort())
//strategy.close("Sell", when = killShort())


 

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-12. 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-and-Slow-EMA-Crossover-Trend-Trading-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