Strategy · Pine Script v5 · Own pane

RSI Divergence Strategy - Eterna MCP

by EternaHybridExchange

This strategy calculates the Relative Strength Index (RSI) and identifies bullish and bearish divergences using RSI and price pivot points.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code84
Settings6inputs
LicenceMIT
Last update7 months ago12 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

84 lines of Pine Script v5 from strategies/momentum/rsi_divergence.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

rsi_divergence.pine
//@version=5
strategy("RSI Divergence Strategy - Eterna MCP", 
         shorttitle="RSI Div",
         overlay=false,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         initial_capital=1000)

// ============================================
// PARAMETERS
// ============================================
rsiLength = input.int(14, "RSI Length", minval=1)
rsiOverbought = input.int(70, "RSI Overbought", minval=50, maxval=100)
rsiOversold = input.int(30, "RSI Oversold", minval=0, maxval=50)
pivotLookback = input.int(5, "Pivot Lookback", minval=1)
leverageSize = input.float(5.0, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, maxval=1)

// ============================================
// RSI CALCULATION
// ============================================
rsi = ta.rsi(close, rsiLength)

// ============================================
// DIVERGENCE DETECTION
// ============================================
// Pivot highs and lows
pivotHigh = ta.pivothigh(rsi, pivotLookback, pivotLookback)
pivotLow = ta.pivotlow(rsi, pivotLookback, pivotLookback)
pricePivotHigh = ta.pivothigh(high, pivotLookback, pivotLookback)
pricePivotLow = ta.pivotlow(low, pivotLookback, pivotLookback)

// Store pivot points
var float lastRsiHigh = na
var float lastPriceHigh = na
var float lastRsiLow = na
var float lastPriceLow = na

if not na(pivotHigh)
    lastRsiHigh := pivotHigh
    lastPriceHigh := pricePivotHigh

if not na(pivotLow)
    lastRsiLow := pivotLow
    lastPriceLow := pricePivotLow

// Bullish divergence: price makes lower low, RSI makes higher low
bullishDiv = not na(lastRsiLow) and not na(lastPriceLow) and 
             low < lastPriceLow and rsi > lastRsiLow and 
             rsi < rsiOversold

// Bearish divergence: price makes higher high, RSI makes lower high
bearishDiv = not na(lastRsiHigh) and not na(lastPriceHigh) and 
             high > lastPriceHigh and rsi < lastRsiHigh and 
             rsi > rsiOverbought

// ============================================
// STRATEGY LOGIC
// ============================================
if bullishDiv and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    alert('{"action":"buy","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

if bearishDiv and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    alert('{"action":"sell","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

// Exit on opposite signal
if bearishDiv and strategy.position_size > 0
    strategy.close("Long")

if bullishDiv and strategy.position_size < 0
    strategy.close("Short")

// ============================================
// PLOTTING
// ============================================
plot(rsi, "RSI", color=color.blue, linewidth=2)
hline(rsiOverbought, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(rsiOversold, "Oversold", color=color.green, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)

plotshape(bullishDiv, "Bullish Divergence", shape.triangleup, location.bottom, color.green, size=size.small)
plotshape(bearishDiv, "Bearish Divergence", shape.triangledown, location.top, color.red, size=size.small)

Overview

RSI Divergence Strategy - Eterna MCP plots the RSI oscillator, overbought and oversold threshold lines, and divergence markers in a separate pane. A long position enters when a bullish divergence forms in oversold conditions, while a short position enters on a bearish divergence in overbought conditions. Exits occur when an opposing divergence signal appears. Key settings allow adjustment of RSI parameters, pivot lookback periods, leverage, and position size for automated webhook alerts. The strategy lacks a stop loss.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint14rsiLength
RSI Overboughtint70rsiOverbought
RSI Oversoldint30rsiOversold
Pivot Lookbackint5pivotLookback
Leveragefloat5.0leverageSize
Position Sizefloat0.01positionSize
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]
11 stars

The Stochastic Divergence Strategy calculates the Stochastic oscillator (%K and %D) to identify regular bullish and bearish divergence patterns against price pivots. It plots the oscillator and divergence lines in a separate indicator pane. Entries trigger on

Strategy v6 Oscillators & momentumDivergence
Updated 5 months ago · Apache-2.0 GitHub repository of Stochastic Divergence Strategy

This strategy calculates regular and hidden divergences across selectable momentum oscillators, including RSI, CCI, and MFI, and plots volatility-based divergence zones. It displays oscillator dynamics in a separate pane while projecting support and resistance

Strategy v6 DivergenceOscillators & momentum
Updated yesterday · MIT GitHub repository of Oscillator Divergence Zones [WavesUnchained] — Strategy

ETH_buy_3commas

by hasnocool
106 stars

This strategy overlays a Cipher B style WaveTrend study on the price chart and is titled for Ethereum buy alerts aimed at 3Commas. It calculates a WaveTrend channel and a short moving average, and can mark buy, sell, gold, and divergence dots. Settings change

Strategy v4 Oscillators & momentumDivergence
Updated 2 years ago · GPL-3.0 GitHub repository of ETH_buy_3commas
24 stars

This overlay strategy combines a Cipher B WaveTrend oscillator with two optional moving averages on the price chart. It exposes WaveTrend channel and average lengths, overbought and oversold levels, buy, sell and gold dots, and regular or hidden divergence mar

Strategy v5 Oscillators & momentumMoving averages
Updated 4 years ago · MPL-2.0 GitHub repository of Cipher B + EMAs Strategy

Divergenced A002

by ruckard
13 stars

Divergenced A002 is a momentum divergence strategy designed to identify entry opportunities using Squeeze Momentum Indicator shifts alongside price action. It enters long when momentum reaches higher lows during lower price lows and enters short on opposite di

Strategy v5 Oscillators & momentumDivergence
Updated 1 year ago · None stated GitHub repository of Divergenced A002

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers