0bps

Strategy vault / Trend following

Simple Moving Average Crossover Strategy 440436

The Simple Moving Average Crossover strategy is based on the crossover of two moving averages, a faster moving average (fast MA) and a slower moving average (slow MA). It goes long (buys) when the fast MA crosses…

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

IMG

Overview

The Simple Moving Average Crossover strategy is based on the crossover of two moving averages, a faster moving average (fast MA) and a slower moving average (slow MA). It goes long (buys) when the fast MA crosses above the slow MA, and closes the long position when the fast MA crosses below the slow MA.

Principle

The strategy uses two moving averages. One is a short-term fast MA that responds quickly to price changes. The other is a long-term slow MA that filters out short-term fluctuations and reflects long-term trends better. When the fast MA crosses above the slow MA, it signals an upward trend in the short-term and is considered a golden cross buy signal. When the fast MA crosses below the slow MA, it signals a short-term downward trend and is considered a death cross sell signal.

Advantages

  1. Simple to implement and easy to understand with few parameters and less prone to overfitting.
  2. Moving averages smooth price fluctuations and have some predictive abilities to avoid being misled by noise.
  3. Relatively small drawdowns, maximum drawdown won't be too large.
  4. Works well across most market conditions, especially trending markets.

Risks

  1. Prone to generating false signals during range-bound markets.
  2. Moving averages have lag and may miss the optimal entry and exit points of trends.
  3. No stop loss setting may lead to large losses.
  4. Improper parameter tuning affects strategy performance.

Risks can be controlled by setting stop loss. Choosing proper parameters can improve strategy performance.

Enhancement

  1. Test different MA length combinations to find optimal parameters.
  2. Add other technical indicators for filtration and signal quality improvement.
  3. Set dynamic stop loss to control risks.
  4. Incorporate volatility metrics to optimize entries and exits.
  5. Optimize position sizing and money management.

Conclusion

In summary, the Simple Moving Average Crossover is a simple and practical trend following strategy. It identifies trend changes using the indicator properties of moving averages. The main advantages are easy implementation, understandability, and relatively small drawdowns. The main disadvantages are potential false signals, lagging nature. The strategy can be improved further through parameter optimization, stop loss setting, and combining with other indicators.

Parameters

NameDefaultWhat it controls
v_input_110Fast MA Length
v_input_230Slow MA Length
v_input_3trueStop Loss Percentage

Source Pine Script

/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Simple Moving Average Crossover", overlay=true)

// Input parameters
fastLength = input(10, title="Fast MA Length")
slowLength = input(30, title="Slow MA Length")
stopLossPercent = input(1, title="Stop Loss Percentage")

// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)

// Buy condition: Fast MA crosses above Slow MA
buyCondition = ta.crossover(fastMA, slowMA)

// Sell condition: Fast MA crosses below Slow MA
sellCondition = ta.crossunder(fastMA, slowMA)

// Plot moving averages as lines
plot(fastMA, color=color.blue, title="Fast MA", linewidth=2)
plot(slowMA, color=color.red, title="Slow MA", linewidth=2)

// Execute trades based on conditions
if (buyCondition)
    strategy.entry("Buy", strategy.long)

if (sellCondition)
    strategy.close("Buy")

// Set stop loss level
stopLossLevel = close * (1 - stopLossPercent / 100)
strategy.exit("Sell", from_entry="Buy", loss=stopLossLevel)


Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-30. 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/Simple-Moving-Average-Crossover-Strategy-440436.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