0bps

Strategy vault / Arbitrage

Comparative Relative Strength Strategy

The comparative relative strength strategy generates trades by comparing the relative strength of two markets. Outperformance of the comparison market versus the benchmark is seen as a buy signal, underperformance as…

Author
ChaoZhang
Complexity
Starter · 46 lines
Parameters
6
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

Strategy Logic

The comparative relative strength strategy generates trades by comparing the relative strength of two markets. Outperformance of the comparison market versus the benchmark is seen as a buy signal, underperformance as a sell signal.

The logic is:

  1. Select comparison market, e.g. a stock

  2. Select benchmark market, e.g. S&P 500 index

  3. Compute ratio of comparison market vs benchmark

  4. Go long the comparison when ratio exceeds overbought level

  5. Go short when ratio falls below oversold zone

  6. Set pullback line to close positions when price falls back

By comparing relative strength, the strategy aims to uncover undervalued opportunities and avoid overvalued conditions.

Advantages

  • Compares relative strength to find undervaluation

  • Pullback line avoids chasing trends

  • Simple and clear rules

Risks

  • Appropriate benchmark needs selection

  • Overbought/oversold zones require optimization

  • LONG/SHORT only misses full opportunities

Summary

The relative strength strategy identifies arbitrage chances by comparing two markets. But parameter tuning and stop strategies require prudent assessment.

Parameters

NameDefaultWhat it controls
v_input_1BTC_USDT:swapb
v_input_210len
v_input_30.9988BuyBand
v_input_40.996SellBand
v_input_50.9975CloseBand
v_input_6falseTrade reverse

Source Pine Script

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

//@version=2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 10/03/2017
// Comparative Relative Strength Strategy for ES
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy("Comparative Relative Strength Strategy", shorttitle="CRS")
a = syminfo.tickerid 
b = input("BTC_USDT:swap") 
len = input(10) 
BuyBand = input(0.9988, step = 0.0001)
SellBand = input(0.9960, step = 0.0001)
CloseBand = input(0.9975, step = 0.0001)
reverse = input(false, title="Trade reverse")
hline(CloseBand, color=blue, linestyle=hline.style_dashed)
hline(SellBand, color=red, linestyle=hline.style_solid)
hline(BuyBand, color=green, linestyle=hline.style_solid)
as = security(a, timeframe.period, close) 
bs = security(b, timeframe.period, close) 
nRes = sma(as/bs, len)
pos = iff(nRes > BuyBand, 1,
	     iff(nRes < SellBand, -1,
	      iff(pos[1] == 1 and nRes < CloseBand, 0,
	       iff(pos[1] == -1 and nRes > CloseBand, 0, nz(pos[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("Long", when = possig == 0)	 
    strategy.close("Short", when = possig == 0)	 
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(as/bs, title="CRS", color=gray) 
plot(nRes, color=navy)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. 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 spread arbitrage engine with WebSocket order routing and leg-risk controls from strategies/Comparative-Relative-Strength-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