Percentile Nearest Rank Rainbow Overlay (PNRV)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("PNRV", overlay = true)
grad(src)=>
    color out = switch int(src)
        0 => color.new(#1500FF , 90)
        1 => color.new(#1709F6 , 90)
        2 => color.new(#1912ED , 90)
        3 => color.new(#1B1AE5 , 90)
        4 => color.new(#1D23DC , 90)
        5 => color.new(#1F2CD3 , 90)
        6 => color.new(#2135CA , 90)
        7 => color.new(#233EC1 , 90)
        8 => color.new(#2446B9 , 90)
        9 => color.new(#264FB0 , 90)
        10 => color.new(#2858A7 , 90)
        11 => color.new(#2A619E , 90)
        12 => color.new(#2C6A95 , 90)
        13 => color.new(#2E728D , 90)
        14 => color.new(#307B84 , 90)
        15 => color.new(#32847B , 90)
        16 => color.new(#348D72 , 90)
        17 => color.new(#36956A , 90)
        18 => color.new(#389E61 , 90)
        19 => color.new(#3AA758 , 90)
        20 => color.new(#3CB04F , 90)
        21 => color.new(#3EB946 , 90)
        22 => color.new(#3FC13E , 90)
        23 => color.new(#41CA35 , 90)
        24 => color.new(#43D32C , 90)
        25 => color.new(#45DC23 , 90)
        26 => color.new(#47E51A , 90)
        27 => color.new(#49ED12 , 90)
        28 => color.new(#4BF609 , 90)
        29 => color.new(#4DFF00 , 90)
        30 => color.new(#53FF00 , 90)
        31 => color.new(#59FF00 , 90)
        32 => color.new(#5FFE00 , 90)
        33 => color.new(#65FE00 , 90)
        34 => color.new(#6BFE00 , 90)
        35 => color.new(#71FE00 , 90)
        36 => color.new(#77FD00 , 90)
        37 => color.new(#7DFD00 , 90)
        38 => color.new(#82FD00 , 90)
        39 => color.new(#88FD00 , 90)
        40 => color.new(#8EFC00 , 90)
        41 => color.new(#94FC00 , 90)
        42 => color.new(#9AFC00 , 90)
        43 => color.new(#A0FB00 , 90)
        44 => color.new(#A6FB00 , 90)
        45 => color.new(#ACFB00 , 90)
        46 => color.new(#B2FB00 , 90)
        47 => color.new(#B8FA00 , 90)
        48 => color.new(#BEFA00 , 90)
        49 => color.new(#C4FA00 , 90)
        50 => color.new(#CAF900 , 90)
        51 => color.new(#D0F900 , 90)
        52 => color.new(#D5F900 , 90)
        53 => color.new(#DBF900 , 90)
        54 => color.new(#E1F800 , 90)
        55 => color.new(#E7F800 , 90)
        56 => color.new(#EDF800 , 90)
        57 => color.new(#F3F800 , 90)
        58 => color.new(#F9F700 , 90)
        59 => color.new(#FFF700 , 90)
        60 => color.new(#FFEE00 , 90)
        61 => color.new(#FFE600 , 90)
        62 => color.new(#FFDE00 , 90)
        63 => color.new(#FFD500 , 90)
        64 => color.new(#FFCD00 , 90)
        65 => color.new(#FFC500 , 90)
        66 => color.new(#FFBD00 , 90)
        67 => color.new(#FFB500 , 90)
        68 => color.new(#FFAC00 , 90)
        69 => color.new(#FFA400 , 90)
        70 => color.new(#FF9C00 , 90)
        71 => color.new(#FF9400 , 90)
        72 => color.new(#FF8C00 , 90)
        73 => color.new(#FF8300 , 90)
        74 => color.new(#FF7B00 , 90)
        75 => color.new(#FF7300 , 90)
        76 => color.new(#FF6B00 , 90)
        77 => color.new(#FF6200 , 90)
        78 => color.new(#FF5A00 , 90)
        79 => color.new(#FF5200 , 90)
        80 => color.new(#FF4A00 , 90)
        81 => color.new(#FF4200 , 90)
        82 => color.new(#FF3900 , 90)
        83 => color.new(#FF3100 , 90)
        84 => color.new(#FF2900 , 90)
        85 => color.new(#FF2100 , 90)
        86 => color.new(#FF1900 , 90)
        87 => color.new(#FF1000 , 90)
        88 => color.new(#FF0800 , 90)
        89 => color.new(#FF0000 , 90)
        90 => color.new(#F60000 , 90)
        91 => color.new(#DF0505 , 90)
        92 => color.new(#C90909 , 90)
        93 => color.new(#B20E0E , 90)
        94 => color.new(#9B1313 , 90)
        95 => color.new(#851717 , 90)
        96 => color.new(#6E1C1C , 90)
        97 => color.new(#572121 , 90)
        98 => color.new(#412525 , 90)
        99 => color.new(#2A2A2A , 90)
        100 => color.new(#220027 , 90)
    out
length = input.int(20)
source = input.source(close)
_1 = plot(ta.percentile_nearest_rank(source, length, 0), color = color.new(color.white, 100))
_2 = plot(ta.percentile_nearest_rank(source, length, 2), color = color.new(color.white, 100))
fill(_1, _2, color = grad(1))
_3 = plot(ta.percentile_nearest_rank(source, length, 4), color = color.new(color.white, 100))
fill(_2, _3, color = grad(3))
_4 = plot(ta.percentile_nearest_rank(source, length, 6), color = color.new(color.white, 100))
fill(_3, _4, color = grad(5))
_5 = plot(ta.percentile_nearest_rank(source, length, 8), color = color.new(color.white, 100))
fill(_4, _5, color = grad(7))
_6 = plot(ta.percentile_nearest_rank(source, length, 10), color = color.new(color.white, 100))
fill(_5,_6, color = grad(9))
_7 = plot(ta.percentile_nearest_rank(source, length, 12), color = color.new(color.white, 100))
fill(_6,_7, color = grad(11))
_8 = plot(ta.percentile_nearest_rank(source, length, 14), color = color.new(color.white, 100))
fill(_7,_8, color = grad(13))
_9 = plot(ta.percentile_nearest_rank(source, length, 16), color = color.new(color.white, 100))
fill(_8,_9, color = grad(15))
_10 = plot(ta.percentile_nearest_rank(source, length, 18), color = color.new(color.white, 100))
fill(_9,_10, color = grad(17))
_11 = plot(ta.percentile_nearest_rank(source, length, 20), color = color.new(color.white, 100))
fill(_10,_11, color = grad(19))
_12 = plot(ta.percentile_nearest_rank(source, length, 22), color = color.new(color.white, 100))
fill(_11,_12, color = grad(21))
_13 = plot(ta.percentile_nearest_rank(source, length, 24), color = color.new(color.white, 100))
fill(_12,_13, color = grad(23))
_14 = plot(ta.percentile_nearest_rank(source, length, 26), color = color.new(color.white, 100))
fill(_13,_14, color = grad(25))
_15 = plot(ta.percentile_nearest_rank(source, length, 28), color = color.new(color.white, 100))
fill(_14,_15, color = grad(27))
_16 = plot(ta.percentile_nearest_rank(source, length, 30), color = color.new(color.white, 100))
fill(_15,_16, color = grad(29))
_17 = plot(ta.percentile_nearest_rank(source, length, 32), color = color.new(color.white, 100))
fill(_16,_17, color = grad(31))
_18 = plot(ta.percentile_nearest_rank(source, length, 34), color = color.new(color.white, 100))
fill(_17,_18, color = grad(33))
_19 = plot(ta.percentile_nearest_rank(source, length, 36), color = color.new(color.white, 100))
fill(_18,_19, color = grad(35))
_20 = plot(ta.percentile_nearest_rank(source, length, 38), color = color.new(color.white, 100))
fill(_19,_20, color = grad(37))
_21 = plot(ta.percentile_nearest_rank(source, length, 40), color = color.new(color.white, 100))
fill(_20,_21, color = grad(39))
_22 = plot(ta.percentile_nearest_rank(source, length, 42), color = color.new(color.white, 100))
fill(_21,_22, color = grad(41))
_23 = plot(ta.percentile_nearest_rank(source, length, 44), color = color.new(color.white, 100))
fill(_22,_23, color = grad(43))
_24 = plot(ta.percentile_nearest_rank(source, length, 46), color = color.new(color.white, 100))
fill(_23,_24, color = grad(45))
_25 = plot(ta.percentile_nearest_rank(source, length, 48), color = color.new(color.white, 100))
fill(_24,_25, color = grad(49))
_26 = plot(ta.percentile_nearest_rank(source, length, 50), color = color.new(color.white, 100))
fill(_25,_26, color = grad(51))
_27 = plot(ta.percentile_nearest_rank(source, length, 52), color = color.new(color.white, 100))
fill(_26,_27, color = grad(53))
_28 = plot(ta.percentile_nearest_rank(source, length, 54), color = color.new(color.white, 100))
fill(_27,_28, color = grad(55))
_29 = plot(ta.percentile_nearest_rank(source, length, 56), color = color.new(color.white, 100))
fill(_28,_29, color = grad(57))
_30 = plot(ta.percentile_nearest_rank(source, length, 58), color = color.new(color.white, 100))
fill(_29,_30, color = grad(59))
_31 = plot(ta.percentile_nearest_rank(source, length, 60), color = color.new(color.white, 100))
fill(_30,_31, color = grad(61))
_32 = plot(ta.percentile_nearest_rank(source, length, 62), color = color.new(color.white, 100))
fill(_31,_32, color = grad(63))
_33 = plot(ta.percentile_nearest_rank(source, length, 64), color = color.new(color.white, 100))
fill(_32,_33, color = grad(65))
_34 = plot(ta.percentile_nearest_rank(source, length, 66), color = color.new(color.white, 100))
fill(_33,_34, color = grad(67))
_35 = plot(ta.percentile_nearest_rank(source, length, 68), color = color.new(color.white, 100))
fill(_34,_35, color = grad(69))
_36 = plot(ta.percentile_nearest_rank(source, length, 70), color = color.new(color.white, 100))
fill(_35,_36, color = grad(71))
_37 = plot(ta.percentile_nearest_rank(source, length, 72), color = color.new(color.white, 100))
fill(_36,_37, color = grad(73))
_38 = plot(ta.percentile_nearest_rank(source, length, 74), color = color.new(color.white, 100))
fill(_37,_38, color = grad(75))
_39 = plot(ta.percentile_nearest_rank(source, length, 76), color = color.new(color.white, 100))
fill(_38,_39, color = grad(77))
_40 = plot(ta.percentile_nearest_rank(source, length, 78), color = color.new(color.white, 100))
fill(_39,_40, color = grad(79))
_41 = plot(ta.percentile_nearest_rank(source, length, 80), color = color.new(color.white, 100))
fill(_40,_41, color = grad(81))
_42 = plot(ta.percentile_nearest_rank(source, length, 82), color = color.new(color.white, 100))
fill(_41,_42, color = grad(83))
_43 = plot(ta.percentile_nearest_rank(source, length, 84), color = color.new(color.white, 100))
fill(_42,_43, color = grad(85))
_44 = plot(ta.percentile_nearest_rank(source, length, 86), color = color.new(color.white, 100))
fill(_43,_44, color = grad(87))
_45 = plot(ta.percentile_nearest_rank(source, length, 88), color = color.new(color.white, 100))
fill(_44,_45, color = grad(89))
_46 = plot(ta.percentile_nearest_rank(source, length, 90), color = color.new(color.white, 100))
fill(_45,_46, color = grad(91))
_47 = plot(ta.percentile_nearest_rank(source, length, 92), color = color.new(color.white, 100))
fill(_46,_47, color = grad(93))
_48 = plot(ta.percentile_nearest_rank(source, length, 94), color = color.new(color.white, 100))
fill(_47,_48, color = grad(95))
_49 = plot(ta.percentile_nearest_rank(source, length, 96), color = color.new(color.white, 100))
fill(_48,_49, color = grad(97))
_50 = plot(ta.percentile_nearest_rank(source, length, 98), color = color.new(color.white, 100))
fill(_49,_50, color = grad(99))
_51 = plot(ta.percentile_nearest_rank(source, length, 100), color = color.new(color.white, 100))
fill(_50,_51, color = grad(100))