Rainbow Adaptive Rsi

https://www.tradingview.com/script/ZIO3hXCd-Rainbow-Adaptive-RSI/

The following oscillator uses an adaptive moving average as input for another RSI oscillator and aims to provide a way to minimize the impact of retracements over the oscillator output without introducing significant lag. An additional trigger line is present in order to provide entry points from the crosses between the oscillator and the trigger line. More details are given below.

Settings

  • Length : period of the oscillator

  • Power : control the sensitivity of the oscillator to retracements, with higher values minimizing the sensitivity to retracements.

  • Src : source input of the indicator

The indicator also includes the following graphical settings:

  • Gradient : determine the color mode to use for the gradient, options include "Red To Green", "Red To Blue" and "None", with "None" displaying no gradient.

  • Color fill : determine whether to fill the area between the oscillator and the trigger line or not, by default "On".

  • Circles : determine whether to show circles highlighting the crosses between the oscillator and the trigger line.

Usage

The indicator can be used like any normalized oscillator, but unlike a classical RSI the oscillator does not converge toward 50 with higher length values, this is caused by the RSI using a smooth input. The power setting will minimize the impact of certain variations on the oscillator:

the oscillator at the bottom uses a power value of 1.5

The trigger line is a smoothed RSI using an EMA as input, and won't remain as near to 100 and 0 as the main oscillator. Using a moving average of the main oscillator as a trigger line would create faster crosses, but's this approach allows us to have no crosses when a retracement is present.

Details

As previously discussed the main oscillator uses an adaptive moving average as input; this adaptive moving average is computed using a smoothing factor derived from an RSI oscillator, a similar adaptive moving average known as ARSI, but unlike ARSI which uses a classical RSI of the closing price for the calculation of the smoothing factor, our smoothing factor makes use of RSI on the adaptive moving average error, which provides a higher level of adaptiveness.

Code

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=4
study("Rainbow Adaptive Rsi","RAR")
//Settings[---------------------------------------------------------------------
h1 = input(true ,"───────────── Rsi Settings ──────────────")
length = input(14 ,"  Length",minval=1)
power = input(1. ,"  Power",minval=0,step=.1)
src = input(close,"  Source")
//----
h2 = input(true ,"───────────── Plot Settings ─────────────")
gradient = input("Red To Green","  Gradient",options=["Red To Green","Red To Blue","None"])
colfill = input("On" ,"  Color Fill",options=["On","Off"])
use_circ = input("On" ,"  Circles",options=["On","Off"])
//-----------------------------------------------------------------------------]
//Gradient[---------------------------------------------------------------------
get_gradient(x)=>
var css = array.new_color(na)
if barstate.isfirst
if gradient == "Red To Green"
array.push(css,#FF1100), array.push(css,#FF1200), array.push(css,#FF1400), array.push(css,#FF1500), array.push(css,#FF1700), array.push(css,#FF1800), array.push(css,#FF1A00), array.push(css,#FF1B00), array.push(css,#FF1D00), array.push(css,#FF1F00), array.push(css,#FF2000), array.push(css,#FF2200), array.push(css,#FF2300), array.push(css,#FF2500), array.push(css,#FF2600), array.push(css,#FF2800), array.push(css,#FF2900), array.push(css,#FF2B00), array.push(css,#FF2D00), array.push(css,#FF2E00), array.push(css,#FF3000), array.push(css,#FF3100), array.push(css,#FF3300), array.push(css,#FF3400), array.push(css,#FF3600), array.push(css,#FF3700), array.push(css,#FF3900), array.push(css,#FF3B00), array.push(css,#FF3C00), array.push(css,#FF3E00), array.push(css,#FF3F00), array.push(css,#FF4100), array.push(css,#FF4200), array.push(css,#FF4400), array.push(css,#FF4500), array.push(css,#FF4700), array.push(css,#FF4900), array.push(css,#FF4A00), array.push(css,#FF4C00), array.push(css,#FF4D00), array.push(css,#FF4F00), array.push(css,#FF5000), array.push(css,#FF5200), array.push(css,#FF5300), array.push(css,#FF5500), array.push(css,#FF5700), array.push(css,#FF5800), array.push(css,#FF5A00), array.push(css,#FF5B00), array.push(css,#FF5D00), array.push(css,#FF5E00), array.push(css,#FF6000), array.push(css,#FF6200), array.push(css,#FF6300), array.push(css,#FF6500), array.push(css,#FF6600), array.push(css,#FF6800), array.push(css,#FF6900), array.push(css,#FF6B00), array.push(css,#FF6C00), array.push(css,#FF6E00), array.push(css,#FF7000), array.push(css,#FF7100), array.push(css,#FF7300), array.push(css,#FF7400), array.push(css,#FF7600), array.push(css,#FF7700), array.push(css,#FF7900), array.push(css,#FF7A00), array.push(css,#FF7C00), array.push(css,#FF7E00), array.push(css,#FF7F00), array.push(css,#FF8100), array.push(css,#FF8200), array.push(css,#FF8400), array.push(css,#FF8500), array.push(css,#FF8700), array.push(css,#FF8800), array.push(css,#FF8A00), array.push(css,#FF8C00), array.push(css,#FF8D00), array.push(css,#FF8F00), array.push(css,#FF9000), array.push(css,#FF9200), array.push(css,#FF9300), array.push(css,#FF9500), array.push(css,#FF9600), array.push(css,#FF9800), array.push(css,#FF9A00), array.push(css,#FF9B00), array.push(css,#FF9D00), array.push(css,#FF9E00), array.push(css,#FFA000), array.push(css,#FFA100), array.push(css,#FFA300), array.push(css,#FFA400), array.push(css,#FFA600), array.push(css,#FFA800), array.push(css,#FFA900), array.push(css,#FFAB00), array.push(css,#FDAC00), array.push(css,#FBAD02), array.push(css,#F9AE03), array.push(css,#F7AE04), array.push(css,#F5AF06), array.push(css,#F3B007), array.push(css,#F1B108), array.push(css,#EFB20A), array.push(css,#EDB30B), array.push(css,#EBB30C), array.push(css,#E9B40E), array.push(css,#E7B50F), array.push(css,#E4B610), array.push(css,#E2B712), array.push(css,#E0B813), array.push(css,#DEB814), array.push(css,#DCB916), array.push(css,#DABA17), array.push(css,#D8BB18), array.push(css,#D6BC1A), array.push(css,#D4BD1B), array.push(css,#D2BD1C), array.push(css,#D0BE1E), array.push(css,#CEBF1F), array.push(css,#CCC020), array.push(css,#C9C122), array.push(css,#C7C223), array.push(css,#C5C224), array.push(css,#C3C326), array.push(css,#C1C427), array.push(css,#BFC528), array.push(css,#BDC62A), array.push(css,#BBC72B), array.push(css,#B9C72C), array.push(css,#B7C82E), array.push(css,#B5C92F), array.push(css,#B3CA30), array.push(css,#B0CB32), array.push(css,#AECC33), array.push(css,#ACCC34), array.push(css,#AACD36), array.push(css,#A8CE37), array.push(css,#A6CF38), array.push(css,#A4D03A), array.push(css,#A2D13B), array.push(css,#A0D13C), array.push(css,#9ED23E), array.push(css,#9CD33F), array.push(css,#9AD440), array.push(css,#98D542), array.push(css,#95D643), array.push(css,#93D644), array.push(css,#91D746), array.push(css,#8FD847), array.push(css,#8DD948), array.push(css,#8BDA4A), array.push(css,#89DB4B), array.push(css,#87DB4C), array.push(css,#85DC4E), array.push(css,#83DD4F), array.push(css,#81DE50), array.push(css,#7FDF52), array.push(css,#7CE053), array.push(css,#7AE054), array.push(css,#78E156), array.push(css,#76E257), array.push(css,#74E358), array.push(css,#72E45A), array.push(css,#70E55B), array.push(css,#6EE55C), array.push(css,#6CE65E), array.push(css,#6AE75F), array.push(css,#68E860), array.push(css,#66E962), array.push(css,#64EA63), array.push(css,#61EA64), array.push(css,#5FEB66), array.push(css,#5DEC67), array.push(css,#5BED68), array.push(css,#59EE6A), array.push(css,#57EF6B), array.push(css,#55EF6C), array.push(css,#53F06E), array.push(css,#51F16F), array.push(css,#4FF270), array.push(css,#4DF372), array.push(css,#4BF473), array.push(css,#48F474), array.push(css,#46F576), array.push(css,#44F677), array.push(css,#42F778), array.push(css,#40F87A), array.push(css,#3EF97B), array.push(css,#3CF97C), array.push(css,#3AFA7E), array.push(css,#38FB7F), array.push(css,#36FC80), array.push(css,#34FD82), array.push(css,#32FE83), array.push(css,#30FF85),
else
array.push(css,#FF1100), array.push(css,#FD1101), array.push(css,#FC1102), array.push(css,#FB1203), array.push(css,#FA1204), array.push(css,#F91206), array.push(css,#F81307), array.push(css,#F71308), array.push(css,#F61309), array.push(css,#F4140A), array.push(css,#F3140C), array.push(css,#F2140D), array.push(css,#F1150E), array.push(css,#F0150F), array.push(css,#EF1511), array.push(css,#EE1612), array.push(css,#ED1613), array.push(css,#EC1614), array.push(css,#EA1715), array.push(css,#E91717), array.push(css,#E81818), array.push(css,#E71819), array.push(css,#E6181A), array.push(css,#E5191C), array.push(css,#E4191D), array.push(css,#E3191E), array.push(css,#E11A1F), array.push(css,#E01A20), array.push(css,#DF1A22), array.push(css,#DE1B23), array.push(css,#DD1B24), array.push(css,#DC1B25), array.push(css,#DB1C27), array.push(css,#DA1C28), array.push(css,#D91C29), array.push(css,#D71D2A), array.push(css,#D61D2B), array.push(css,#D51E2D), array.push(css,#D41E2E), array.push(css,#D31E2F), array.push(css,#D21F30), array.push(css,#D11F32), array.push(css,#D01F33), array.push(css,#CF2034), array.push(css,#CD2035), array.push(css,#CC2036), array.push(css,#CB2138), array.push(css,#CA2139), array.push(css,#C9213A), array.push(css,#C8223B), array.push(css,#C7223D), array.push(css,#C6223E), array.push(css,#C4233F), array.push(css,#C32340), array.push(css,#C22341), array.push(css,#C12443), array.push(css,#C02444), array.push(css,#BF2545), array.push(css,#BE2546), array.push(css,#BD2548), array.push(css,#BC2649), array.push(css,#BA264A), array.push(css,#B9264B), array.push(css,#B8274C), array.push(css,#B7274E), array.push(css,#B6274F), array.push(css,#B52850), array.push(css,#B42851), array.push(css,#B32853), array.push(css,#B22954), array.push(css,#B02955), array.push(css,#AF2956), array.push(css,#AE2A57), array.push(css,#AD2A59), array.push(css,#AC2B5A), array.push(css,#AB2B5B), array.push(css,#AA2B5C), array.push(css,#A92C5E), array.push(css,#A72C5F), array.push(css,#A62C60), array.push(css,#A52D61), array.push(css,#A42D62), array.push(css,#A32D64), array.push(css,#A22E65), array.push(css,#A12E66), array.push(css,#A02E67), array.push(css,#9F2F69), array.push(css,#9D2F6A), array.push(css,#9C2F6B), array.push(css,#9B306C), array.push(css,#9A306D), array.push(css,#99316F), array.push(css,#983170), array.push(css,#973171), array.push(css,#963272), array.push(css,#953274), array.push(css,#933275), array.push(css,#923376), array.push(css,#913377), array.push(css,#903378), array.push(css,#8F347A), array.push(css,#8E347B), array.push(css,#8D347C), array.push(css,#8C357D), array.push(css,#8A357E), array.push(css,#893580), array.push(css,#883681), array.push(css,#873682), array.push(css,#863683), array.push(css,#853785), array.push(css,#843786), array.push(css,#833887), array.push(css,#823888), array.push(css,#803889), array.push(css,#7F398B), array.push(css,#7E398C), array.push(css,#7D398D), array.push(css,#7C3A8E), array.push(css,#7B3A90), array.push(css,#7A3A91), array.push(css,#793B92), array.push(css,#783B93), array.push(css,#763B94), array.push(css,#753C96), array.push(css,#743C97), array.push(css,#733C98), array.push(css,#723D99), array.push(css,#713D9B), array.push(css,#703E9C), array.push(css,#6F3E9D), array.push(css,#6D3E9E), array.push(css,#6C3F9F), array.push(css,#6B3FA1), array.push(css,#6A3FA2), array.push(css,#6940A3), array.push(css,#6840A4), array.push(css,#6740A6), array.push(css,#6641A7), array.push(css,#6541A8), array.push(css,#6341A9), array.push(css,#6242AA), array.push(css,#6142AC), array.push(css,#6042AD), array.push(css,#5F43AE), array.push(css,#5E43AF), array.push(css,#5D44B1), array.push(css,#5C44B2), array.push(css,#5B44B3), array.push(css,#5945B4), array.push(css,#5845B5), array.push(css,#5745B7), array.push(css,#5646B8), array.push(css,#5546B9), array.push(css,#5446BA), array.push(css,#5347BC), array.push(css,#5247BD), array.push(css,#5047BE), array.push(css,#4F48BF), array.push(css,#4E48C0), array.push(css,#4D48C2), array.push(css,#4C49C3), array.push(css,#4B49C4), array.push(css,#4A49C5), array.push(css,#494AC7), array.push(css,#484AC8), array.push(css,#464BC9), array.push(css,#454BCA), array.push(css,#444BCB), array.push(css,#434CCD), array.push(css,#424CCE), array.push(css,#414CCF), array.push(css,#404DD0), array.push(css,#3F4DD2), array.push(css,#3E4DD3), array.push(css,#3C4ED4), array.push(css,#3B4ED5), array.push(css,#3A4ED6), array.push(css,#394FD8), array.push(css,#384FD9), array.push(css,#374FDA), array.push(css,#3650DB), array.push(css,#3550DD), array.push(css,#3351DE), array.push(css,#3251DF), array.push(css,#3151E0), array.push(css,#3052E1), array.push(css,#2F52E3), array.push(css,#2E52E4), array.push(css,#2D53E5), array.push(css,#2C53E6), array.push(css,#2B53E8), array.push(css,#2954E9), array.push(css,#2854EA), array.push(css,#2754EB), array.push(css,#2655EC), array.push(css,#2555EE), array.push(css,#2455EF), array.push(css,#2356F0), array.push(css,#2256F1), array.push(css,#2157F3),
array.get(css,round(x*199)) // Assuming x∈[0,1]
//-----------------------------------------------------------------------------]
//Rsi[--------------------------------------------------------------------------
ama = 0.
alpha = abs(rsi(src - ama[1],length)/100 - 0.5)
ama := nz(ama[1]+pow(alpha,power)*(src-ama[1]),src)
rsi = rsi(ama,length)
trigger = ema(rsi(ema(src,length/2),length),length/2)
//-----------------------------------------------------------------------------]
//Plots[--------------------------------------------------------------------------
true_grad = gradient != "None"
col_css = get_gradient(rsi/100)
A = plot(true_grad ? rsi : na,color=col_css,editable=false)
B = plot(true_grad ? trigger : na,color=na,editable=false)
fill(A,B,colfill == "On" and true_grad ? col_css : na,50,editable=false)
//----
plot(not true_grad ? rsi : na,color=#2157f3)
plot(not true_grad ? trigger : na,color=#ff1100)
hline(80),hline(20)
//---- Circles
plot(use_circ == "Off" ? na : cross(rsi,trigger) ? rsi : na,"Crossing Points",
true_grad ? col_css : na,2,plot.style_circles,editable=false)
//-----------------------------------------------------------------------------]