Strategy vault / Trend following
MACD of RSI Trading Strategy
This strategy uses the MACD indicator to determine the trend of the RSI indicator, generating trading signals. It belongs to the indicator combo filter strategy type.
Overview
This strategy uses the MACD indicator to determine the trend of the RSI indicator, generating trading signals. It belongs to the indicator combo filter strategy type.
Strategy Logic
The strategy is based on two main indicators:
RSI Calculates the regular 14-period RSI.
MACD of RSI Calculates MACD values on the RSI, with default fast MA 12, slow MA 26, signal line 9.
When MACD of RSI crosses up, the fast and slow MAs golden cross, it determines an uptrend and goes long.
When MACD crosses down, the fast and slow MAs dead cross, it determines a downtrend and goes short.
The exponential moving averages of MACD help determine the longer term trend of RSI itself, resulting in more accurate signals.
Advantages
- MACD judges RSI trend direction for higher accuracy
- RSI as primary indicator, MACD as secondary
- Exponential MAs make trend determination stable
- Combination verifies each other, avoiding whipsaws
- Parameter tuning provides flexibility for different markets
Risks
- Both RSI and MACD can lag, leading to inaccurate signals
- Wrong MACD parameters may generate more false signals
- Purely indicator-based, sensitive to sudden events
- Stop loss mechanism needs further improvements
- Parameter optimization required for different products
Risks can be reduced by:
- Optimizing RSI and MACD parameter combinations
- Adding other filters for confirmation
- Relaxing TP/SL to avoid premature exit
- Considering re-entries
- Position sizing to limit single loss
Enhancement Directions
The strategy can be improved from:
Testing RSI and MACD parameter combinations
Adding secondary confirmation when MACD signals
e.g. candlestick patterns, volume, Bollinger bands etc.
Optimizing stops to trailing stops
Adding re-entry rules
Re-establish positions after stops are hit if trend continues
Adjusting position sizes by volatility
Smaller size during high volatility, larger size in low volatility
Summary
This strategy combines RSI and MACD indicators to verify each other for more accurate and stable trend detection. But parameters need optimization, and additional technical filters or trading rules are required for confirmation, avoiding sudden events. Also stop loss mechanisms and dynamic position sizing are important. Continued learning and optimizing is crucial for adapting to changing market conditions for steady profits.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | 12 | fastLength |
| v_input_3 | 26 | slowLength |
| v_input_4 | 9 | signalLength |
| v_input_5 | 6 | monthfrom |
| v_input_6 | 12 | monthuntil |
| v_input_7 | true | dayfrom |
| v_input_8 | 31 | dayuntil |
Source Pine Script
/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title = "MACD of RSI", overlay = false)
//////////////////////// RSI ///////////////////////////
src = close, len = input(14, minval=1, title="Length")
up = sma(max(change(src), 0), len)
down = sma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
//////////////////////// RSI //////////////////////////
//////////////// MACD ////////////////////////////
sourcemacd = rsi
fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)
fastMA = ema(sourcemacd, fastLength)
slowMA = ema(sourcemacd, slowLength)
macd = fastMA - slowMA
signal = ema(macd, signalLength)
delta=macd-signal
swap1 = delta>0?green:red
plot(delta,color=swap1,style=columns,title='Histo',histbase=0,transp=20)
p1 = plot(macd,color=blue,title='MACD Line')
p2 = plot(signal,color=red,title='Signal')
fill(p1, p2, color=blue)
hline(0)
/////////////////////////MACD //////////////////////////
// Conditions
longCond = na
sellCond = na
longCond := crossover(delta,0)
sellCond := crossunder(delta,0)
monthfrom =input(6)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)
if ( longCond )
strategy.entry("BUY", strategy.long, stop=close, oca_name="TREND", comment="BUY")
else
strategy.cancel(id="BUY")
if ( sellCond )
strategy.close("BUY")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-21. 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/MACD-of-RSI-Trading-Strategy.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
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- EMA and RSI Trend Trading StrategyPine Script · Trend following · 1d
- Multi Indicator Trend Following Strategy with Dynamic Risk ManagementPine Script · Trend following · 2h
- Dynamic Moving Average Trend Crossover StrategyPine Script · Trend following · 1d
- Multi Technical Indicator Moving Average Crossover Trend Following Quantitative Trading StrategyPine Script · Trend following · 1h
- Moving Vegas Channel Crossover StrategyPine Script · Trend following · 1d