0bps

Strategy vault / Mean reversion

Double Moving Average Reversal Strategy 435968

This is a trend following and reversal trading strategy based on simple moving averages. It uses the crossover of 1-day and 4-day moving averages to determine the trend direction and generate buy and sell signals.

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

IMG

Overview

This is a trend following and reversal trading strategy based on simple moving averages. It uses the crossover of 1-day and 4-day moving averages to determine the trend direction and generate buy and sell signals.

Strategy Logic

When the 1-day MA crosses below the 4-day MA, a sell signal is generated. When the 1-day MA crosses above the 4-day MA, a buy signal is generated. By using the crossover of a fast and slow moving average to identify trend reversal points, it aims to profit.

After entering the market, stop loss and take profit points are set. The stop loss is set 10 points below the entry price. The take profit is set 100 points above the entry price. This can limit losses and lock in profits.

Advantage Analysis

  • Uses double MAs to identify reversal points simply and practially
  • Sets stop loss and take profit to limit risk
  • adjustable parameters adaptable to different market conditions
  • easy to understand and implement, suitable for beginners

Risk Analysis

  • Invalid MA parameters may cause overtrading or missing opportunities
  • Improper stop loss and take profit setting may cause premature exit
  • The lagging of double MAs identifying reversals may cause losses
  • Poor performance if parameters are not adjusted per market changes

Risks can be mitigated by tuning parameters, setting dynamic stops, incorporating other indicators for signal validation etc.

Optimization Directions

  • Adding MACD, KD to filter fake signals
  • Studying the effect of different MA periods
  • Adding trend filter to avoid counter-trend trades
  • Using proportional stops instead of fixed values
  • Dynamically adjusting parameters by volatility

Summary

This is a typical double MA reversal strategy overall. It identifies reversals by fast and slow MA crossovers, controls risk with stops, simple and practical to understand for beginners. With parameter tuning and optimizations, it can be adaptive and adding filters can improve it further. It is a very good starter strategy to learn.

Source Pine Script

/*backtest
start: 2023-11-19 00:00:00
end: 2023-12-19 00:00:00
period: 1h
basePeriod: 15m
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/
// © cesarpieres72

//@version=5
strategy("300% STRATEGY", overlay=true, margin_long=10, margin_short=10)
 
var float lastLongOrderPrice = na
var float lastShortOrderPrice = na

longCondition = ta.crossover(ta.sma(close, 1), ta.sma(close, 4))
if (longCondition)
    strategy.entry("Long Entry", strategy.long)  // Enter long

shortCondition = ta.crossunder(ta.sma(close, 1), ta.sma(close, 4))
if (shortCondition)
    strategy.entry("Short Entry", strategy.short)  // Enter short

if (longCondition)
    lastLongOrderPrice := close

if (shortCondition)
    lastShortOrderPrice := close

// Calculate stop loss and take profit based on the last executed order's price
stopLossLong = lastLongOrderPrice - 170  // 10 USDT lower than the last long order price
takeProfitLong = lastLongOrderPrice + 150  // 100 USDT higher than the last long order price
stopLossShort = lastShortOrderPrice + 170  // 10 USDT higher than the last short order price
takeProfitShort = lastShortOrderPrice - 150  // 100 USDT lower than the last short order price

// Apply stop loss and take profit to long positions
strategy.exit("Long Exit", from_entry="Long Entry", stop=stopLossLong, limit=takeProfitLong)

// Apply stop loss and take profit to short positions
strategy.exit("Short Exit", from_entry="Short Entry", stop=stopLossShort, limit=takeProfitShort) 

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-20. 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/Double-Moving-Average-Reversal-Strategy-435968.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