0bps

Strategy vault / Trend following

Fast and Slow Moving Average Crossover Strategy

The fast and slow moving average crossover strategy is a quantitative trading strategy that generates trading signals by comparing fast and slow moving averages. It goes long when the fast MA crosses above the slow…

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

Strategy Overview

The fast and slow moving average crossover strategy is a quantitative trading strategy that generates trading signals by comparing fast and slow moving averages. It goes long when the fast MA crosses above the slow MA, and goes short when the fast MA crosses below the slow MA. The strategy aims to capture trend turning points on the medium-short term timeframe.

Strategy Logic

  1. Calculate the fast MA, typically 5-10 period EMA.

  2. Calculate the slow MA, typically 20-60 period SMA.

  3. Go long when fast MA crosses above slow MA.

  4. Go short when fast MA crosses below slow MA.

  5. Initiate new trades at each crossover.

The fast MA reacts swiftly to price changes and reflects the latest trend. The slow MA filters out low frequency noises and captures the major trend. Crossovers signal potential trend reversals for improved trading accuracy.

The flexible parameter settings can be optimized for different periods and market environments.

Advantages of the Strategy

  • Fast and slow MAs combine for trend identification

  • Clear and simple crossover signals

  • Period optimization for different markets

  • Easy to program and backtest

  • Combinable with other indicators

Risk Warnings

  • Potential lagging of moving averages

  • Possible false breakout signals

  • Prevent excessive trading frequency

  • Entry and exit levels unclear

Conclusion

The fast and slow MA crossover strategy judges trend turning points by comparing different MA periods, and is a classical and common quantitative trading approach. Parameters can be tuned and combined with other indicators to control risks and improve returns.

Parameters

NameDefaultWhat it controls
v_input_19fastLength
v_input_240slowlength

Source Pine Script

/*backtest
start: 2023-08-15 00:00:00
end: 2023-09-14 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("Cruzameto 2MM", overlay=true)

fastLength = input(9)
slowlength = input(40)
//MACDLength = input(9)

delta = ema(close, fastLength) - sma(close, slowlength)
//aMACD = ema(MACD, MACDLength)
//delta = MACD - aMACD

if (crossover(delta, 0))
    strategy.entry("Compra", strategy.long, comment="2MM")

if (crossunder(delta, 0))
    strategy.entry("Venda", strategy.short, comment="2MM")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-01. 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-Moving-Average-Crossover-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