0bps

Strategy vault / Momentum

Momentum Moving Average Crossover Trading Strategy

This strategy generates trading signals based on the MACD indicator. The MACD indicator consists of three lines: the MACD line, SIGNAL line and histogram (HISTO) line. When the MACD line crosses above the SIGNAL line…

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

IMG

Overview

This strategy generates trading signals based on the MACD indicator. The MACD indicator consists of three lines: the MACD line, SIGNAL line and histogram (HISTO) line. When the MACD line crosses above the SIGNAL line and turns positive, it generates a buy signal. When the MACD line crosses below the SIGNAL line and turns negative, it generates a sell signal.

Strategy Logic

  1. Calculate the MACD line, SIGNAL line and HISTO line.
  2. Identify crossover points between the MACD line and SIGNAL line to determine buy and sell signals.
  3. Use a 34-period EMA as support/resistance zone, go long only above EMA and go short only below EMA.
  4. Set stop loss and take profit to lock in profits.

Specifically, when the close price crosses above the 34-period EMA and the MACD line crosses above the SIGNAL line into positive territory, it indicates strong upside momentum, so we buy. When the close price crosses below the 34-period EMA and the MACD line crosses below the SIGNAL line into negative territory, it indicates strong downside momentum, so we sell.

Advantages

  1. MACD indicator accurately identifies turns in price action with clear signals.
  2. Combining with EMA filter avoids false buy/sell signals.
  3. Stop loss and take profit controls per trade loss.

Risks and Solutions

  1. MACD signals lag price action and may miss best entry/exit points. Can optimize parameters to shorten moving average periods.
  2. Single indicator prone to generating false signals. Can add other indicators like KDJ for filtration.
  3. No limit on number of trades, may lead to overtrading. Can set daily/weekly trade limits.

Enhancement Opportunities

  1. Optimize MACD parameters to find best parameter combination.
  2. Add other indicator judgments to avoid false signals, e.g. MACD+KDJ, MACD+BOLL combinations.
  3. Implement trade frequency limits to prevent overtrading.
  4. Optimize stop loss/take profit strategy to improve risk/reward ratio.

Conclusion

This strategy identifies trading opportunities using the MACD indicator and filters signals using a 34-period EMA. It allows timely entries when new price trends start while controlling risk via stop loss/take profit. The strategy can be further refined via parameter optimization, adding other indicators etc. to improve profitability.

Parameters

NameDefaultWhat it controls
v_input_1trueCheck here for tendies

Source Pine Script

/*backtest
start: 2024-01-19 00:00:00
end: 2024-02-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © melihtuna

//@version=2
strategy("Jim's MACD", overlay=true)

Tendies = input(true, title="Check here for tendies")

// === MACD Setup ===
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)

//EMA
ma = ema(close, 5)
plot(ema(close,5))


//Entry
if (close > ma and cross(macdLine,signalLine) and histLine> 0.4 and signalLine > 0 or histLine > 0 and signalLine > 0 )
    strategy.entry("BUY", strategy.long)
if(close < ma and cross(macdLine,signalLine) and histLine < -0.4 and signalLine < 0 or close < ma and histLine < 0 and signalLine < 0 )
    strategy.entry("SELL", strategy.short)
    
//Exit 
strategy.close("BUY", when = histLine < 0  )
strategy.close("SELL", when = histLine > 0  )

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-19. 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/Momentum-Moving-Average-Crossover-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