0bps

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.

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

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:

  1. RSI Calculates the regular 14-period RSI.

  2. 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:

  1. Testing RSI and MACD parameter combinations

  2. Adding secondary confirmation when MACD signals

    e.g. candlestick patterns, volume, Bollinger bands etc.

  3. Optimizing stops to trailing stops

  4. Adding re-entry rules

    Re-establish positions after stops are hit if trend continues

  5. 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

NameDefaultWhat it controls
v_input_114Length
v_input_212fastLength
v_input_326slowLength
v_input_49signalLength
v_input_56monthfrom
v_input_612monthuntil
v_input_7truedayfrom
v_input_831dayuntil

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.

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/MACD-of-RSI-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