0bps

Strategy vault / Trend following

Moving Average Aggregation MACD Strategy

This strategy combines 5 different types of moving averages, and generates trading signals when the directions of all 5 moving averages are consistent. The aggregation of multiple moving averages can effectively…

Author
ChaoZhang
Complexity
Starter · 42 lines
Parameters
2

IMG

Overview

This strategy combines 5 different types of moving averages, and generates trading signals when the directions of all 5 moving averages are consistent. The aggregation of multiple moving averages can effectively filter market noise and identify trend direction.

Strategy Logic

This strategy uses SMA, EMA, RMA, WMA and VWMA five kinds of moving averages. It calculates five 8-day fast MAs and five 144-day slow MAs. When all fast MAs are rising and all slow MAs are rising, it generates a long signal. When all fast MAs are falling and all slow MAs are falling, it generates a short signal.

Advantage Analysis

  • Aggregating multiple moving averages makes signals more reliable and avoids false signals
  • Utilizes advantages of different MAs, like SMA smooths price, VWMA considers volume, WMA assigns weights, etc
  • Parameters are adjustable for optimizing fast and slow MA lengths

Risk Analysis

  • When one or two out of the aggregated MAs generate false signals, it also affects the strategy
  • Cannot generate timely signals when trend starts
  • Parameter optimization is needed to find optimum parameters

Optimization Directions

  • Can test different MA combinations and parameters
  • Can combine with other indicators for confirmation, like MACD, RSI, etc
  • Can dynamically adjust MA parameters based on market conditions

Summary

This strategy generates trading signals when all major moving averages reach consensus on direction. It effectively utilizes strengths of different MAs while filtering some noise to identify market trend direction. Further enhancements like parameter optimization and indicator combos can improve strategy stability. Overall a simple and practical trend following strategy.

Parameters

NameDefaultWhat it controls
v_input_18FAST LOOKBACK
v_input_2144SLOW LOOKBACK

Source Pine Script

//@version=2
strategy(title="MACD Multi-MA Strategy", overlay=false )

src = close 
len1 = input(8, "FAST LOOKBACK") 
len2 = input(144, "SLOW LOOKBACK")

/////////////////////////////////////////////
length = len2-len1
ma = vwma(src, length)
plot(ma, title="VWMA", color=lime)


length1 = len2-len1
ma1 = rma(src, length1)
plot(ma1, title="RMA", color=purple)

length2 = len2-len1
ma2 = sma(src, length2)
plot(ma2, title="SMA", color=red)


length3 = len2-len1
ma3 = wma(src, length3)
plot(ma3, title="WMA", color=orange)

length4 = len2-len1
ma4 = ema(src, length4)
plot(ma4, title="EMA", color=yellow)





long = ma > ma[1] and ma1 > ma1[1] and ma2 > ma2[1] and ma3 > ma3[1] and ma4 > ma4[1]
short = ma < ma[1] and ma1 < ma1[1] and ma2 < ma2[1] and ma3 < ma3[1] and ma4 < ma4[1]


strategy.entry("Long", strategy.long, when=long)
strategy.entry("Short", strategy.short, when=short)

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