Skip to content
GetProfitable
Search
Momentum

Momentum Divergence Hint

Marks the bars where price takes out its highest high of the lookback while RSI fails to take out its own highest reading, and the mirror case at lows. A hint to go and look, not a signal.

indicator
//@version=6
indicator("Momentum Divergence Hint", "Div Hint", overlay = true)

length = input.int(20, "Lookback bars", minval = 2, group = "Settings")
rsiLen = input.int(14, "RSI length", minval = 2, group = "Settings")
bull = input.color(#26A69A, "Low without RSI low", group = "Style")
bear = input.color(#EF5350, "High without RSI high", group = "Style")

rsi = ta.rsi(close, rsiLen)
priorHigh = ta.highest(high, length)
priorLow = ta.lowest(low, length)
priorRsiHigh = ta.highest(rsi, length)
priorRsiLow = ta.lowest(rsi, length)

newHigh = high > priorHigh[1]
newLow = low < priorLow[1]
rsiAlsoHigh = rsi > priorRsiHigh[1]
rsiAlsoLow = rsi < priorRsiLow[1]

bearHint = newHigh and not rsiAlsoHigh
bullHint = newLow and not rsiAlsoLow

plotshape(bearHint, "Bearish hint", location = location.abovebar, style = shape.xcross, color = bear, size = size.tiny)
plotshape(bullHint, "Bullish hint", location = location.belowbar, style = shape.xcross, color = bull, size = size.tiny)
alertcondition(bearHint, "New high without a new RSI high", "Price made a new high for the lookback while RSI did not")
alertcondition(bullHint, "New low without a new RSI low", "Price made a new low for the lookback while RSI did not")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • This is a deliberately crude test on fixed windows. It is not pivot based divergence and it does not connect two confirmed swings, so it fires on shapes a chartist would not draw a line across.
  • Momentum routinely lags price at the start of a strong trend, so early trend bars produce hints that mean nothing.
  • A hint says the two series disagree for one bar. It says nothing about whether that disagreement resolves, or in which direction.
  • The lookback decides the result. A different N on the same chart marks a different set of bars.

Written from this description

Compare the highest high of the last N bars with the highest RSI of the same N bars. Mark a bar when price makes a new N bar high but RSI does not, and mark the opposite case at a new N bar low.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.