Indicators

Get Relative strength indicator Code That Actually Works

Describe your idea → AI generates code → built-in compiler fixes errors → one-click copy. Working relative strength indicator in under 30 seconds.

4.9/5 Rating
10,000+ Traders
Free Forever Plan

The Problem

You've spotted a killer relative strength indicator setup in a forum or YouTube video that compares asset performance to a benchmark, but the shared Pine Script is buggy and throws endless errors when you paste it into TradingView. Or worse, you're trying to code it yourself from scratch, wrestling with RSI calculations, relative price ratios, and plot functions that just won't compile. Hours wasted, no working indicator, and your edge slips away.

The Solution

With HorizonAI's chat interface, just type 'Create a relative strength indicator comparing SPY to QQQ with overbought/oversold alerts' and get working Pine Script in 30 seconds. Our built-in compiler auto-checks and fixes every error before delivery, so you always get flawless code. One-click copy, paste into TradingView—your relative strength indicator is live and trading-ready instantly.

Why Traders Choose HorizonAI for Relative strength indicator

Everything you need to build trading tools without writing a single line of code

Guaranteed Working Code

Built-in compiler auto-detects and fixes errors on the fly—5,000+ traders have generated 20,000+ error-free scripts. No more cryptic Pine Script bugs killing your relative strength indicator.

30-Second Generation

Describe your relative strength indicator, hit send—working code arrives instantly. Skip days waiting for freelancers or weeks learning syntax.

Endless Customization

Chat back and forth: tweak lengths, add divergences, refine signals. Iterate until your relative strength indicator matches your exact strategy.

RSI vs Benchmark Power

Build relative strength indicators that plot asset performance against indexes like SPY, with clear buy/sell signals and alerts for outperformance edges.

How It Works

From idea to working code in three simple steps

1

Describe It

Tell the AI exactly what you want your relative strength indicator to do. Plain English, no code knowledge needed.

2

Generate & Fix

AI writes the code and auto-compiles it. Any errors are fixed automatically before you see it.

3

Copy & Trade

One-click copy. Paste into TradingView or MT5. Your relative strength indicator is live in under a minute.

Try It Now — It's Free

See What You'll Get

Real, production-ready code generated by HorizonAI — ready to copy and use

Relative strength indicator — Pine Script

This Relative Strength Indicator plots RSI alongside normalized relative performance vs a benchmark like SPY, with overbought/oversold alerts and backgrounds—expect clear signals for outperformance trades without a single error.

Pine Script
//@version=5
indicator(title="Relative Strength Indicator", shorttitle="RSI Relative", overlay=false, timeframe="", timeframe_gaps=true)

// Input parameters
rsi_length = input.int(14, title="RSI Length", minval=1)
rs_length = input.int(20, title="Relative Strength MA Length", minval=1)
benchmark = input.symbol("SPY", title="Benchmark Symbol")
overbought = input.int(70, title="Overbought Level", minval=50, maxval=100)
oversold = input.int(30, title="Oversold Level", minval=0, maxval=50)
show_background = input.bool(true, title="Show Background Colors")

// Fetch benchmark data
bench_close = request.security(benchmark, timeframe.period, close)

// Calculate RSI for current symbol
src = close
change = ta.change(src)
gain = math.max(change, 0)
loss = math.max(-change, 0)
avg_gain = ta.rma(gain, rsi_length)
avg_loss = ta.rma(loss, rsi_length)
rs = avg_gain / avg_loss
rsi = 100 - (100 / (1 + rs))

// Calculate Relative Strength: current vs benchmark
rel_strength = src / bench_close
rs_ma = ta.sma(rel_strength, rs_length)

// Normalize RS to RSI scale for comparison
rs_normalized = 100 * (rs_ma - ta.lowest(rs_ma, 100)) / (ta.highest(rs_ma, 100) - ta.lowest(rs_ma, 100))

// Plots
plot(rsi, title="RSI", color=color.blue, linewidth=2)
plot(rs_normalized, title="Relative Strength", color=color.orange, linewidth=2)

// Overbought/Oversold lines
hline(overbought, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversold, "Oversold", color=color.green, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)

// Background colors
bgcolor(show_background and rsi > overbought ? color.new(color.red, 90) : na, title="OB BG")
bgcolor(show_background and rsi < oversold ? color.new(color.green, 90) : na, title="OS BG")

// Alerts
rsi_ob = ta.crossover(rsi, overbought)
rsi_os = ta.crossunder(rsi, oversold)
rs_ob = ta.crossover(rs_normalized, overbought)
rs_os = ta.crossunder(rs_normalized, oversold)

alertcondition(rsi_ob or rs_ob, title="Overbought Alert", message="Relative Strength Indicator: Overbought signal on {{ticker}} vs {{benchmark}}")
alertcondition(rsi_os or rs_os, title="Oversold Alert", message="Relative Strength Indicator: Oversold signal on {{ticker}} vs {{benchmark}}")

// Table for info
if barstate.islast
    var table info_table = table.new(position.top_right, 2, 4, bgcolor=color.white, border_width=1)
    table.cell(info_table, 0, 0, "RSI", text_color=color.black)
    table.cell(info_table, 1, 0, str.tostring(rsi, "#.##"), text_color=color.blue)
    table.cell(info_table, 0, 1, "Rel Str", text_color=color.black)
    table.cell(info_table, 1, 1, str.tostring(rs_normalized, "#.##"), text_color=color.orange)
    table.cell(info_table, 0, 2, "Benchmark", text_color=color.black)
    table.cell(info_table, 1, 2, benchmark, text_color=color.gray)

This is just one example. Generate any indicator or strategy you can imagine.

Generate Your Own Code
"I kept getting Pine Script errors trying to code a relative strength indicator vs SPY from some TradingView script I found—total frustration. Typed my idea into HorizonAI, got perfect code in 20 seconds with the compiler fixing everything, and now I get phone alerts whenever my stock outperforms. Game-changer for my scans."
T
Verified Trader
HorizonAI User
10K+
Traders
50K+
Scripts Generated
30s
Avg Generation
Free
To Start

Frequently Asked Questions

Everything you need to know to get started

Will the relative strength indicator code actually work?

Absolutely—our built-in compiler auto-checks and fixes every error before you get the code, delivering 100% working scripts. Over 5,000 traders have generated 20,000+ flawless Pine Scripts. Paste it in TradingView and watch your relative strength indicator run perfectly.

How is this different from asking ChatGPT?

HorizonAI is trained specifically on Pine Script docs and trading strategies, so it nails relative strength logic without hallucinations. ChatGPT spits out broken code full of syntax errors—ours has an auto-compiler that fixes issues instantly. Traders switch because they finally get working relative strength indicators.

Can I customize the relative strength indicator after generating it?

Yes, it's a full chat conversation—ask to add divergence detection, change the benchmark to QQQ, or tweak alerts on the fly. Iterate as many times as needed until your relative strength indicator is perfect. No starting over, just refine in seconds.

How long does it take to get my relative strength indicator code?

Under 30 seconds from description to working code. Type your relative strength idea, AI generates and compiles it, one-click copy to TradingView. Beats learning Pine Script (weeks) or hiring freelancers (days)—instant edge for busy traders.

Is HorizonAI free?

Yes—you can start generating code right now for free, no credit card required. The free tier gives you access to the AI chat, code generation, and the auto-compiler. Over 5,000 traders are already using it.

Ready to Build Your Trading Tools?

Join thousands of traders who use HorizonAI to create custom indicators and strategies without coding. Start free today.

Start Building — It's Free

No credit card required. Free forever plan available.

Related Guides