Strategy vault / Mean reversion
Combo Trading Strategy Based on 123 Reversal and MACD
This strategy combines 123 reversal patterns and MACD indicators to generate stronger trade signals through filtering. 123 reversals capture short-term reversal opportunities while MACD provides mid-long term trend…
Overview
This strategy combines 123 reversal patterns and MACD indicators to generate stronger trade signals through filtering. 123 reversals capture short-term reversal opportunities while MACD provides mid-long term trend guidance. The combo signal can effectively discover high probability trade setups.
Strategy Logic
123 reversal strategy buys when the last two days were down days and today's close is up, with Stochastic below threshold; sells when last two days were up days and today is down, with Stochastic above threshold.
MACD strategy goes long when fast MA is above slow MA, and short when fast MA is below slow MA.
Trades are taken only when both strategies agree, otherwise no action is taken. Trade direction can be switched.
Advantage Analysis
Main advantages:
Combo signal effectively filters false breakouts, improving win rate.
123 captures short-term reversals, MACD judges mid-long term trend direction.
Stochastic with 123 avoids over-trading after trend reversal.
Two strategies share different tasks, mutually validating, avoiding over-optimization.
Easily switch between long/short, adaptable to various market environments.
Risk Analysis
Main risks:
Combo signal may be too conservative, missing good opportunities.
Reversals are susceptible to sudden events, prone to failure.
Lack of stop loss exposes strategy to large losses.
Double filtering may cause missing trend trades.
Lack of parameter optimization, default values may not fit all instruments.
Optimization Directions
Improvements:
Test different parameter combinations to find optimal values.
Add stop loss to control loss per trade.
Incorporate more filter indicators to improve signal quality.
Introduce machine learning models for automatic parameter optimization.
Test across more trading instruments to evaluate robustness.
Switch parameter sets based on market conditions.
Summary
Overall, combining dual signals avoids over-optimization compared to single strategies. With additions like more filters, stop losses and so on, it can become a robust and practical quantitative trading strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | true | KSmoothing |
| v_input_3 | 3 | DLength |
| v_input_4 | 50 | Level |
| v_input_5 | 14 | r |
| v_input_6 | 21 | LengthMACD |
| v_input_7 | 5 | SmthLen |
| v_input_8 | false | Trade reverse |
Source Pine Script
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-14 02:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 24/07/2020
// This is combo strategies for get a cumulative signal.
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
// The strategy sells at market, if close price is lower than the previous close price
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// This is one of the techniques described by William Blau in his book
// "Momentum, Direction and Divergence" (1995). If you like to learn more,
// we advise you to read this book. His book focuses on three key aspects
// of trading: momentum, direction and divergence. Blau, who was an electrical
// engineer before becoming a trader, thoroughly examines the relationship
// between price and momentum in step-by-step examples. From this grounding,
// he then looks at the deficiencies in other oscillators and introduces some
// innovative techniques, including a fresh twist on Stochastics. On directional
// issues, he analyzes the intricacies of ADX and offers a unique approach to help
// define trending and non-trending periods.
// Blau`s indicator is like usual MACD, but it plots opposite of meaningof
// stndard MACD indicator.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
vFast = sma(stoch(close, high, low, Length), KSmoothing)
vSlow = sma(vFast, DLength)
pos = 0.0
pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0)))
pos
fADX(Len) =>
up = change(high)
down = -change(low)
trur = rma(tr, Len)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, Len) / trur)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, Len) / trur)
sum = plus + minus
100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), Len)
EMACD(r,SmthLen,LengthMACD) =>
pos = 0
source = close
fastMA = ema(source, r)
slowMA = ema(source, LengthMACD)
xmacd = fastMA - slowMA
xMA_MACD = ema(xmacd, SmthLen)
pos := iff(xmacd < xMA_MACD, -1,
iff(xmacd > xMA_MACD, 1, nz(pos[1], 0)))
pos
strategy(title="Combo Backtest 123 Reversal & Ergodic MACD", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
r = input(14, minval=1)
LengthMACD = input(21, minval=1)
SmthLen = input(5, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posEMACD = EMACD(r,SmthLen,LengthMACD)
pos = iff(posReversal123 == 1 and posEMACD == 1 , 1,
iff(posReversal123 == -1 and posEMACD == -1, -1, 0))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1 , 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
if (possig == 0)
strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Combo-Trading-Strategy-Based-on-123-Reversal-and-MACD.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Dual Indicator Slight Reversal Trading StrategyPine Script · Mean reversion · 15m
- Intraday Single Candle Indicator Combo Short Term Trading StrategyPine Script · Mean reversion · 1d
- 15 MIN BTCUSDTPERP BOTPine Script · Mean reversion · 45m
- Hourly Fluctuation Trading StrategyPine Script · Mean reversion
- Multi factor Quantitative Trading Strategy 440526Pine Script · Mean reversion · 4h
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h