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.
// 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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
RSI Length
int
14
rsiLength
Source
source
close
rsiSource
TF1 (blank = chart)
timeframe
tf1
Timeframe 2
timeframe
15
tf2
Timeframe 3
timeframe
60
tf3
Timeframe 4
timeframe
240
tf4
Divergence Lookback
int
50
lookbackBars
Oversold
int
30
oversold
Overbought
int
70
overbought
Long: confluence >
float
2.0
bullThreshold
Short: confluence <
float
-2.0
bearThreshold
Bullish Color
color
#089981
bullColorInput
Show all 13 settings
Setting
Type
Default
Variable
Bearish Color
color
#f23645
bearColorInput
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.
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
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
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
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
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
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