please bear with me , as i ask some questions, to help clarify your request.
i am confused by gradient. gradient implies 1 thing changing, as in 1 line changing to many colors.
but i think you want 5 lines, each one a different SHADE of red or green.
why didn't you post the code for fig.1, then we would have a starting point with your settings?
what are your preferred default settings for the averages? length, type
if fig.4 is what you want, why not use it?
if fig.4 is close to what you want, then why didn't you post the code for it, for others to have a starting point?
-----------------------
here are the links you mentioned
Madrid Moving Average Ribbons for ThinkorSwim , by Xiuying
https://usethinkscript.com/threads/madrid-moving-average-ribbons-for-thinkorswim.3122/
MovAvgExpRibbon
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExpRibbon
-----------------------
i copied that madrid study and modified it.
you didn't mention any of your settings, so i guessed at average lengths. 10,25,40,55,70
i added average formulas and parameters for 5. can choose type and length.
this isn't quite what you asked for, but hopefully it is a starting point.
i don't understand the purpose of having a bunch of similarly color shaded lines, starting and stopping at the same bar. might as well just have 1 line.
i think it gives more information to see line colors changing independently. to see 1 or 2 change color, to indicate something might happen soon.
i kept the plot color rules from the madrid study. it checks the price change of each line, bar to bar, and compares the shortest length average to the longest one. from those 2 conditions, it creates 4 color possibilities ( + flat).
line colors,
green , short length is moving up , line change is up
blue , short length is moving up , line change is down
gray , price changes are the same
yellow , short length is moving down , line change is up
red , short length is moving down , line change is down
there are 5 labels, one for each line, that
..match the color of the line
..describe the type and length of the average ( EMA10 )
Ruby:
# avg_ribbon_5x_colors_00
# Q
#https://usethinkscript.com/threads/a-5-ma-ribbon-with-dynamic-trend-based-coloring.12983/
# ref - copy the line color rules from here
# https://usethinkscript.com/threads/madrid-moving-average-ribbons-for-thinkorswim.3122/
# Madrid Moving Average Ribbons for ThinkorSwim
def na = Double.NaN;
def bn = BarNumber();
# last bar ( most recent)
#def lastbar = !isnan(close[0]) and isnan(close[-1]);
# up , up_rev , down_rev , down
DefineGlobalColor("up", color.green);
DefineGlobalColor("up_rev", color.blue);
DefineGlobalColor("flat", color.gray);
DefineGlobalColor("down_rev", color.yellow);
DefineGlobalColor("down", color.red);
# GlobalColor("up")
# GlobalColor("up_rev")
# GlobalColor("flat")
# GlobalColor("down_rev")
# GlobalColor("down")
#-------------------------
# ma1 should be the shortest length average
# ma5 should be the longest length average
def price = close;
input ma1_len = 10;
input ma1_type = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
input ma2_len = 25;
input ma2_type = AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);
input ma3_len = 40;
input ma3_type = AverageType.EXPONENTIAL;
def ma3 = MovingAverage(ma3_type, price, ma3_len);
input ma4_len = 55;
input ma4_type = AverageType.EXPONENTIAL;
def ma4 = MovingAverage(ma4_type, price, ma4_len);
input ma5_len = 70;
input ma5_type = AverageType.EXPONENTIAL;
def ma5 = MovingAverage(ma5_type, price, ma5_len);
#def up1 = (ma1 crosses above ma5);
#def dwn1 = (ma1 crosses below ma5);
#---------------------------
input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
#z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();
#z1.SetStyle(Curve.MEDIUM_DASH);
plot z2 = if show_lines then ma2 else na;
#z2.SetDefaultColor(GetColor(2));
#z2.setlineweight(1);
z2.HideBubble();
plot z3 = if show_lines then ma3 else na;
#z3.SetDefaultColor(GetColor(3));
#z3.setlineweight(1);
z3.HideBubble();
plot z4 = if show_lines then ma4 else na;
#z4.SetDefaultColor(GetColor(4));
#z4.setlineweight(1);
z4.HideBubble();
plot z5 = if show_lines then ma5 else na;
#z4.SetDefaultColor(GetColor(5));
#z4.setlineweight(1);
z4.HideBubble();
#----------------------------
z1.AssignValueColor(
if ma1 > ma1[1] and ma1 > ma5 then GlobalColor("up")
else if ma1 < ma1[1] and ma1 > ma5 then GlobalColor("up_rev")
else if ma1 < ma1[1] and ma1 < ma5 then GlobalColor("down")
else if ma1 > ma1[1] and ma1 < ma5 then GlobalColor("down_rev")
else GlobalColor("flat"));
z2.AssignValueColor(
if ma2 > ma2[1] and ma1 > ma5 then GlobalColor("up")
else if ma2 < ma2[1] and ma1 > ma5 then GlobalColor("up_rev")
else if ma2 < ma2[1] and ma1 < ma5 then GlobalColor("down")
else if ma2 > ma2[1] and ma1 < ma5 then GlobalColor("down_rev")
else GlobalColor("flat"));
z3.AssignValueColor(
if ma3 > ma3[1] and ma1 > ma5 then GlobalColor("up")
else if ma3 < ma3[1] and ma1 > ma5 then GlobalColor("up_rev")
else if ma3 < ma3[1] and ma1 < ma5 then GlobalColor("down")
else if ma3 > ma3[1] and ma1 < ma5 then GlobalColor("down_rev")
else GlobalColor("flat"));
z4.AssignValueColor(
if ma4 > ma4[1] and ma1 > ma5 then GlobalColor("up")
else if ma4 < ma4[1] and ma1 > ma5 then GlobalColor("up_rev")
else if ma4 < ma4[1] and ma1 < ma5 then GlobalColor("down")
else if ma4 > ma4[1] and ma1 < ma5 then GlobalColor("down_rev")
else GlobalColor("flat"));
z5.AssignValueColor(
if ma5 > ma5[1] and ma1 > ma5 then GlobalColor("up")
else if ma5 < ma5[1] and ma1 > ma5 then GlobalColor("up_rev")
else if ma5 < ma5[1] and ma1 < ma5 then GlobalColor("down")
else if ma5 > ma5[1] and ma1 < ma5 then GlobalColor("down_rev")
else GlobalColor("flat"));
#----------------------------
# labels
#input ma1_len = 10;
#input ma1_type = AverageType.EXPONENTIAL;
input show_labels = yes;
addlabel(show_labels,
(if ma1_type == AverageType.simple then "MA"
else if ma1_type == AverageType.EXPONENTIAL then "EMA"
else if ma1_type == AverageType.hull then "HULL"
else if ma1_type == AverageType.WEIGHTED then "WT"
else if ma1_type == AverageType.WILDERS then "WILD"
else "-") + ma1_len
, z1.TakeValueColor());
addlabel(show_labels,
(if ma2_type == AverageType.simple then "MA"
else if ma2_type == AverageType.EXPONENTIAL then "EMA"
else if ma2_type == AverageType.hull then "HULL"
else if ma2_type == AverageType.WEIGHTED then "WT"
else if ma2_type == AverageType.WILDERS then "WILD"
else "-") + ma2_len
, z2.TakeValueColor());
addlabel(show_labels,
(if ma3_type == AverageType.simple then "MA"
else if ma3_type == AverageType.EXPONENTIAL then "EMA"
else if ma3_type == AverageType.hull then "HULL"
else if ma3_type == AverageType.WEIGHTED then "WT"
else if ma3_type == AverageType.WILDERS then "WILD"
else "-") + ma3_len
, z3.TakeValueColor());
addlabel(show_labels,
(if ma4_type == AverageType.simple then "MA"
else if ma4_type == AverageType.EXPONENTIAL then "EMA"
else if ma4_type == AverageType.hull then "HULL"
else if ma4_type == AverageType.WEIGHTED then "WT"
else if ma4_type == AverageType.WILDERS then "WILD"
else "-") + ma4_len
, z4.TakeValueColor());
addlabel(show_labels,
(if ma5_type == AverageType.simple then "MA"
else if ma5_type == AverageType.EXPONENTIAL then "EMA"
else if ma5_type == AverageType.hull then "HULL"
else if ma5_type == AverageType.WEIGHTED then "WT"
else if ma5_type == AverageType.WILDERS then "WILD"
else "-") + ma5_len
, z5.TakeValueColor());
#--------------------------
# ref
#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage
# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
# ..AverageTypes..
# EXPONENTIAL
# HULL
# SIMPLE
# WEIGHTED
# WILDERS
#
showing different average types
-----------------------
sites for picking colors
pick 2 colors and a quantity and generate a list of colors between them
https://colordesigner.io/gradient-generator
https://www.w3schools.com/colors/colors_picker.asp