0bps

Strategy vault / Breakout

Momentum Breakout Moving Average Trading Strategy

This strategy generates trading signals for low volatility stocks by combining moving averages, MACD indicator and candlestick patterns. It can print buy or sell signals to alert when certain conditions are met. I…

Author
ChaoZhang
Complexity
Intermediate · 63 lines
Parameters
9
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy generates trading signals for low volatility stocks by combining moving averages, MACD indicator and candlestick patterns. It can print buy or sell signals to alert when certain conditions are met. I use it as a time saver to help identify which charts to look at. You can adjust the inputs and settings to suit your needs. I would suggest allowing two or three orders.

Strategy Logic

The strategy mainly uses three indicators for trade signal judgment:

  1. Moving Averages: Calculates three moving averages - fast, slow and baseline, and generates buy signal when fast line crosses above slow line.

  2. MACD Indicator: Calculates MACD histogram and signal line, generates buy signal when MACD histogram crosses above 0.

  3. Candlestick Patterns: Calculates the percentage increase within a single candle, generates buy signal when increase exceeds a certain percentage, judging it as mark up by market makers.

For sell signals, the strategy sets a stop loss level and take profit level. It generates sell signal when price reaches stop loss level and take profit level.

Advantages

  1. Combines three different types of technical indicators for mutual verification and avoids false signals.

  2. Good liquidity, suitable for low volatility stocks. Moving averages identify mid-long term trends, MACD captures short term momentum, candlesticks identify market maker behaviors.

  3. Sets stop loss and take profit conditions to lock in profits and prevent enlarged losses.

  4. Simple and clear logic, easy to implement. Intuitive adjustable parameters, flexible adaptation to different market conditions.

  5. Indicator parameters are optimized and tested for stability and profitability.

Risks

  1. As a trend following strategy, ineffective in range-bound choppy markets, may produce frequent small gains/losses.

  2. Candlestick patterns are subjective, difficult to accurately judge market maker behaviors, may generate some false signals.

  3. Stop loss and take profit need to be adjusted for different stocks, too small may stop loss prematurely, too large may limit profits.

  4. The strategy is relatively complex and needs to consider multiple indicators simultaneously, requiring high technical skills from traders. Parameters need continuous tracking and optimization.

Enhancement Directions

  1. Add market condition judgment, follow trends in obvious trending phases, avoid trading during consolidations. Can add ATR etc. to assist.

  2. Optimize moving average parameters, adjust periods to fit the stock's characteristics. Experiment with different moving average types.

  3. Introduce machine learning to model market maker behaviors, reduce false signals.

  4. Develop dynamic stop loss and take profit strategies, instead of fixed settings.

  5. Simplify the strategy by removing highly subjective indicators to reduce false signals. Can also consider averaging same type indicators to get more stable results.

Conclusion

This strategy integrates moving averages, MACD and market maker behavior judgment into a relatively complete low risk stock trading strategy. It has certain advantages but also some aspects that can be improved. Although complex, the technical requirement is not too demanding for traders. With continuous optimization and testing, this strategy can become a very practical quantitative trading tool. It provides a reference solution for short-mid term trading of low volatility stocks.

Parameters

NameDefaultWhat it controls
v_input_112fastLength
v_input_226slowLength
v_input_3100baseLength
v_input_49MACDLength
v_input_512MACDfast
v_input_626MACDslow
v_input_76Gain %
v_input_82Stop Loss %
v_input_96Profit %

Source Pine Script

/*backtest
start: 2022-10-25 00:00:00
end: 2023-10-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Simple Stock Strategy", overlay=true)

//Simple Trading Strategy for Stocks//
// by @ShanghaiCrypto //

////SMA////
fastLength = input(12)
slowLength = input(26)
baseLength = input(100)
price = close

mafast = sma(price, fastLength)
maslow = sma(price, slowLength)
mabase = sma(price, baseLength)

///MACD////
MACDLength = input(9)
MACDfast = input(12)
MACDslow = input(26)
MACD = ema(close, MACDfast) - ema(close, MACDslow)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD

////PUMP////
OneCandleIncrease = input(6, title='Gain %')
pump = OneCandleIncrease/100

////Profit Capture and Stop Loss//////
stop = input(2.0, title='Stop Loss %', type=float)/100
profit = input(6.0, title='Profit %', type=float)/100
stop_level = strategy.position_avg_price * (1 - stop)
take_level = strategy.position_avg_price * (1 + profit)

////Entries/////
if crossover(mafast, maslow)
    strategy.entry("Cross", strategy.long, comment="BUY")

if (crossover(delta, 0))
    strategy.entry("MACD", strategy.long, comment="BUY")
    
if close > (open + open*pump)
    strategy.entry("Pump", strategy.long, comment="BUY")

/////Exits/////
strategy.exit("SELL","Cross", stop=stop_level, limit=take_level)
strategy.exit("SELL","MACD", stop=stop_level, limit=take_level)
strategy.exit("SELL","Pump", stop=stop_level, limit=take_level)

////Plots////
plot(mafast, color=green)
plot(maslow, color=red)
plot(mabase, color=yellow)
plot(take_level, color=blue)
plot(stop_level, color=orange)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-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/Momentum-Breakout-Moving-Average-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