0bps

Strategy vault / Mean reversion

Trading Strategy for Oscillating Markets Combining MACD and RSI Indicators

This strategy is named "Trading Strategy for Oscillating Markets Combining MACD and RSI Indicators". It is designed specifically for the recent oscillating and ranging crypto markets, generating trade signals by…

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

This strategy is named "Trading Strategy for Oscillating Markets Combining MACD and RSI Indicators". It is designed specifically for the recent oscillating and ranging crypto markets, generating trade signals by integrating the trend indicator MACD and the momentum oscillator RSI.

MACD is the moving average convergence divergence indicator, judging market trend and reversals. MACD crossover with the fast line crossing above the slow line generates buy signals, while crossover below generates sell signals.

RSI is the relative strength index, gauging overbought and oversold conditions. RSI above 50 suggests overbought state, while below 50 is oversold. This strategy uses RSI to filter some noisy signals from MACD.

The trading logic is as follows:

When MACD crossover happens with the fast line crossing above the slow line, it indicates the short-term trend is changing from down to up, but a buy signal is only confirmed when RSI is at low levels (below preset parameter) to avoid whipsaws in overbought zones.

When MACD crossover happens with the fast line crossing below the slow line, it flags the short-term trend reversing from up to down, but a sell signal is only confirmed when RSI reaches high levels (above preset parameter) to avoid whipsaws in oversold zones.

This strategy suits the current oscillating and ranging crypto markets to capture reversal opportunities at highs and lows for profits. But stop loss should be applied to limit single trade loss. Also, MACD and RSI parameters need market-adjusted optimization for reliable signals.

In conclusion, combining MACD and RSI can improve strategy effectiveness for oscillating markets. But no indicators can perfectly predict markets. Traders still need sound market trend judgment and flexible strategy adjustment.

Parameters

NameDefaultWhat it controls
v_input_113Start Date
v_input_26Start Month
v_input_32022Start Year
v_input_4trueEnd Date
v_input_57End Month
v_input_62200End Year
v_input_714length
v_input_855overSold
v_input_950overBought
v_input_1012fastLength
v_input_1126slowlength
v_input_129MACDLength

Source Pine Script

/*backtest
start: 2022-09-06 00:00:00
end: 2023-03-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Range Strat - MACD/RSI", 
     overlay=true,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=100, precision=2, initial_capital=100,
     pyramiding=2,
     commission_value=0.05)

// Make input options that configure backtest date range
startDate = input(title="Start Date", defval=13)
startMonth = input(title="Start Month", defval=6)
startYear = input(title="Start Year", defval=2022)

endDate = input(title="End Date", defval=1)
endMonth = input(title="End Month", defval=7)
endYear = input(title="End Year", defval=2200)

// Look if the close time of the current bar
// falls inside the date range
inDateRange = (time >= timestamp(syminfo.timezone, startYear,
         startMonth, startDate, 0, 0)) and
     (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))

// RSI Settings
length = input( 14 )
overSold = input( 55 )
overBought = input( 50 )
price = open
vrsi = ta.rsi(price, length)
cu = (vrsi <= overSold)
co = (vrsi >= overBought)

//MACD Settings
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(open, fastLength) - ta.ema(open, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
MACDco = ta.crossover(delta, 0)
MACDcu = ta.crossunder(delta, 0)

// Strategy Entry
if (not na(vrsi))
	if (inDateRange and MACDco and cu)
		strategy.entry("LONG", strategy.long, comment="LONG")
	if (inDateRange and MACDcu and co)
		strategy.entry("SHORT", strategy.short, comment="SHORT")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-13. 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/Trading-Strategy-for-Oscillating-Markets-Combining-MACD-and-RSI-Indicators.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