here is the code i found someone in tradingview have developed an indicator if that can be converted to PRO REAL TIME PLEASE
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © TJ_667
// Concept developed from RSI : The Complete Guide by John Hayden
// RSI is regarded as a momentum indicator. 2:1 momentum is associated with RSI values of 66.67 and 33.33 respectfully. In an Uptrend an RSI value of 40 should not be broken and in a downtrend
// a RSI value of 60 should not be exceeded. 4:1 momentum (RSI values of 80/20) can be associated with extreme market conditions, typically thought of as being Overbought or Oversold.
// Simple divergence provides a strong indication that the preceding trend will resume as soon as the retracement is completed. Multiple long-term divergences (not shown in this indicator)
// increase the likelihood that the preceding trend has ended.
// An Uptrend is indicated when:
// 1. RSI values remain in an 80/40 range
// 2. Presence of bearish divergences
// 3. Hidden bullish divergences are seen
// A Downtrend is indicated when:
// 1. RSI values remain in a 60/20 range
// 2. Presence of bullish divergence
// 3. Hidden bearish divergence is seen
// Personal additions to John Haydens concepts are horizontal pivot breaks and diagonal trendline breaks. The 80/20 line color shows the last break of horizontal pivot points, while the rsi
// line changes color with diagonal breaks. Additional support/resistance is shown by 66.67 and 33.33 lines.
//@version=4
study(“Koalafied RSI”, overlay=false)
//——————– INPUTS ——————– //
len = input(14, minval=1, title=”RSI Length”)
showTS = input(true, ‘Show Trend State’)
showTM2 = input(true, ‘Show Trend Momentum (2:1)’)
showTM3 = input(true, ‘Show Trend Momentum (3:1)’)
showOBS = input(true, ‘Show OB/OS’)
showDiags = input(true, title = “Show Diag Breaks”)
HZB = input(true, “Show Horizontal Pivot Initial Break”)
ShowPivots = input(false, title=”Show Pivot Points”)
left = input(10, minval=1, title=”Pivot Length Left Hand Side”)
right = input(10, minval=1, title=”Pivot Length Right Hand Side”)
// RSI
rsi = rsi(close, len)
// Trend State
var state = 0
if crossover(rsi, 66.67)
state := 1
if crossunder(rsi, 33.33)
state := 2
if state == 1 and crossunder(rsi, 40)
state := 3
if state == 2 and crossover(rsi, 60)
state := 3
state := state
state_col = state == 1 ? color.blue : state == 2 ? color.red : state == 3 ? color.black : na
state_col2 = state == 1 ? color.blue : state == 2 ? color.red : state == 3 ? color.silver : na
// Trend
bgcolor(showTS ? state_col : na, title = ‘Trend State’, transp = 95)
// 2:1 Momentum
BG_col = rsi > 66.67 ? color.blue : rsi < 33.33 ? color.red : na
bgcolor(showTM2 ? BG_col : na, title = ‘Trend Momentum’, transp = 95)
// 3:1 Momentum
fillH_col = rsi > 75 ? color.aqua : na
fillL_col = rsi < 25 ? color.fuchsia : na
// 4:1 Momentum
OB = rsi > 80 ? color.red : na
OS = rsi < 20 ? color.blue : na
bgcolor(showOBS ? OB : na, title = ‘Overbought’, transp = 90)
bgcolor(showOBS ? OS : na, title = ‘Oversold’, transp = 90)
// Support/Resistance
support = state == 3 and rsi < 40 ? color.blue : na
resistance = state == 3 and rsi > 60 ? color.red : na
//——————– PIVOTS ——————– //
// Adapted from ‘Pivot Points High Low (HH/HL/LH/LL)’ – Mohamed3nan
// Determine pivots
pvtLenL = left
pvtLenR = right
// Get High and Low Pivot Points
pvthi = pivothigh(rsi, pvtLenL, pvtLenR)
pvtlo = pivotlow(rsi, pvtLenL, pvtLenR)
// Get HH, LH, LL, HL
valuewhen_1 = valuewhen(pvthi, rsi[pvtLenR], 1)
valuewhen_2 = valuewhen(pvthi, rsi[pvtLenR], 0)
higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
valuewhen_3 = valuewhen(pvthi, rsi[pvtLenR], 1)
valuewhen_4 = valuewhen(pvthi, rsi[pvtLenR], 0)
lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
valuewhen_5 = valuewhen(pvtlo, rsi[pvtLenR], 1)
valuewhen_6 = valuewhen(pvtlo, rsi[pvtLenR ], 0)
higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
valuewhen_7 = valuewhen(pvtlo, rsi[pvtLenR], 1)
valuewhen_8 = valuewhen(pvtlo, rsi[pvtLenR ], 0)
lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
plot(ShowPivots ? rsi[pvtLenR] : na, “HH”, style = plot.style_circles, linewidth = 2, color = higherhigh ? color.new(color.aqua,0) : na, offset=-pvtLenR)
plot(ShowPivots ? rsi[pvtLenR] : na, “HL”, style = plot.style_circles, linewidth = 2, color = higherlow ? color.new(color.aqua,0) : na, offset=-pvtLenR)
plot(ShowPivots ? rsi[pvtLenR] : na, “LH”, style = plot.style_circles, linewidth = 2, color= lowerhigh ? color.new(color.red,0) : na, offset=-pvtLenR)
plot(ShowPivots ? rsi[pvtLenR] : na, “LL”, style = plot.style_circles, linewidth = 2, color= lowerlow ? color.new(color.red,0) : na, offset=-pvtLenR)
//Count How many candles for current Pivot Level, If new reset.
counthi = 0
countlo = 0
counthi := na(pvthi) ? nz(counthi[1]) + 1 : 0
countlo := na(pvtlo) ? nz(countlo[1]) + 1 : 0
pvthis = 0.0
pvtlos = 0.0
pvthis := na(pvthi) ? pvthis[1] : rsi[pvtLenR]
pvtlos := na(pvtlo) ? pvtlos[1] : rsi[pvtLenR]
// Horizontal Pivot State
var stateHB = 0
if crossover(rsi, pvthis)
stateHB := 1
if crossunder(rsi, pvtlos)
stateHB := 2
stateHB := stateHB
statechangeL = crossover(rsi, pvthis) and stateHB[1] == 2
statechangeS = crossunder(rsi, pvtlos) and stateHB[1] == 1
stateHB_col = stateHB == 1 ? color.blue : stateHB == 2 ? color.red : na
//——————– DIAGONALS ——————– //
// Adapted from ‘Trendlines’ – BacktestRookies
ph = pvthi
pl = pvtlo
phv1 = valuewhen(ph, rsi[right], 0)
phb1 = valuewhen(ph, bar_index[right], 0)
phv2 = valuewhen(ph, rsi[right], 1)
phb2 = valuewhen(ph, bar_index[right], 1)
plv1 = valuewhen(pl, rsi[right], 0)
plb1 = valuewhen(pl, bar_index[right], 0)
plv2 = valuewhen(pl, rsi[right], 1)
plb2 = valuewhen(pl, bar_index[right], 1)
// TRENDLINE CODE
// ————–
get_slope(x1,x2,y1,y2)=>
m = (y2-y1)/(x2-x1)
get_y_intercept(m, x1, y1)=>
b=y1-m*x1
get_y(m, b, ts)=>
Y = m * ts + b
int res_x1 = na
float res_y1 = na
int res_x2 = na
float res_y2 = na
int sup_x1 = na
float sup_y1 = na
int sup_x2 = na
float sup_y2 = na
// Resistance
res_x1 := ph ? phb1 : res_x1[1]
res_y1 := ph ? phv1 : res_y1[1]
res_x2 := ph ? phb2 : res_x2[1]
res_y2 := ph ? phv2 : res_y2[1]
res_m = get_slope(res_x1,res_x2,res_y1,res_y2)
res_b = get_y_intercept(res_m, res_x1, res_y1)
res_y = get_y(res_m, res_b, bar_index)
// Support
sup_x1 := pl ? plb1 : sup_x1[1]
sup_y1 := pl ? plv1 : sup_y1[1]
sup_x2 := pl ? plb2 : sup_x2[1]
sup_y2 := pl ? plv2 : sup_y2[1]
sup_m = get_slope(sup_x1,sup_x2,sup_y1,sup_y2)
sup_b = get_y_intercept(sup_m, sup_x1, sup_y1)
sup_y = get_y(sup_m, sup_b, bar_index)
// Breaks
long_break = rsi > res_y ? color.blue : na
short_break = rsi < sup_y ? color.red : na
no_break = rsi < res_y and rsi > sup_y ? color.gray : na
//——————– Plots ——————– //
r = plot(rsi, “RSI”, color = not showDiags ? color.gray : na, linewidth = 1, transp = 0)
rl = plot(showDiags ? rsi : na, color = long_break, title=”RSI Long Diag”, style = plot.style_line, transp = 10, linewidth = 2)
rs = plot(showDiags ? rsi : na, color = short_break, title=”RSI Short Diag”, style = plot.style_line, transp = 10, linewidth = 2)
rnb = plot(showDiags ? rsi : na, color = no_break, title=”RSI No Diag”, style = plot.style_line, transp = 0, linewidth = 1)
h = plot(80, “High”, color = stateHB_col, style = plot.style_circles, transp = 40)
mhh = plot(66.67, “Resistance”, color = resistance, linewidth = 2, transp = 25)
mh = plot(60, “Mid-High Band”, color = state == 2 or state == 3 ? state_col2 : na, style = plot.style_circles, linewidth = 1, transp = 50)
ml = plot(40, “Mid-Low Band”, color = state == 1 or state == 3 ? state_col2 : na, style = plot.style_circles, linewidth = 1, transp = 50)
mll = plot(33.33, “Support”, color = support, linewidth = 2, transp = 25)
l = plot(20, “Low”, color = stateHB_col, style = plot.style_circles, transp = 40)
fill(mh, ml, state_col2, title = “Trend State”, transp = 92)
fill(ml, r, showTM3 ? fillH_col : na, title = “Bull 3:1 Momentum”, transp = 85)
fill(mh, r, showTM3 ? fillL_col : na, title = “Bear 3:1 Momentum”, transp = 85)
plotshape(HZB ? statechangeL : na, style=shape.triangleup,
location=location.bottom, color=color.blue, transp = 25)
plotshape(HZB ? statechangeS : na, style=shape.triangledown,
location=location.top, color=color.red, transp = 25)
//——————– RSI Divergences ——————– //
// Adapted from built-in Divergences Script
lbR = input(title=”Pivot Lookback Right”, defval=3)
lbL = input(title=”Pivot Lookback Left”, defval=3)
rangeUpper = input(title=”Max of Lookback Range”, defval=10)
rangeLower = input(title=”Min of Lookback Range”, defval=3)
plotBull = input(title=”Plot Bullish”, defval=true)
plotHiddenBull = input(title=”Plot Hidden Bullish”, defval=true)
plotBear = input(title=”Plot Bearish”, defval=true)
plotHiddenBear = input(title=”Plot Hidden Bearish”, defval=true)
bearColor = color.red
bullColor = color.blue
hiddenBullColor = color.new(color.blue, 25)
hiddenBearColor = color.new(color.red, 25)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = rsi
plFound = na(pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//——————————————————————————
// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = close[lbR] < valuewhen(plFound, close[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
///plot(
/// plFound ? rsi[lbR] : na,
// offset=-lbR,
// title=”Regular Bullish”,
// linewidth=2,
// color=(bullCond ? bullColor : noneColor),
// transp=50
// )
plotshape(
bullCond ? rsi[lbR] : na,
offset=-lbR,
title=”Regular Bullish Label”,
text=”D”,
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor,
transp=65
)
//——————————————————————————
// Hidden Bullish
// Osc: Lower Low
oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Higher Low
priceHL = close[lbR] > valuewhen(plFound, close[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
plot(
plFound ? rsi[lbR] : na,
offset=-lbR,
title=”Hidden Bullish”,
linewidth=1,
color=(hiddenBullCond ? hiddenBullColor : noneColor),
transp=15
)
//plotshape(
// hiddenBullCond ? rsi[lbR] : na,
// offset=-lbR,
// title=”Hidden Bullish Label”,
// text=” H “,
// style=shape.labelup,
// location=location.absolute,
// color=bullColor,
// textcolor=textColor,
// transp=75
// )
//——————————————————————————
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = close[lbR] > valuewhen(phFound, close[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound
//plot(
// phFound ? rsi[lbR] : na,
// offset=-lbR,
// title=”Regular Bearish”,
// linewidth=2,
// color=(bearCond ? bearColor : noneColor),
// transp=50
// )
plotshape(
bearCond ? rsi[lbR] : na,
offset=-lbR,
title=”Regular Bearish Label”,
text=”D”,
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor,
transp=65
)
//——————————————————————————
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Lower High
priceLH = close[lbR] < valuewhen(phFound, close[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
plot(
phFound ? rsi[lbR] : na,
offset=-lbR,
title=”Hidden Bearish”,
linewidth=1,
color=(hiddenBearCond ? hiddenBearColor : noneColor),
transp=15
)
//plotshape(
// hiddenBearCond ? rsi[lbR] : na,
// offset=-lbR,
// title=”Hidden Bearish Label”,
// text=” H “,
// style=shape.labeldown,
// location=location.absolute,
// color=bearColor,
// textcolor=textColor,
// transp=75
// )