Strategy · Pine Script v6 · On the chart

MTF RSI Confluence

by shubhamtaywade82

A strategy that scores RSI across four timeframes, with weights falling from the chart timeframe to the 4-hour, and adds or subtracts points for RSI divergence at recent pivots.

View on GitHub

Archived by its author

GitHub stars1on the repository
Pine versionv6current
Lines of code79
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago31 May 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

79 lines of Pine Script v6 from strategies/agent-examples/mtf-rsi-confluence-strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mtf-rsi-confluence-strategy.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Strategy derived from pinescript-agents/examples/intermediate/multi-timeframe-rsi.pine for backtesting in pinescripts-collections.

//@version=6
strategy("MTF RSI Confluence [Agent Example]", shorttitle="MTFRSISt", overlay=true, margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)

rsiLength = input.int(14, "RSI Length", minval=1, group="RSI")
rsiSource = input.source(close, "Source", group="RSI")

tf1 = input.timeframe("", "TF1 (blank = chart)", group="Timeframes")
tf2 = input.timeframe("15", "Timeframe 2", group="Timeframes")
tf3 = input.timeframe("60", "Timeframe 3", group="Timeframes")
tf4 = input.timeframe("240", "Timeframe 4", group="Timeframes")

lookbackBars = input.int(50, "Divergence Lookback", minval=10, group="Divergence")

oversold = input.int(30, "Oversold", group="Levels")
overbought = input.int(70, "Overbought", group="Levels")

bullThreshold = input.float(2.0, "Long: confluence >", step=0.25, group="Signals")
bearThreshold = input.float(-2.0, "Short: confluence <", step=0.25, group="Signals")
bullColorInput = input.color(#089981, "Bullish Color", group="Visuals")
bearColorInput = input.color(#f23645, "Bearish Color", group="Visuals")

rsi_tf1 = tf1 == "" ? ta.rsi(rsiSource, rsiLength) : request.security(syminfo.tickerid, tf1, ta.rsi(rsiSource, rsiLength), lookahead=barmerge.lookahead_off)
rsi2 = request.security(syminfo.tickerid, tf2, ta.rsi(rsiSource, rsiLength), lookahead=barmerge.lookahead_off)
rsi3 = request.security(syminfo.tickerid, tf3, ta.rsi(rsiSource, rsiLength), lookahead=barmerge.lookahead_off)
rsi4 = request.security(syminfo.tickerid, tf4, ta.rsi(rsiSource, rsiLength), lookahead=barmerge.lookahead_off)

rsi1 = rsi_tf1

pivotHigh = ta.pivothigh(high, 5, 5)
pivotLow = ta.pivotlow(low, 5, 5)

var float lastPivotHighPrice = na
var float lastPivotHighRSI = na
var int lastPivotHighBar = na
var float lastPivotLowPrice = na
var float lastPivotLowRSI = na
var int lastPivotLowBar = na

if not na(pivotHigh)
    lastPivotHighPrice := high[5]
    lastPivotHighRSI := rsi1[5]
    lastPivotHighBar := bar_index - 5

if not na(pivotLow)
    lastPivotLowPrice := low[5]
    lastPivotLowRSI := rsi1[5]
    lastPivotLowBar := bar_index - 5

var bool bullishDiv = false
var bool bearishDiv = false
bullishDiv := false
bearishDiv := false
if not na(pivotLow) and not na(lastPivotLowPrice) and bar_index - lastPivotLowBar < lookbackBars and low[5] < lastPivotLowPrice and rsi1[5] > lastPivotLowRSI
    bullishDiv := true
if not na(pivotHigh) and not na(lastPivotHighPrice) and bar_index - lastPivotHighBar < lookbackBars and high[5] > lastPivotHighPrice and rsi1[5] < lastPivotHighRSI
    bearishDiv := true

confluenceScore = (rsi1 < oversold ? 1.0 : 0.0) + (rsi2 < oversold ? 0.75 : 0.0) + (rsi3 < oversold ? 0.5 : 0.0) + (rsi4 < oversold ? 0.25 : 0.0) - (rsi1 > overbought ? 1.0 : 0.0) - (rsi2 > overbought ? 0.75 : 0.0) - (rsi3 > overbought ? 0.5 : 0.0) - (rsi4 > overbought ? 0.25 : 0.0) + (bullishDiv ? 2.0 : 0.0) - (bearishDiv ? 2.0 : 0.0)

longSignal = confluenceScore > bullThreshold
shortSignal = confluenceScore < bearThreshold

if longSignal
    strategy.entry("Long", strategy.long)
if shortSignal
    strategy.entry("Short", strategy.short)

if strategy.position_size > 0 and confluenceScore < bullThreshold
    strategy.close("Long")
if strategy.position_size < 0 and confluenceScore > bearThreshold
    strategy.close("Short")

plot(confluenceScore, "Confluence Score", color=confluenceScore > 0 ? bullColorInput : confluenceScore < 0 ? bearColorInput : color.new(#2a2e39, 0), linewidth=2, style=plot.style_stepline)
hline(0, "Neutral", color=color.new(#2a2e39, 40))
plotshape(longSignal, "Long Signal", shape.triangleup, location.belowbar, color.new(bullColorInput, 0), size=size.tiny, text="L")
plotshape(shortSignal, "Short Signal", shape.triangledown, location.abovebar, color.new(bearColorInput, 0), size=size.tiny, text="S")

Overview

MTF RSI Confluence enters long when the score rises above a threshold and short when it falls below the negative threshold, and closes a position when the score weakens. It has no stop loss or take profit. Size is ten percent of equity.

Details

Published by

shubhamtaywade82 on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Oscillators & momentum, Divergence

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
RSI Lengthint14rsiLength
SourcesourceclosersiSource
TF1 (blank = chart)timeframetf1
Timeframe 2timeframe15tf2
Timeframe 3timeframe60tf3
Timeframe 4timeframe240tf4
Divergence Lookbackint50lookbackBars
Oversoldint30oversold
Overboughtint70overbought
Long: confluence >float2.0bullThreshold
Short: confluence <float-2.0bearThreshold
Bullish Colorcolor#089981bullColorInput
Show all 13 settings
SettingTypeDefaultVariable
Bearish Colorcolor#f23645bearColorInput
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

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

RSI Divergence

by muammeryldrm42
7 stars

This strategy detects bullish and bearish RSI divergences using price and RSI pivot points. A bullish divergence triggers a long entry when price forms a lower low while RSI forms a higher low below 40. A bearish divergence triggers a short entry when price fo

Strategy v5 Oscillators & momentumDivergence
Updated 3 months ago · MIT GitHub repository of RSI Divergence

This strategy executes long positions by combining a 200-period EMA trend filter, Stochastic RSI oversold crosses, and Williams Alligator retracements, supplemented by RSI divergence detection. It triggers long entries when the price trades above the 200 EMA w

Strategy v4 TrendOscillators & momentum
Updated 3 years ago · Apache-2.0 GitHub repository of 200 EMA + Alligator + Stochastic Long Strategy
4 stars

Divergence Strategy scans multiple technical oscillators to detect regular and hidden divergences against price action. It evaluates customizable indicators including MACD, RSI, Stochastic, CCI, Momentum, OBV, and Money Flow Index to trigger strategy entries o

Strategy v4 DivergenceOscillators & momentum
Updated 4 years ago · None stated GitHub repository of Divergence Strategy

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