AutoColor
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dmdman
//@version=5
//testing new version features...

// @description Function provides rgb color based on deviation of highest and lowest value for the period from current value
library("AutoColor", overlay = true)

// @function Calculates rgb color based on deviation of highest and lowest value for the period from current value  
// @param src1 Series to use (`close` is used if no argument is supplied).
// @param len1 Length for highest and lowest series (`10` is used if no argument is supplied).
// @returns color for series
export fColor(float src1 = close, int len1 = 10) =>
    float libHi = ta.highest(src1,len1)
    float libLo = ta.lowest(src1,len1)
    float flt1 = (src1-libLo)/(libHi-libLo)
    color out = color.rgb(255*(1-flt1),255*flt1,0)
    out

plot(series = hl2,linewidth = 3,color=fColor(hl2,40))

