sorry, i still don't understand what you are asking for.
your post 3 has many words, but most of them don't help to describe what you want.
after the first 3 sentences, nothing makes sense, nothing is of any use for guessing at what you want.
i have no idea what i am supposed to learn from looking at those pictures.
i make posts like this , not to be mean, but to try to give people feedback on their poor communication. to hopefully get them to rethink logically how to describe their issue.
think about,
where do you want to see something,
what do you want to see,
when do you want to see it,
where do you want to see something,
. chart
what do you want to see,
. horizontal lines, from high and low of a candle, extending for 20 bars
when do you want to see it,
. starting on first bar that this is true , sma80 > sma40 and Close > sma 80.
. same for opposite conditions
---------------------
i went ahead and guessed at something, based on post 1 conditions.
on the first bar that this is true,
.. sma80 > sma40 and Close > sma 80 (and for the opposite conditions)
it starts drawing a line from the high and low.
it draws 2 lines for 20 bars.
if a line is being drawn, another line will not start during it.
Code:
#lines_at_avgaboveavg
#https://usethinkscript.com/threads/help-drawing-line.18048/
#Help drawing line
#Drmoh1800 2/23
#I am trying to do this scipt of some one can help me to add line at high
#Sma80>sma40
#Close > sma 80
#To draw line at high of this candle extended for 20 candles
#Similar to down side
#Sma 80< sma 40
#Close < sma 80
#I want to draw line at low of this candle extended maybe 20 candles
def na = double.nan;
def bn = barnumber();
def data = close;
input length = 20;
#input avg1_type = AverageType.exponential;
input avg1_type = AverageType.Simple;
input avg1_length = 40;
def avg1 = MovingAverage(avg1_type, data, avg1_length );
input avg2_type = AverageType.Simple;
input avg2_length = 80;
def avg2 = MovingAverage(avg2_type, data, avg2_length );
input avg3_type = AverageType.Simple;
input avg3_length = 160;
def avg3 = MovingAverage(avg3_type, data, avg3_length );
input avg4_type = AverageType.Simple;
input avg4_length = 320;
def avg4 = MovingAverage(avg4_type, data, avg4_length );
input show_average_lines = yes;
plot zavg1 = if show_average_lines then avg1 else na;
plot zavg2 = if show_average_lines then avg2 else na;
#plot zavg3 = if show_average_lines then avg3 else na;
#plot zavg4 = if show_average_lines then avg4 else na;
zavg1.SetDefaultColor(getcolor(2));
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(getcolor(3));
zavg2.setlineweight(1);
zavg2.hidebubble();
#-------
def up1 = avg2 > avg1;
def up2 = close > avg2;
def up = up1 and up2;
def upfirst = !up[1] and up;
def upcnt = if bn == 1 then 0
else if upcnt[1] > 0 then upcnt[1] - 1
else if upfirst then length
else 0;
def upsignal = upcnt == length;
#-------
def uplinetop = if bn == 1 then na
else if upsignal then high
else if upcnt > 0 then uplinetop[1]
else na;
plot zuphi = uplinetop;
zuphi.setdefaultcolor(color.cyan);
def uplinebot = if bn == 1 then na
else if upsignal then low
else if upcnt > 0 then uplinebot[1]
else na;
plot zuplo = uplinebot;
zuplo.setdefaultcolor(color.cyan);
#===================
def dwn1 = avg2 < avg1;
def dwn2 = close < avg2;
def dwn = dwn1 and dwn2;
def dwnfirst = !dwn[1] and dwn;
def dwncnt = if bn == 1 then 0
else if dwncnt[1] > 0 then dwncnt[1] - 1
else if dwnfirst then length
else 0;
def dwnsignal = dwncnt == length;
#-------
def dwnlinetop = if bn == 1 then na
else if dwnsignal then high
else if dwncnt > 0 then dwnlinetop[1]
else na;
plot zdwnhi = dwnlinetop;
zdwnhi.setdefaultcolor(color.yellow);
def dwnlinebot = if bn == 1 then na
else if dwnsignal then low
else if dwncnt > 0 then dwnlinebot[1]
else na;
plot zdwnlo = dwnlinebot;
zdwnlo.setdefaultcolor(color.yellow);
#------------------
def test_bub = no;
addchartbubble(test_bub,low,
upcnt
, (if upcnt > 0 then color.cyan else color.gray), no);
addchartbubble(test_bub,low,
dwncnt
, (if dwncnt > 0 then color.yellow else color.gray), no);
def test_lines = 0;
#addverticalline( test_lines and up1 or up2, "-");
addverticalline( test_lines and upfirst, "-", color.cyan);
addverticalline( test_lines and upsignal, "-", color.green);
#addverticalline( dwnfirst, "-", color.red);
#