Support/Resistance that ends once touched

Department

New member
Hello,
I was wondering if someone knew how to code a price level that starts and ends on a condition? I have certain bars I'd like to trigger a price level. This level would then stop at the point were price touched it again.
My current code is below with the level indicated but I don't know how to make the line appear and only extend to the next time that price is touched.
Code:
input history = 10;
input multiplier = 1.5;

def highLow = high - low;
def body = bodyHeight();
def greenCandle = open < close;
def redCandle = close < open;
def volatility = atr(history);
def significantBar = volatility * multiplier;
def imBody = (body > highLow* 0.5) and (highLow >= significantBar);

assignPriceColor(if imBody and greenCandle then Color.dark_green else Color.Current);
assignPriceColor(if imBody and redCandle then Color.dark_red else Color.Current);

#These would be the price levels drawn on the chart.
#They start at the previous candle's high/low and end once price returns to that price.
#Green Candles
plot supportLevel = if imBody and greenCandle then high[1] else double.NaN;
supportLevel.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

#Red Candles
plot resistenceLevel = if imBody and redCandle then low[1] else double.NaN;
resistenceLevel.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

This would ideally result in a graph as shown below:
cRJfU42.png
 
Solution
Updated the code for this indicator to make better use of the plots.
I made it way to complicated the first time around, I blame lack of sleep.

Also added a basic strategy to buy and sell on bar open after signal bar,
and added more plots. (My kingdom for an array.....😩..lol).

@Stock Tradin, I would appreciate some more feed back from you as I'm not a chart/data analyst by any means.
I'm a coder, that's what I know, so that's what I do....
and it doesn't look like we will be hearing from @Department any time soon.
Also working on a script to buy 1 and sell 1 after every opposite bar and set multiple stops (sell 1 or buy 1) at the corresponding price levels.
Code:
#Support and Reisitance Lines That End When Price Returns to...
Updated the code in post #16.
Noticed some bugs in the plotting. (Really... is an array in thinkscript too much to ask for).
So here are couple things I would like you to re-visit.

#1 Could you possibly add "Style" for the lines that I could use? as an example see picture

#2 I personally found the extended lines were extremely huge help and great info!!! Awesome job on that.
#3 The buy and sell points, they really dont work that well in live trading because they repaint
#4 the lines going from buy n sell signals really bothered me, but again, that's just my personal opinion and if anyone wants to use them you coded the values to change that....
#5 are you talking about the bug where after saving the values and restarting TOS the next day, nothing was saved ? Because that's what I was getting and can't figure out why? Like the Buy and Sell enabled/disabled always returned to enabled.....every time I restarted the TOS.
 
@Stock Tradin
#1 Could you possibly add "Style" for the lines that I could use? as an example see picture
Will look at updating.

#3 The buy and sell points, they really dont work that well in live trading because they repaint
The signals do not repaint.
The buy/sell arrows plot on the bar after the signal bar.

What you are experiencing is a possible signal without confirmation.
Signals are confirmed at the close of a bar and stay in the direction of the signal.
You should always wait until bar close and enter a trade on the open of the following bar.

Repainting is the signals of past bars changing based on later bars.

#4 the lines going from buy n sell signals really bothered me, but again, that's just my personal opinion and if anyone wants to use them you coded the values to change that....
You can remove the four lines of AddOrder code and save it as a study.
That will remove the lines


#5 are you talking about the bug where after saving the values and restarting TOS the next day, nothing was saved ? Because that's what I was getting and can't figure out why? Like the Buy and Sell enabled/disabled always returned to enabled.....every time I restarted the TOS.
Have not experienced this bug.

The bug I had noticed was sometimes plots were reused out of order and made them quit plotting their earlier values sooner.
Code has been updated to fix that.
 
@Stock Tradin

Will look at updating.


The signals do not repaint.
The buy/sell arrows plot on the bar after the signal bar.

What you are experiencing is a possible signal without confirmation.
Signals are confirmed at the close of a bar and stay in the direction of the signal.
You should always wait until bar close and enter a trade on the open of the following bar.

Repainting is the signals of past bars changing based on later bars.


You can remove the four lines of AddOrder code and save it as a study.
That will remove the lines



Have not experienced this bug.

The bug I had noticed was sometimes plots were reused out of order and made them quit plotting their earlier values sooner.
Code has been updated to fix that.
Awesome!! I will take a look again what I said about repainting........I was recording my trades today but somehow I got an error and couldn't review the video to see exactly how the indicator acted. But I realllly enjoyed the extended lines.....excellent idea and execution sir.....Thank you
 
@Stock Tradin
Updated code in post #16 again.
-Changed painting strategy to SetStyle( Curve.Points);. (Not able to make this an input variable to change, had to hard code it.)
-Another plotting bug fix.

@naquan24
I could change the greenbar plot to open of the greenbar, but I cannot change the redbar plot to to close of the redbar as the open
of the next bar is equal to that plot and counts as a touch which ends the plot.

The Mobius Supply and Demand Zones Support and Resistance Script you asked about in another thread may be a good complimentary study for this one.

It may also help answer @Stock Tradin question of "WHEN".
 
Last edited:
@Stock Tradin
Updated code in post #16 again.
-Changed painting strategy to SetStyle( Curve.Points);. (Not able to make this an input variable to change, had to hard code it.)
-Another plotting bug fix.

@naquan24
I could change the greenbar plot to open of the greenbar, but I cannot change the redbar plot to to close of the redbar as the open
of the next bar is equal to that plot and counts as a touch which ends the plot.

The Mobius Supply and Demand Zones Support and Resistance Script you asked about in another thread may be a good complimentary study for this one.

It may also help answer @Stock Tradin question of "WHEN".
Excellent....I like it!! Thank you sir....
 
Yes it will....here is an example: Stock AVYA on 1H chart....on Nov 25th, 2020 you took a trade at $18.11 and held it till Oct 26 2021 to be filled!!! The stock went up to HOD being $34.06 !!!!! But who knew right?????? That's money makers for ya.....

To be honest, I personally do not keep stocks over night ever...I am a day trader and I mostly trade from market open to about 12PM......after that, I found the market to be too slow/lazy and a few times I took trades around 2, 3 or even 4PM, I found myself holding them to After Hours and had to manually close them for a loss....therefore, I am not taking any trades after 12 and I do not hold trades over night because my experience gives me nothing but bad luck.

Anyways...you have to find the range of the stock that its trading within.....like the one above, it's within $2 or so.....so if you gonna day trade you basically analyze the stock and see where the lines are and hopefully it will hit them lines you've created/modified. I cant tell you when KSCP will get there....heck, it might be even delisted??????? You never know, but there will be a lot of companies with a lot of losses along with the Market Makers, who thrive on orders and make money on those lines that the automatically draws. The stock is brand new, a newborn.....I personally dont believe it will be delisted or cancelled, but any day, news might come out, a good report/budget/earnings etc....it might skyrocket it to $50 a share!!!

Again, I do not know when or even if that might happen, but please review any stock on the market with the great indicator you've created and you'll see that you just cant argue with history.....

I hope this answered your questions?
 
Fixed another plotting bug and removed strategy for now to reduce load time.

Ruby:
#Support and Reisitance Lines That End When Price Returns to Line.
#Original idea by Department
#Coded by Svanoy
#https://usethinkscript.com/threads/support-resistance-that-ends-once-touched.9491/#post-89067

######################################################################################
#Definition of Signal.################################################################
######################################################################################

input history = 10;
input multiplier = 1.5;
input bsmulti =1.2;
def highLow = high-low;
def buyopenlow = open-low;
def sellhighopen = high-open;
def greenCandle = open < close;
def redCandle = close < open;
def body = BodyHeight();
def volatility = ATR(history, AverageType.WILDERS);
def significantBar = volatility * multiplier;
def imBody = (body > highLow * 0.5) and (highLow >= significantBar);
def buybody = (body > buyopenLow * 0.5) and (buyopenLow >= volatility * bsmulti);
def sellbody = (body > sellhighopen * 0.5) and (sellhighopen >= volatility * bsmulti);
AssignPriceColor(if imBody and greenCandle then Color.LIME else Color.CURRENT);
AssignPriceColor(if imBody and redCandle then Color.DARK_RED else Color.CURRENT);

plot Bottom = buyBody and greenCandle;
Bottom.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
Bottom.SetLineWeight(5);
Bottom.AssignValueColor(Color.CYAN );

plot Top = sellBody and redCandle;
Top.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
Top.SetLineWeight(5);
Top.AssignValueColor(Color.LIGHT_ORANGE);

#######################################################################################
#Define Level Plot Triggers..##########################################################
#######################################################################################
def RedBar = imBody and redCandle ;#and low[1]>close;
def GreenBar = imBody and greenCandle ;#and high[1]<close;

######################################################################################
#Defintions of Support Levels.########################################################
######################################################################################
plot SupportLevel = if GreenBar then high[1] else Double.NaN;
SupportLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def SLine0;
def SLine1;
def SLine2;
def SLine3;
def SLine4;
def SLine5;
def SLine6;
def SLine7;
def SLine8;
def SLine9;
def SLine10;
def SLine11;
def SLine12;
def SLine13;
def SLine14;
def SLine15;
def SLine16;
def SLine17;
def SLine18;
def SLine19;
def SLine20;

def SLineCount;
If BarNumber() == 1 { SLineCount = 1;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine1[1]) and low<=SLine1[1]) { SLineCount=0;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine2[1]) and low<=SLine2[1]) { SLineCount=1;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine3[1]) and low<=SLine3[1]) { SLineCount=2;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine4[1]) and low<=SLine4[1]) { SLineCount=3;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine5[1]) and low<=SLine5[1]) { SLineCount=4;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine6[1]) and low<=SLine6[1]) { SLineCount=5;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine7[1]) and low<=SLine7[1]) { SLineCount=6;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine8[1]) and low<=SLine8[1]) { SLineCount=7;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine9[1]) and low<=SLine9[1]) { SLineCount=8;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine10[1]) and low<=SLine10[1]) { SLineCount=9;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine11[1]) and low<=SLine11[1]) { SLineCount=10;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine12[1]) and low<=SLine12[1]) { SLineCount=11;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine13[1]) and low<=SLine13[1]) { SLineCount=12;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine14[1]) and low<=SLine14[1]) { SLineCount=13;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine15[1]) and low<=SLine15[1]) { SLineCount=14;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine16[1]) and low<=SLine16[1]) { SLineCount=15;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine17[1]) and low<=SLine17[1]) { SLineCount=16;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine18[1]) and low<=SLine18[1]) { SLineCount=17;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine19[1]) and low<=SLine19[1]) { SLineCount=18;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine20[1]) and low<=SLine20[1]) { SLineCount=19;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine0[1]) and low<=SLine0[1]) { SLineCount=20;

}else if (!IsNaN(SupportLevel) and !IsNaN(SLine0[1]) and low<=SLine0[1]) { SLineCount=0;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine1[1]) and low<=SLine1[1]) { SLineCount=1;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine2[1]) and low<=SLine2[1]) { SLineCount=2;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine3[1]) and low<=SLine3[1]) { SLineCount=3;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine4[1]) and low<=SLine4[1]) { SLineCount=4;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine5[1]) and low<=SLine5[1]) { SLineCount=5;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine6[1]) and low<=SLine6[1]) { SLineCount=6;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine7[1]) and low<=SLine7[1]) { SLineCount=7;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine8[1]) and low<=SLine8[1]) { SLineCount=8;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine9[1]) and low<=SLine9[1]) { SLineCount=9;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine10[1]) and low<=SLine10[1]) { SLineCount=10;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine11[1]) and low<=SLine11[1]) { SLineCount=11;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine12[1]) and low<=SLine12[1]) { SLineCount=12;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine13[1]) and low<=SLine13[1]) { SLineCount=13;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine14[1]) and low<=SLine14[1]) { SLineCount=14;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine15[1]) and low<=SLine15[1]) { SLineCount=15;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine16[1]) and low<=SLine16[1]) { SLineCount=16;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine17[1]) and low<=SLine17[1]) { SLineCount=17;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine18[1]) and low<=SLine18[1]) { SLineCount=18;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine19[1]) and low<=SLine19[1]) { SLineCount=19;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine20[1]) and low<=SLine20[1]) { SLineCount=20;
}else if (!IsNaN(SupportLevel)) and SLineCount[1]!=20 { SLineCount = SLineCount[1] + 1;
}else if (IsNaN(SupportLevel)) and SLineCount[1]==20 { SLineCount = 0;
} else {
    SLineCount = SLineCount[1];
}

#green candles
######################################################################################
#Plots of Support Levels.#############################################################
######################################################################################
SLine0 = if !IsNaN(SupportLevel) and SLineCount == 0 then SupportLevel else if !IsNaN(SLine0[1]) and low <= SLine0[1] then 0 else SLine0[1];
plot SLineP0 = if SLine0 > 0 then SLine0 else Double.NaN;
SLineP0.SetStyle(Curve.POINTS);
SLineP0.SetDefaultColor(Color.LIGHT_GREEN);
SLineP0.SetLineWeight(1);
SLineP0.HideBubble();
#----------------------------------------------------------------------------------
SLine1 = if !IsNaN(SupportLevel) and SLineCount == 1 then SupportLevel else if !IsNaN(SLine1[1]) and low <= SLine1[1] then 0 else SLine1[1];
plot SLineP1 = if SLine1 > 0 then SLine1 else Double.NaN;
SLineP1.SetStyle(Curve.POINTS);
SLineP1.SetDefaultColor(Color.LIGHT_GREEN);
SLineP1.SetLineWeight(1);
SLineP1.HideBubble();
#----------------------------------------------------------------------------------
SLine2 = if !IsNaN(SupportLevel) and SLineCount == 2 then SupportLevel else if !IsNaN(SLine2[1]) and low <= SLine2[1] then 0 else SLine2[1];
plot SLineP2 = if SLine2 > 0 then SLine2 else Double.NaN;
SLineP2.SetStyle(Curve.POINTS);
SLineP2.SetDefaultColor(Color.LIGHT_GREEN);
SLineP2.SetLineWeight(1);
SLineP2.HideBubble();
#----------------------------------------------------------------------------------
SLine3 = if !IsNaN(SupportLevel) and SLineCount == 3 then SupportLevel else if !IsNaN(SLine3[1]) and low <= SLine3[1] then 0 else SLine3[1];
plot SLineP3 = if SLine3 > 0 then SLine3 else Double.NaN;
SLineP3.SetStyle(Curve.POINTS);
SLineP3.SetDefaultColor(Color.LIGHT_GREEN);
SLineP3.SetLineWeight(1);
SLineP3.HideBubble();
#----------------------------------------------------------------------------------
SLine4 = if !IsNaN(SupportLevel) and SLineCount == 4 then SupportLevel else if !IsNaN(SLine4[1]) and low <= SLine4[1] then 0 else SLine4[1];
plot SLineP4 = if SLine4 > 0 then SLine4 else Double.NaN;
SLineP4.SetStyle(Curve.POINTS);
SLineP4.SetDefaultColor(Color.LIGHT_GREEN);
SLineP4.SetLineWeight(1);
SLineP4.HideBubble();
def SLine4Length = if SLine4 != SLine4[1] then 1 else if !IsNaN(SLine4[1]) and IsNaN(SLine4) then 0 else if !IsNaN(SLine4) then SLine4Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
SLine5 = if !IsNaN(SupportLevel) and SLineCount == 5 then SupportLevel else if !IsNaN(SLine5[1]) and low <= SLine5[1] then 0 else SLine5[1];
plot SLineP5 = if SLine5 > 0 then SLine5 else Double.NaN;
SLineP5.SetStyle(Curve.POINTS);
SLineP5.SetDefaultColor(Color.LIGHT_GREEN);
SLineP5.SetLineWeight(1);
SLineP5.HideBubble();
#----------------------------------------------------------------------------------
SLine6 = if !IsNaN(SupportLevel) and SLineCount == 6 then SupportLevel else if !IsNaN(SLine6[1]) and low <= SLine6[1] then 0 else SLine6[1];
plot SLineP6 = if SLine6 > 0 then SLine6 else Double.NaN;
SLineP6.SetStyle(Curve.POINTS);
SLineP6.SetDefaultColor(Color.LIGHT_GREEN);
SLineP6.SetLineWeight(1);
SLineP6.HideBubble();
#----------------------------------------------------------------------------------
SLine7 = if !IsNaN(SupportLevel) and SLineCount == 7 then SupportLevel else if !IsNaN(SLine7[1]) and low <= SLine7[1] then 0 else SLine7[1];
plot SLineP7 = if SLine7 > 0 then SLine7 else Double.NaN;
SLineP7.SetStyle(Curve.POINTS);
SLineP7.SetDefaultColor(Color.LIGHT_GREEN);
SLineP7.SetLineWeight(1);
SLineP7.HideBubble();
#----------------------------------------------------------------------------------
SLine8 = if !IsNaN(SupportLevel) and SLineCount == 8 then SupportLevel else if !IsNaN(SLine8[1]) and low <= SLine8[1] then 0 else SLine8[1];
plot SLineP8 = if SLine8 > 0 then SLine8 else Double.NaN;
SLineP8.SetStyle(Curve.POINTS);
SLineP8.SetDefaultColor(Color.LIGHT_GREEN);
SLineP8.SetLineWeight(1);
SLineP8.SetLineWeight(1);
SLineP8.HideBubble();
#----------------------------------------------------------------------------------
SLine9 = if !IsNaN(SupportLevel) and SLineCount == 9 then SupportLevel else if !IsNaN(SLine9[1]) and low <= SLine9[1] then 0 else SLine9[1];
plot SLineP9 = if SLine9 > 0 then SLine9 else Double.NaN;
SLineP9.SetStyle(Curve.POINTS);
SLineP9.SetDefaultColor(Color.LIGHT_GREEN);
SLineP9.SetLineWeight(1);
SLineP9.HideBubble();
#----------------------------------------------------------------------------------
SLine10 = if !IsNaN(SupportLevel) and SLineCount == 10 then SupportLevel else if !IsNaN(SLine10[1]) and low <= SLine10[1] then 0 else SLine10[1];
plot SLineP10 = if SLine10 > 0 then SLine10 else Double.NaN;
SLineP10.SetStyle(Curve.POINTS);
SLineP10.SetDefaultColor(Color.LIGHT_GREEN);
SLineP10.SetLineWeight(1);
SLineP10.HideBubble();
#----------------------------------------------------------------------------------
SLine11 = if !IsNaN(SupportLevel) and SLineCount == 11 then SupportLevel else if !IsNaN(SLine11[1]) and low <= SLine11[1] then 0 else SLine11[1];
plot SLineP11 = if SLine11 > 0 then SLine11 else Double.NaN;
SLineP11.SetStyle(Curve.POINTS);
SLineP11.SetDefaultColor(Color.LIGHT_GREEN);
SLineP11.SetLineWeight(1);
SLineP11.HideBubble();
#----------------------------------------------------------------------------------
SLine12 = if !IsNaN(SupportLevel) and SLineCount == 12 then SupportLevel else if !IsNaN(SLine12[1]) and low <= SLine12[1] then 0 else SLine12[1];
plot SLineP12 = if SLine12 > 0 then SLine12 else Double.NaN;
SLineP12.SetStyle(Curve.POINTS);
SLineP12.SetDefaultColor(Color.LIGHT_GREEN);
SLineP12.SetLineWeight(1);
SLineP12.HideBubble();
#----------------------------------------------------------------------------------
SLine13 = if !IsNaN(SupportLevel) and SLineCount == 13 then SupportLevel else if !IsNaN(SLine13[1]) and low <= SLine13[1] then 0 else SLine13[1];
plot SLineP13 = if SLine13 > 0 then SLine13 else Double.NaN;
SLineP13.SetStyle(Curve.POINTS);
SLineP13.SetDefaultColor(Color.LIGHT_GREEN);
SLineP13.SetLineWeight(1);
SLineP13.HideBubble();
#----------------------------------------------------------------------------------
SLine14 = if !IsNaN(SupportLevel) and SLineCount == 14 then SupportLevel else if !IsNaN(SLine14[1]) and low <= SLine14[1] then 0 else SLine14[1];
plot SLineP14 = if SLine14 > 0 then SLine14 else Double.NaN;
SLineP14.SetStyle(Curve.POINTS);
SLineP14.SetDefaultColor(Color.LIGHT_GREEN);
SLineP14.SetLineWeight(1);
SLineP14.HideBubble();
#----------------------------------------------------------------------------------
SLine15 = if !IsNaN(SupportLevel) and SLineCount == 15 then SupportLevel else if !IsNaN(SLine15[1]) and low <= SLine15[1] then 0 else SLine15[1];
plot SLineP15 = if SLine15 > 0 then SLine15 else Double.NaN;
SLineP15.SetStyle(Curve.POINTS);
SLineP15.SetDefaultColor(Color.LIGHT_GREEN);
SLineP15.SetLineWeight(1);
SLineP15.HideBubble();
#----------------------------------------------------------------------------------
SLine16 = if !IsNaN(SupportLevel) and SLineCount == 16 then SupportLevel else if !IsNaN(SLine16[1]) and low <= SLine16[1] then 0 else SLine16[1];
plot SLineP16 = if SLine16 > 0 then SLine16 else Double.NaN;
SLineP16.SetStyle(Curve.POINTS);
SLineP16.SetDefaultColor(Color.LIGHT_GREEN);
SLineP16.SetLineWeight(1);
SLineP16.HideBubble();
#----------------------------------------------------------------------------------
SLine17 = if !IsNaN(SupportLevel) and SLineCount == 17 then SupportLevel else if !IsNaN(SLine17[1]) and low <= SLine17[1] then 0 else SLine17[1];
plot SLineP17 = if SLine17 > 0 then SLine17 else Double.NaN;
SLineP17.SetStyle(Curve.POINTS);
SLineP17.SetDefaultColor(Color.LIGHT_GREEN);
SLineP17.SetLineWeight(1);
SLineP17.HideBubble();
#----------------------------------------------------------------------------------
SLine18 = if !IsNaN(SupportLevel) and SLineCount == 18 then SupportLevel else if !IsNaN(SLine18[1]) and low < SLine18[1] then 0 else SLine18[1];
plot SLineP18 = if SLine18 > 0 then SLine18 else Double.NaN;
SLineP18.SetStyle(Curve.POINTS);
SLineP18.SetDefaultColor(Color.LIGHT_GREEN);
SLineP18.SetLineWeight(1);
SLineP18.HideBubble();
#----------------------------------------------------------------------------------
SLine19 = if !IsNaN(SupportLevel) and SLineCount == 19 then SupportLevel else if !IsNaN(SLine19[1]) and low <= SLine19[1] then 0 else SLine19[1];
plot SLineP19 = if SLine19 > 0 then SLine19 else Double.NaN;
SLineP19.SetStyle(Curve.POINTS);
SLineP19.SetDefaultColor(Color.LIGHT_GREEN);
SLineP19.SetLineWeight(1);
SLineP19.HideBubble();
#----------------------------------------------------------------------------------
SLine20 = if !IsNaN(SupportLevel) and SLineCount == 20 then SupportLevel else if !IsNaN(SLine20[1]) and low <= SLine20[1] then 0 else SLine20[1];
plot SLineP20 = if SLine20 > 0 then SLine20 else Double.NaN;
SLineP20.SetStyle(Curve.POINTS);
SLineP20.SetDefaultColor(Color.LIGHT_GREEN);
SLineP20.SetLineWeight(1);
SLineP20.HideBubble();
#----------------------------------------------------------------------------------
#####################################################################################


#red candles
######################################################################################
#Definitons of Resistance Levels.#####################################################
######################################################################################
plot ResistanceLevel = if RedBar then low[1] else Double.NaN;
ResistanceLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def RLine0;
def RLine1;
def RLine2;
def RLine3;
def RLine4;
def RLine5;
def RLine6;
def RLine7;
def RLine8;
def RLine9;
def RLine10;
def RLine11;
def RLine12;
def RLine13;
def RLine14;
def RLine15;
def RLine16;
def RLine17;
def RLine18;
def RLine19;
def RLine20;

def RLineCount;
If BarNumber() == 1 { RLineCount = 1;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine1[1]) and high>=RLine1[1]) { RLineCount=0;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine2[1]) and high>=RLine2[1]) { RLineCount=1;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine3[1]) and high>=RLine3[1]) { RLineCount=2;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine4[1]) and high>=RLine4[1]) { RLineCount=3;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine5[1]) and high>=RLine5[1]) { RLineCount=4;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine6[1]) and high>=RLine6[1]) { RLineCount=5;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine7[1]) and high>=RLine7[1]) { RLineCount=6;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine8[1]) and high>=RLine8[1]) { RLineCount=7;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine9[1]) and high>=RLine9[1]) { RLineCount=8;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine10[1]) and high>=RLine10[1]) { RLineCount=9;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine11[1]) and high>=RLine11[1]) { RLineCount=10;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine12[1]) and high>=RLine12[1]) { RLineCount=11;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine13[1]) and high>=RLine13[1]) { RLineCount=12;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine14[1]) and high>=RLine14[1]) { RLineCount=13;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine15[1]) and high>=RLine15[1]) { RLineCount=14;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine16[1]) and high>=RLine16[1]) { RLineCount=15;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine17[1]) and high>=RLine17[1]) { RLineCount=16;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine18[1]) and high>=RLine18[1]) { RLineCount=17;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine19[1]) and high>=RLine19[1]) { RLineCount=18;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine20[1]) and high>=RLine20[1]) { RLineCount=19;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine0[1]) and high>=RLine0[1]) { RLineCount=20;

}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine0[1]) and high>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine1[1]) and high>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine2[1]) and high>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine3[1]) and high>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine4[1]) and high>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine5[1]) and high>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine6[1]) and high>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine7[1]) and high>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine8[1]) and high>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine9[1]) and high>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine10[1]) and high>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine11[1]) and high>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine12[1]) and high>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine13[1]) and high>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine14[1]) and high>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine15[1]) and high>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine16[1]) and high>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine17[1]) and high>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine18[1]) and high>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine19[1]) and high>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine20[1]) and high>=RLine20[1]) { RLineCount=20;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]!=20 { RLineCount = RLineCount[1] + 1;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]==20 { RLineCount = 0;
} else {
    RLineCount = RLineCount[1];
}

######################################################################################
#Plots of Resistance Levels.##########################################################
######################################################################################
RLine0 = if !IsNaN(ResistanceLevel) and RLineCount == 0 then ResistanceLevel else if !IsNaN(RLine0[1]) and high >= RLine0[1] then Double.NaN else RLine0[1];
plot RLineP0 = if RLine0 > 0 then RLine0 else Double.NaN;
RLineP0.SetStyle(Curve.POINTS);
RLineP0.SetDefaultColor(Color.LIGHT_RED);
RLineP0.SetLineWeight(1);
RLineP0.HideBubble();
def RLine0Length = if RLine0 != RLine0[1] then 1 else if !IsNaN(RLine0[1]) and IsNaN(RLine0) then 0 else if !IsNaN(RLine0) then RLine0Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine1 = if !IsNaN(ResistanceLevel) and RLineCount == 1 then ResistanceLevel else if !IsNaN(RLine1[1]) and high >= RLine1[1] then Double.NaN else RLine1[1];
plot RLineP1 = if RLine1 > 0 then RLine1 else Double.NaN;
RLineP1.SetStyle(Curve.POINTS);
RLineP1.SetDefaultColor(Color.LIGHT_RED);
RLineP1.SetLineWeight(1);
RLineP1.HideBubble();
def RLine1Length = if RLine1 != RLine1[1] then 1 else if !IsNaN(RLine1[1]) and IsNaN(RLine1) then 0 else if !IsNaN(RLine1) then RLine1Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine2 = if !IsNaN(ResistanceLevel) and RLineCount == 2 then ResistanceLevel else if !IsNaN(RLine2[1]) and high >= RLine2[1] then Double.NaN else RLine2[1];
plot RLineP2 = if RLine2 > 0 then RLine2 else Double.NaN;
RLineP2.SetStyle(Curve.POINTS);
RLineP2.SetDefaultColor(Color.LIGHT_RED);
RLineP2.SetLineWeight(1);
RLineP2.HideBubble();
def RLine2Length = if RLine2 != RLine2[1] then 1 else if !IsNaN(RLine2[1]) and IsNaN(RLine2) then 0 else if !IsNaN(RLine2) then RLine2Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine3 = if !IsNaN(ResistanceLevel) and RLineCount == 3 then ResistanceLevel else if !IsNaN(RLine3[1]) and high >= RLine3[1] then Double.NaN else RLine3[1];
plot RLineP3 = if RLine3 > 0 then RLine3 else Double.NaN;
RLineP3.SetStyle(Curve.POINTS);
RLineP3.SetDefaultColor(Color.LIGHT_RED);
RLineP3.SetLineWeight(1);
RLineP3.HideBubble();
def RLine3Length = if RLine3 != RLine3[1] then 1 else if !IsNaN(RLine3[1]) and IsNaN(RLine3) then 0 else if !IsNaN(RLine3) then RLine3Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine4 = if !IsNaN(ResistanceLevel) and RLineCount == 4 then ResistanceLevel else if !IsNaN(RLine4[1]) and high >= RLine4[1] then Double.NaN else RLine4[1];
plot RLineP4 = if RLine4 > 0 then RLine4 else Double.NaN;
RLineP4.SetStyle(Curve.POINTS);
RLineP4.SetDefaultColor(Color.LIGHT_RED);
RLineP4.SetLineWeight(1);
RLineP4.HideBubble();
def RLine4Length = if RLine4 != RLine4[1] then 1 else if !IsNaN(RLine4[1]) and IsNaN(RLine4) then 0 else if !IsNaN(RLine4) then RLine4Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine5 = if !IsNaN(ResistanceLevel) and RLineCount == 5 then ResistanceLevel else if !IsNaN(RLine5[1]) and high >= RLine5[1] then Double.NaN else RLine5[1];
plot RLineP5 = if RLine5 > 0 then RLine5 else Double.NaN;
RLineP5.SetStyle(Curve.POINTS);
RLineP5.SetDefaultColor(Color.LIGHT_RED);
RLineP5.SetLineWeight(1);
RLineP5.HideBubble();
def RLine5Length = if RLine5 != RLine5[1] then 1 else if !IsNaN(RLine5[1]) and IsNaN(RLine5) then 0 else if !IsNaN(RLine5) then RLine5Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
RLine6 = if !IsNaN(ResistanceLevel) and RLineCount == 6 then ResistanceLevel else if !IsNaN(RLine6[1]) and high >= RLine6[1] then Double.NaN else RLine6[1];
plot RLineP6 = if RLine6 > 0 then RLine6 else Double.NaN;
RLineP6.SetStyle(Curve.POINTS);
RLineP6.SetDefaultColor(Color.LIGHT_RED);
RLineP6.SetLineWeight(1);
RLineP6.HideBubble();
#----------------------------------------------------------------------------------
RLine7 = if !IsNaN(ResistanceLevel) and RLineCount == 7 then ResistanceLevel else if !IsNaN(RLine7[1]) and high >= RLine7[1] then Double.NaN else RLine7[1];
plot RLineP7 = if RLine7 > 0 then RLine7 else Double.NaN;
RLineP7.SetStyle(Curve.POINTS);
RLineP7.SetDefaultColor(Color.LIGHT_RED);
RLineP7.SetLineWeight(1);
RLineP7.HideBubble();
#----------------------------------------------------------------------------------
RLine8 = if !IsNaN(ResistanceLevel) and RLineCount == 8 then ResistanceLevel else if !IsNaN(RLine8[1]) and high >= RLine8[1] then Double.NaN else RLine8[1];
plot RLineP8 = if RLine8 > 0 then RLine8 else Double.NaN;
RLineP8.SetStyle(Curve.POINTS);
RLineP8.SetDefaultColor(Color.LIGHT_RED);
RLineP8.SetLineWeight(1);
RLineP8.HideBubble();
#----------------------------------------------------------------------------------
RLine9 = if !IsNaN(ResistanceLevel) and RLineCount == 9 then ResistanceLevel else if !IsNaN(RLine9[1]) and high >= RLine9[1] then Double.NaN else RLine9[1];
plot RLineP9 = if RLine9 > 0 then RLine9 else Double.NaN;
RLineP9.SetStyle(Curve.POINTS);
RLineP9.SetDefaultColor(Color.LIGHT_RED);
RLineP9.SetLineWeight(1);
RLineP9.HideBubble();
#----------------------------------------------------------------------------------
RLine10 = if !IsNaN(ResistanceLevel) and RLineCount == 10 then ResistanceLevel else if !IsNaN(RLine10[1]) and high >= RLine10[1] then Double.NaN else RLine10[1];
plot RLineP10 = if RLine10 > 0 then RLine10 else Double.NaN;
RLineP10.SetStyle(Curve.POINTS);
RLineP10.SetDefaultColor(Color.LIGHT_RED);
RLineP10.SetLineWeight(1);
RLineP10.HideBubble();
#----------------------------------------------------------------------------------
RLine11 = if !IsNaN(ResistanceLevel) and RLineCount == 11 then ResistanceLevel else if !IsNaN(RLine11[1]) and high >= RLine11[1] then Double.NaN else RLine11[1];
plot RLineP11 = if RLine11 > 0 then RLine11 else Double.NaN;
RLineP11.SetStyle(Curve.POINTS);
RLineP11.SetDefaultColor(Color.LIGHT_RED);
RLineP11.SetLineWeight(1);
RLineP11.HideBubble();
#----------------------------------------------------------------------------------
RLine12 = if !IsNaN(ResistanceLevel) and RLineCount == 12 then ResistanceLevel else if !IsNaN(RLine12[1]) and high >= RLine12[1] then Double.NaN else RLine12[1];
plot RLineP12 = if RLine12 > 0 then RLine12 else Double.NaN;
RLineP12.SetStyle(Curve.POINTS);
RLineP12.SetDefaultColor(Color.LIGHT_RED);
RLineP12.SetLineWeight(1);
RLineP12.HideBubble();
#----------------------------------------------------------------------------------
RLine13 = if !IsNaN(ResistanceLevel) and RLineCount == 13 then ResistanceLevel else if !IsNaN(RLine13[1]) and high >= RLine13[1] then Double.NaN else RLine13[1];
plot RLineP13 = if RLine13 > 0 then RLine13 else Double.NaN;
RLineP13.SetStyle(Curve.POINTS);
RLineP13.SetDefaultColor(Color.LIGHT_RED);
RLineP13.SetLineWeight(1);
RLineP13.HideBubble();
#----------------------------------------------------------------------------------
RLine14 = if !IsNaN(ResistanceLevel) and RLineCount == 14 then ResistanceLevel else if !IsNaN(RLine14[1]) and high >= RLine14[1] then Double.NaN else RLine14[1];
plot RLineP14 = if RLine14 > 0 then RLine14 else Double.NaN;
RLineP14.SetStyle(Curve.POINTS);
RLineP14.SetDefaultColor(Color.LIGHT_RED);
RLineP14.SetLineWeight(1);
RLineP14.HideBubble();
#----------------------------------------------------------------------------------
RLine15 = if !IsNaN(ResistanceLevel) and RLineCount == 15 then ResistanceLevel else if !IsNaN(RLine15[1]) and high >= RLine15[1] then Double.NaN else RLine15[1];
plot RLineP15 = if RLine15 > 0 then RLine15 else Double.NaN;
RLineP15.SetStyle(Curve.POINTS);
RLineP15.SetDefaultColor(Color.LIGHT_RED);
RLineP15.SetLineWeight(1);
RLineP15.HideBubble();
#----------------------------------------------------------------------------------
RLine16 = if !IsNaN(ResistanceLevel) and RLineCount == 16 then ResistanceLevel else if !IsNaN(RLine16[1]) and high >= RLine16[1] then Double.NaN else RLine16[1];
plot RLineP16 = if RLine16 > 0 then RLine16 else Double.NaN;
RLineP16.SetStyle(Curve.POINTS);
RLineP16.SetDefaultColor(Color.LIGHT_RED);
RLineP16.SetLineWeight(1);
RLineP16.HideBubble();
#----------------------------------------------------------------------------------
RLine17 = if !IsNaN(ResistanceLevel) and RLineCount == 17 then ResistanceLevel else if !IsNaN(RLine17[1]) and high >= RLine17[1] then Double.NaN else RLine17[1];
plot RLineP17 = if RLine17 > 0 then RLine17 else Double.NaN;
RLineP17.SetStyle(Curve.POINTS);
RLineP17.SetDefaultColor(Color.LIGHT_RED);
RLineP17.SetLineWeight(1);
RLineP17.HideBubble();
#----------------------------------------------------------------------------------
RLine18 = if !IsNaN(ResistanceLevel) and RLineCount == 18 then ResistanceLevel else if !IsNaN(RLine18[1]) and high >= RLine18[1] then Double.NaN else RLine18[1];
plot RLineP18 = if RLine18 > 0 then RLine18 else Double.NaN;
RLineP18.SetStyle(Curve.POINTS);
RLineP18.SetDefaultColor(Color.LIGHT_RED);
RLineP18.SetLineWeight(1);
RLineP18.HideBubble();
#----------------------------------------------------------------------------------
RLine19 = if !IsNaN(ResistanceLevel) and RLineCount == 19 then ResistanceLevel else if !IsNaN(RLine19[1]) and high >= RLine19[1] then Double.NaN else RLine19[1];
plot RLineP19 = if RLine19 > 0 then RLine19 else Double.NaN;
RLineP19.SetStyle(Curve.POINTS);
RLineP19.SetDefaultColor(Color.LIGHT_RED);
RLineP19.SetLineWeight(1);
RLineP19.HideBubble();
#----------------------------------------------------------------------------------
RLine20 = if !IsNaN(ResistanceLevel) and RLineCount == 20 then ResistanceLevel else if !IsNaN(RLine20[1]) and high >= RLine20[1] then Double.NaN else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_RED);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
#####################################################################################
 
Last edited:
Fixed another plotting bug and removed strategy for now to reduce load time.

Ruby:
#Support and Reisitance Lines That End When Price Returns to Line.
#Original idea by Department
#Coded by Svanoy
#https://usethinkscript.com/threads/support-resistance-that-ends-once-touched.9491/#post-89067

######################################################################################
#Definition of Signal.################################################################
######################################################################################

input history = 10;
input multiplier = 1.5;

def highLow = high-low;
def buyopenlow = open-low;
def sellhighopen = high-open;
def greenCandle = open < close;
def redCandle = close < open;
def body = BodyHeight();
def volatility = ATR(history, AverageType.WILDERS);
def significantBar = volatility * multiplier;
def imBody = (body > highLow * 0.5) and (highLow >= significantBar);
def buybody = (body > buyopenLow * 0.5) and (buyopenLow >= volatility * 1.2);
def sellbody = (body > sellhighopen * 0.5) and (sellhighopen >= volatility * 1.2);
AssignPriceColor(if imBody and greenCandle then Color.LIME else Color.CURRENT);
AssignPriceColor(if imBody and redCandle then Color.DARK_RED else Color.CURRENT);

plot Bottom = buyBody and greenCandle;
Bottom.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
Bottom.SetLineWeight(5);
Bottom.AssignValueColor(Color.CYAN );

plot Top = sellBody and redCandle;
Top.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
Top.SetLineWeight(5);
Top.AssignValueColor(Color.LIGHT_ORANGE);

#######################################################################################
#Define Level Plot Triggers..##########################################################
#######################################################################################
def RedBar = imBody and redCandle ;#and low[1]>close;
def GreenBar = imBody and greenCandle ;#and high[1]<close;

######################################################################################
#Defintions of Support Levels.########################################################
######################################################################################
plot SupportLevel = if GreenBar then high[1] else Double.NaN;
SupportLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def SLine0;
def SLine1;
def SLine2;
def SLine3;
def SLine4;
def SLine5;
def SLine6;
def SLine7;
def SLine8;
def SLine9;
def SLine10;
def SLine11;
def SLine12;
def SLine13;
def SLine14;
def SLine15;
def SLine16;
def SLine17;
def SLine18;
def SLine19;
def SLine20;

def SLineCount;
If BarNumber() == 1 { SLineCount = 1;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine1[1]) and low<=SLine1[1]) { SLineCount=0;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine2[1]) and low<=SLine2[1]) { SLineCount=1;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine3[1]) and low<=SLine3[1]) { SLineCount=2;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine4[1]) and low<=SLine4[1]) { SLineCount=3;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine5[1]) and low<=SLine5[1]) { SLineCount=4;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine6[1]) and low<=SLine6[1]) { SLineCount=5;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine7[1]) and low<=SLine7[1]) { SLineCount=6;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine8[1]) and low<=SLine8[1]) { SLineCount=7;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine9[1]) and low<=SLine9[1]) { SLineCount=8;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine10[1]) and low<=SLine10[1]) { SLineCount=9;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine11[1]) and low<=SLine11[1]) { SLineCount=10;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine12[1]) and low<=SLine12[1]) { SLineCount=11;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine13[1]) and low<=SLine13[1]) { SLineCount=12;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine14[1]) and low<=SLine14[1]) { SLineCount=13;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine15[1]) and low<=SLine15[1]) { SLineCount=14;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine16[1]) and low<=SLine16[1]) { SLineCount=15;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine17[1]) and low<=SLine17[1]) { SLineCount=16;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine18[1]) and low<=SLine18[1]) { SLineCount=17;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine19[1]) and low<=SLine19[1]) { SLineCount=18;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine20[1]) and low<=SLine20[1]) { SLineCount=19;
}else if (IsNaN(SupportLevel) and !IsNaN(SLine0[1]) and low<=SLine0[1]) { SLineCount=20;
#} else if !IsNaN(SupportLevel) and low>SLine and SLineCount[1] == 20 {
#    SLineCount = 0;

}else if (!IsNaN(SupportLevel) and !IsNaN(SLine0[1]) and low<=SLine0[1]) { SLineCount=0;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine1[1]) and low<=SLine1[1]) { SLineCount=1;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine2[1]) and low<=SLine2[1]) { SLineCount=2;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine3[1]) and low<=SLine3[1]) { SLineCount=3;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine4[1]) and low<=SLine4[1]) { SLineCount=4;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine5[1]) and low<=SLine5[1]) { SLineCount=5;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine6[1]) and low<=SLine6[1]) { SLineCount=6;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine7[1]) and low<=SLine7[1]) { SLineCount=7;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine8[1]) and low<=SLine8[1]) { SLineCount=8;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine9[1]) and low<=SLine9[1]) { SLineCount=9;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine10[1]) and low<=SLine10[1]) { SLineCount=10;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine11[1]) and low<=SLine11[1]) { SLineCount=11;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine12[1]) and low<=SLine12[1]) { SLineCount=12;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine13[1]) and low<=SLine13[1]) { SLineCount=13;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine14[1]) and low<=SLine14[1]) { SLineCount=14;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine15[1]) and low<=SLine15[1]) { SLineCount=15;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine16[1]) and low<=SLine16[1]) { SLineCount=16;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine17[1]) and low<=SLine17[1]) { SLineCount=17;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine18[1]) and low<=SLine18[1]) { SLineCount=18;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine19[1]) and low<=SLine19[1]) { SLineCount=19;
}else if (!IsNaN(SupportLevel) and !IsNaN(SLine20[1]) and low<=SLine20[1]) { SLineCount=20;
}else if (!IsNaN(SupportLevel)) { SLineCount = SLineCount[1] + 1;
} else {
    SLineCount = SLineCount[1];
}

#green candles
######################################################################################
#Plots of Support Levels.#############################################################
######################################################################################
SLine0 = if !IsNaN(SupportLevel) and SLineCount == 0 then SupportLevel else if !IsNaN(SLine0[1]) and low <= SLine0[1] then 0 else SLine0[1];
plot SLineP0 = if SLine0 > 0 then SLine0 else Double.NaN;
SLineP0.SetStyle(Curve.POINTS);
SLineP0.SetDefaultColor(Color.LIGHT_GREEN);
SLineP0.SetLineWeight(1);
SLineP0.HideBubble();
#----------------------------------------------------------------------------------
SLine1 = if !IsNaN(SupportLevel) and SLineCount == 1 then SupportLevel else if !IsNaN(SLine1[1]) and low <= SLine1[1] then 0 else SLine1[1];
plot SLineP1 = if SLine1 > 0 then SLine1 else Double.NaN;
SLineP1.SetStyle(Curve.POINTS);
SLineP1.SetDefaultColor(Color.LIGHT_GREEN);
SLineP1.SetLineWeight(1);
SLineP1.HideBubble();
#----------------------------------------------------------------------------------
SLine2 = if !IsNaN(SupportLevel) and SLineCount == 2 then SupportLevel else if !IsNaN(SLine2[1]) and low <= SLine2[1] then 0 else SLine2[1];
plot SLineP2 = if SLine2 > 0 then SLine2 else Double.NaN;
SLineP2.SetStyle(Curve.POINTS);
SLineP2.SetDefaultColor(Color.LIGHT_GREEN);
SLineP2.SetLineWeight(1);
SLineP2.HideBubble();
#----------------------------------------------------------------------------------
SLine3 = if !IsNaN(SupportLevel) and SLineCount == 3 then SupportLevel else if !IsNaN(SLine3[1]) and low <= SLine3[1] then 0 else SLine3[1];
plot SLineP3 = if SLine3 > 0 then SLine3 else Double.NaN;
SLineP3.SetStyle(Curve.POINTS);
SLineP3.SetDefaultColor(Color.LIGHT_GREEN);
SLineP3.SetLineWeight(1);
SLineP3.HideBubble();
#----------------------------------------------------------------------------------
SLine4 = if !IsNaN(SupportLevel) and SLineCount == 4 then SupportLevel else if !IsNaN(SLine4[1]) and low <= SLine4[1] then 0 else SLine4[1];
plot SLineP4 = if SLine4 > 0 then SLine4 else Double.NaN;
SLineP4.SetStyle(Curve.POINTS);
SLineP4.SetDefaultColor(Color.LIGHT_GREEN);
SLineP4.SetLineWeight(1);
SLineP4.HideBubble();
def SLine4Length = if SLine4 != SLine4[1] then 1 else if !IsNaN(SLine4[1]) and IsNaN(SLine4) then 0 else if !IsNaN(SLine4) then SLine4Length[1] + 1 else 0;
#----------------------------------------------------------------------------------
SLine5 = if !IsNaN(SupportLevel) and SLineCount == 5 then SupportLevel else if !IsNaN(SLine5[1]) and low <= SLine5[1] then 0 else SLine5[1];
plot SLineP5 = if SLine5 > 0 then SLine5 else Double.NaN;
SLineP5.SetStyle(Curve.POINTS);
SLineP5.SetDefaultColor(Color.LIGHT_GREEN);
SLineP5.SetLineWeight(1);
SLineP5.HideBubble();
#----------------------------------------------------------------------------------
SLine6 = if !IsNaN(SupportLevel) and SLineCount == 6 then SupportLevel else if !IsNaN(SLine6[1]) and low <= SLine6[1] then 0 else SLine6[1];
plot SLineP6 = if SLine6 > 0 then SLine6 else Double.NaN;
SLineP6.SetStyle(Curve.POINTS);
SLineP6.SetDefaultColor(Color.LIGHT_GREEN);
SLineP6.SetLineWeight(1);
SLineP6.HideBubble();
#----------------------------------------------------------------------------------
SLine7 = if !IsNaN(SupportLevel) and SLineCount == 7 then SupportLevel else if !IsNaN(SLine7[1]) and low <= SLine7[1] then 0 else SLine7[1];
plot SLineP7 = if SLine7 > 0 then SLine7 else Double.NaN;
SLineP7.SetStyle(Curve.POINTS);
SLineP7.SetDefaultColor(Color.LIGHT_GREEN);
SLineP7.SetLineWeight(1);
SLineP7.HideBubble();
#----------------------------------------------------------------------------------
SLine8 = if !IsNaN(SupportLevel) and SLineCount == 8 then SupportLevel else if !IsNaN(SLine8[1]) and low <= SLine8[1] then 0 else SLine8[1];
plot SLineP8 = if SLine8 > 0 then SLine8 else Double.NaN;
SLineP8.SetStyle(Curve.POINTS);
SLineP8.SetDefaultColor(Color.LIGHT_GREEN);
SLineP8.SetLineWeight(1);
SLineP8.SetLineWeight(1);
SLineP8.HideBubble();
#----------------------------------------------------------------------------------
SLine9 = if !IsNaN(SupportLevel) and SLineCount == 9 then SupportLevel else if !IsNaN(SLine9[1]) and low <= SLine9[1] then 0 else SLine9[1];
plot SLineP9 = if SLine9 > 0 then SLine9 else Double.NaN;
SLineP9.SetStyle(Curve.POINTS);
SLineP9.SetDefaultColor(Color.LIGHT_GREEN);
SLineP9.SetLineWeight(1);
SLineP9.HideBubble();
#----------------------------------------------------------------------------------
SLine10 = if !IsNaN(SupportLevel) and SLineCount == 10 then SupportLevel else if !IsNaN(SLine10[1]) and low <= SLine10[1] then 0 else SLine10[1];
plot SLineP10 = if SLine10 > 0 then SLine10 else Double.NaN;
SLineP10.SetStyle(Curve.POINTS);
SLineP10.SetDefaultColor(Color.LIGHT_GREEN);
SLineP10.SetLineWeight(1);
SLineP10.HideBubble();
#----------------------------------------------------------------------------------
SLine11 = if !IsNaN(SupportLevel) and SLineCount == 11 then SupportLevel else if !IsNaN(SLine11[1]) and low <= SLine11[1] then 0 else SLine11[1];
plot SLineP11 = if SLine11 > 0 then SLine11 else Double.NaN;
SLineP11.SetStyle(Curve.POINTS);
SLineP11.SetDefaultColor(Color.LIGHT_GREEN);
SLineP11.SetLineWeight(1);
SLineP11.HideBubble();
#----------------------------------------------------------------------------------
SLine12 = if !IsNaN(SupportLevel) and SLineCount == 12 then SupportLevel else if !IsNaN(SLine12[1]) and low <= SLine12[1] then 0 else SLine12[1];
plot SLineP12 = if SLine12 > 0 then SLine12 else Double.NaN;
SLineP12.SetStyle(Curve.POINTS);
SLineP12.SetDefaultColor(Color.LIGHT_GREEN);
SLineP12.SetLineWeight(1);
SLineP12.HideBubble();
#----------------------------------------------------------------------------------
SLine13 = if !IsNaN(SupportLevel) and SLineCount == 13 then SupportLevel else if !IsNaN(SLine13[1]) and low <= SLine13[1] then 0 else SLine13[1];
plot SLineP13 = if SLine13 > 0 then SLine13 else Double.NaN;
SLineP13.SetStyle(Curve.POINTS);
SLineP13.SetDefaultColor(Color.LIGHT_GREEN);
SLineP13.SetLineWeight(1);
SLineP13.HideBubble();
#----------------------------------------------------------------------------------
SLine14 = if !IsNaN(SupportLevel) and SLineCount == 14 then SupportLevel else if !IsNaN(SLine14[1]) and low <= SLine14[1] then 0 else SLine14[1];
plot SLineP14 = if SLine14 > 0 then SLine14 else Double.NaN;
SLineP14.SetStyle(Curve.POINTS);
SLineP14.SetDefaultColor(Color.LIGHT_GREEN);
SLineP14.SetLineWeight(1);
SLineP14.HideBubble();
#----------------------------------------------------------------------------------
SLine15 = if !IsNaN(SupportLevel) and SLineCount == 15 then SupportLevel else if !IsNaN(SLine15[1]) and low <= SLine15[1] then 0 else SLine15[1];
plot SLineP15 = if SLine15 > 0 then SLine15 else Double.NaN;
SLineP15.SetStyle(Curve.POINTS);
SLineP15.SetDefaultColor(Color.LIGHT_GREEN);
SLineP15.SetLineWeight(1);
SLineP15.HideBubble();
#----------------------------------------------------------------------------------
SLine16 = if !IsNaN(SupportLevel) and SLineCount == 16 then SupportLevel else if !IsNaN(SLine16[1]) and low <= SLine16[1] then 0 else SLine16[1];
plot SLineP16 = if SLine16 > 0 then SLine16 else Double.NaN;
SLineP16.SetStyle(Curve.POINTS);
SLineP16.SetDefaultColor(Color.LIGHT_GREEN);
SLineP16.SetLineWeight(1);
SLineP16.HideBubble();
#----------------------------------------------------------------------------------
SLine17 = if !IsNaN(SupportLevel) and SLineCount == 17 then SupportLevel else if !IsNaN(SLine17[1]) and low <= SLine17[1] then 0 else SLine17[1];
plot SLineP17 = if SLine17 > 0 then SLine17 else Double.NaN;
SLineP17.SetStyle(Curve.POINTS);
SLineP17.SetDefaultColor(Color.LIGHT_GREEN);
SLineP17.SetLineWeight(1);
SLineP17.HideBubble();
#----------------------------------------------------------------------------------
SLine18 = if !IsNaN(SupportLevel) and SLineCount == 18 then SupportLevel else if !IsNaN(SLine18[1]) and low < SLine18[1] then 0 else SLine18[1];
plot SLineP18 = if SLine18 > 0 then SLine18 else Double.NaN;
SLineP18.SetStyle(Curve.POINTS);
SLineP18.SetDefaultColor(Color.LIGHT_GREEN);
SLineP18.SetLineWeight(1);
SLineP18.HideBubble();
#----------------------------------------------------------------------------------
SLine19 = if !IsNaN(SupportLevel) and SLineCount == 19 then SupportLevel else if !IsNaN(SLine19[1]) and low <= SLine19[1] then 0 else SLine19[1];
plot SLineP19 = if SLine19 > 0 then SLine19 else Double.NaN;
SLineP19.SetStyle(Curve.POINTS);
SLineP19.SetDefaultColor(Color.LIGHT_GREEN);
SLineP19.SetLineWeight(1);
SLineP19.HideBubble();
#----------------------------------------------------------------------------------
SLine20 = if !IsNaN(SupportLevel) and SLineCount == 20 then SupportLevel else if !IsNaN(SLine20[1]) and low <= SLine20[1] then 0 else SLine20[1];
plot SLineP20 = if SLine20 > 0 then SLine20 else Double.NaN;
SLineP20.SetStyle(Curve.POINTS);
SLineP20.SetDefaultColor(Color.LIGHT_GREEN);
SLineP20.SetLineWeight(1);
SLineP20.HideBubble();
#----------------------------------------------------------------------------------
#####################################################################################


#red candles
######################################################################################
#Definitons of Resistance Levels.#####################################################
######################################################################################
plot ResistanceLevel = if RedBar then low[1] else Double.NaN;
ResistanceLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def RLine0;
def RLine1;
def RLine2;
def RLine3;
def RLine4;
def RLine5;
def RLine6;
def RLine7;
def RLine8;
def RLine9;
def RLine10;
def RLine11;
def RLine12;
def RLine13;
def RLine14;
def RLine15;
def RLine16;
def RLine17;
def RLine18;
def RLine19;
def RLine20;

def RLineCount;
If BarNumber() == 1 { RLineCount = 1;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine1[1]) and high>=RLine1[1]) { RLineCount=0;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine2[1]) and high>=RLine2[1]) { RLineCount=1;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine3[1]) and high>=RLine3[1]) { RLineCount=2;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine4[1]) and high>=RLine4[1]) { RLineCount=3;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine5[1]) and high>=RLine5[1]) { RLineCount=4;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine6[1]) and high>=RLine6[1]) { RLineCount=5;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine7[1]) and high>=RLine7[1]) { RLineCount=6;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine8[1]) and high>=RLine8[1]) { RLineCount=7;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine9[1]) and high>=RLine9[1]) { RLineCount=8;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine10[1]) and high>=RLine10[1]) { RLineCount=9;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine11[1]) and high>=RLine11[1]) { RLineCount=10;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine12[1]) and high>=RLine12[1]) { RLineCount=11;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine13[1]) and high>=RLine13[1]) { RLineCount=12;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine14[1]) and high>=RLine14[1]) { RLineCount=13;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine15[1]) and high>=RLine15[1]) { RLineCount=14;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine16[1]) and high>=RLine16[1]) { RLineCount=15;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine17[1]) and high>=RLine17[1]) { RLineCount=16;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine18[1]) and high>=RLine18[1]) { RLineCount=17;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine19[1]) and high>=RLine19[1]) { RLineCount=18;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine20[1]) and high>=RLine20[1]) { RLineCount=19;
}else if (IsNaN(ResistanceLevel) and !IsNaN(RLine0[1]) and high>=RLine0[1]) { RLineCount=20;
#} else if !IsNaN(ResistanceLevel) and RLineCount[1] == 20 and { RLineCount = 0;

}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine0[1]) and high>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine1[1]) and high>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine2[1]) and high>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine3[1]) and high>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine4[1]) and high>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine5[1]) and high>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine6[1]) and high>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine7[1]) and high>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine8[1]) and high>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine9[1]) and high>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine10[1]) and high>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine11[1]) and high>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine12[1]) and high>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine13[1]) and high>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine14[1]) and high>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine15[1]) and high>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine16[1]) and high>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine17[1]) and high>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine18[1]) and high>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine19[1]) and high>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and !IsNaN(RLine20[1]) and high>=RLine20[1]) { RLineCount=20;
}else if (!IsNaN(ResistanceLevel)) { RLineCount = RLineCount[1] + 1;
} else {
    RLineCount = RLineCount[1];
}

######################################################################################
#Plots of Resistance Levels.##########################################################
######################################################################################
RLine0 = if !IsNaN(ResistanceLevel) and RLineCount == 0 then ResistanceLevel else if !IsNaN(RLine0[1]) and high >= RLine0[1] then Double.NaN else RLine0[1];
plot RLineP0 = if RLine0 > 0 then RLine0 else Double.NaN;
RLineP0.SetStyle(Curve.POINTS);
RLineP0.SetDefaultColor(Color.LIGHT_RED);
RLineP0.SetLineWeight(1);
RLineP0.HideBubble();
#----------------------------------------------------------------------------------
RLine1 = if !IsNaN(ResistanceLevel) and RLineCount == 1 then ResistanceLevel else if !IsNaN(RLine1[1]) and high >= RLine1[1] then Double.NaN else RLine1[1];
plot RLineP1 = if RLine1 > 0 then RLine1 else Double.NaN;
RLineP1.SetStyle(Curve.POINTS);
RLineP1.SetDefaultColor(Color.LIGHT_RED);
RLineP1.SetLineWeight(1);
RLineP1.HideBubble();
#----------------------------------------------------------------------------------
RLine2 = if !IsNaN(ResistanceLevel) and RLineCount == 2 then ResistanceLevel else if !IsNaN(RLine2[1]) and high >= RLine2[1] then Double.NaN else RLine2[1];
plot RLineP2 = if RLine2 > 0 then RLine2 else Double.NaN;
RLineP2.SetStyle(Curve.POINTS);
RLineP2.SetDefaultColor(Color.LIGHT_RED);
RLineP2.SetLineWeight(1);
RLineP2.HideBubble();
#----------------------------------------------------------------------------------
RLine3 = if !IsNaN(ResistanceLevel) and RLineCount == 3 then ResistanceLevel else if !IsNaN(RLine3[1]) and high >= RLine3[1] then Double.NaN else RLine3[1];
plot RLineP3 = if RLine3 > 0 then RLine3 else Double.NaN;
RLineP3.SetStyle(Curve.POINTS);
RLineP3.SetDefaultColor(Color.LIGHT_RED);
RLineP3.SetLineWeight(1);
RLineP3.HideBubble();
#----------------------------------------------------------------------------------
RLine4 = if !IsNaN(ResistanceLevel) and RLineCount == 4 then ResistanceLevel else if !IsNaN(RLine4[1]) and high >= RLine4[1] then Double.NaN else RLine4[1];
plot RLineP4 = if RLine4 > 0 then RLine4 else Double.NaN;
RLineP4.SetStyle(Curve.POINTS);
RLineP4.SetDefaultColor(Color.LIGHT_RED);
RLineP4.SetLineWeight(1);
RLineP4.HideBubble();
#----------------------------------------------------------------------------------
RLine5 = if !IsNaN(ResistanceLevel) and RLineCount == 5 then ResistanceLevel else if !IsNaN(RLine5[1]) and high >= RLine5[1] then Double.NaN else RLine5[1];
plot RLineP5 = if RLine5 > 0 then RLine5 else Double.NaN;
RLineP5.SetStyle(Curve.POINTS);
RLineP5.SetDefaultColor(Color.LIGHT_RED);
RLineP5.SetLineWeight(1);
RLineP5.HideBubble();
#----------------------------------------------------------------------------------
RLine6 = if !IsNaN(ResistanceLevel) and RLineCount == 6 then ResistanceLevel else if !IsNaN(RLine6[1]) and high >= RLine6[1] then Double.NaN else RLine6[1];
plot RLineP6 = if RLine6 > 0 then RLine6 else Double.NaN;
RLineP6.SetStyle(Curve.POINTS);
RLineP6.SetDefaultColor(Color.LIGHT_RED);
RLineP6.SetLineWeight(1);
RLineP6.HideBubble();
#----------------------------------------------------------------------------------
RLine7 = if !IsNaN(ResistanceLevel) and RLineCount == 7 then ResistanceLevel else if !IsNaN(RLine7[1]) and high >= RLine7[1] then Double.NaN else RLine7[1];
plot RLineP7 = if RLine7 > 0 then RLine7 else Double.NaN;
RLineP7.SetStyle(Curve.POINTS);
RLineP7.SetDefaultColor(Color.LIGHT_RED);
RLineP7.SetLineWeight(1);
RLineP7.HideBubble();
#----------------------------------------------------------------------------------
RLine8 = if !IsNaN(ResistanceLevel) and RLineCount == 8 then ResistanceLevel else if !IsNaN(RLine8[1]) and high >= RLine8[1] then Double.NaN else RLine8[1];
plot RLineP8 = if RLine8 > 0 then RLine8 else Double.NaN;
RLineP8.SetStyle(Curve.POINTS);
RLineP8.SetDefaultColor(Color.LIGHT_RED);
RLineP8.SetLineWeight(1);
RLineP8.HideBubble();
#----------------------------------------------------------------------------------
RLine9 = if !IsNaN(ResistanceLevel) and RLineCount == 9 then ResistanceLevel else if !IsNaN(RLine9[1]) and high >= RLine9[1] then Double.NaN else RLine9[1];
plot RLineP9 = if RLine9 > 0 then RLine9 else Double.NaN;
RLineP9.SetStyle(Curve.POINTS);
RLineP9.SetDefaultColor(Color.LIGHT_RED);
RLineP9.SetLineWeight(1);
RLineP9.HideBubble();
#----------------------------------------------------------------------------------
RLine10 = if !IsNaN(ResistanceLevel) and RLineCount == 10 then ResistanceLevel else if !IsNaN(RLine10[1]) and high >= RLine10[1] then Double.NaN else RLine10[1];
plot RLineP10 = if RLine10 > 0 then RLine10 else Double.NaN;
RLineP10.SetStyle(Curve.POINTS);
RLineP10.SetDefaultColor(Color.LIGHT_RED);
RLineP10.SetLineWeight(1);
RLineP10.HideBubble();
#----------------------------------------------------------------------------------
RLine11 = if !IsNaN(ResistanceLevel) and RLineCount == 11 then ResistanceLevel else if !IsNaN(RLine11[1]) and high >= RLine11[1] then Double.NaN else RLine11[1];
plot RLineP11 = if RLine11 > 0 then RLine11 else Double.NaN;
RLineP11.SetStyle(Curve.POINTS);
RLineP11.SetDefaultColor(Color.LIGHT_RED);
RLineP11.SetLineWeight(1);
RLineP11.HideBubble();
#----------------------------------------------------------------------------------
RLine12 = if !IsNaN(ResistanceLevel) and RLineCount == 12 then ResistanceLevel else if !IsNaN(RLine12[1]) and high >= RLine12[1] then Double.NaN else RLine12[1];
plot RLineP12 = if RLine12 > 0 then RLine12 else Double.NaN;
RLineP12.SetStyle(Curve.POINTS);
RLineP12.SetDefaultColor(Color.LIGHT_RED);
RLineP12.SetLineWeight(1);
RLineP12.HideBubble();
#----------------------------------------------------------------------------------
RLine13 = if !IsNaN(ResistanceLevel) and RLineCount == 13 then ResistanceLevel else if !IsNaN(RLine13[1]) and high >= RLine13[1] then Double.NaN else RLine13[1];
plot RLineP13 = if RLine13 > 0 then RLine13 else Double.NaN;
RLineP13.SetStyle(Curve.POINTS);
RLineP13.SetDefaultColor(Color.LIGHT_RED);
RLineP13.SetLineWeight(1);
RLineP13.HideBubble();
#----------------------------------------------------------------------------------
RLine14 = if !IsNaN(ResistanceLevel) and RLineCount == 14 then ResistanceLevel else if !IsNaN(RLine14[1]) and high >= RLine14[1] then Double.NaN else RLine14[1];
plot RLineP14 = if RLine14 > 0 then RLine14 else Double.NaN;
RLineP14.SetStyle(Curve.POINTS);
RLineP14.SetDefaultColor(Color.LIGHT_RED);
RLineP14.SetLineWeight(1);
RLineP14.HideBubble();
#----------------------------------------------------------------------------------
RLine15 = if !IsNaN(ResistanceLevel) and RLineCount == 15 then ResistanceLevel else if !IsNaN(RLine15[1]) and high >= RLine15[1] then Double.NaN else RLine15[1];
plot RLineP15 = if RLine15 > 0 then RLine15 else Double.NaN;
RLineP15.SetStyle(Curve.POINTS);
RLineP15.SetDefaultColor(Color.LIGHT_RED);
RLineP15.SetLineWeight(1);
RLineP15.HideBubble();
#----------------------------------------------------------------------------------
RLine16 = if !IsNaN(ResistanceLevel) and RLineCount == 16 then ResistanceLevel else if !IsNaN(RLine16[1]) and high >= RLine16[1] then Double.NaN else RLine16[1];
plot RLineP16 = if RLine16 > 0 then RLine16 else Double.NaN;
RLineP16.SetStyle(Curve.POINTS);
RLineP16.SetDefaultColor(Color.LIGHT_RED);
RLineP16.SetLineWeight(1);
RLineP16.HideBubble();
#----------------------------------------------------------------------------------
RLine17 = if !IsNaN(ResistanceLevel) and RLineCount == 17 then ResistanceLevel else if !IsNaN(RLine17[1]) and high >= RLine17[1] then Double.NaN else RLine17[1];
plot RLineP17 = if RLine17 > 0 then RLine17 else Double.NaN;
RLineP17.SetStyle(Curve.POINTS);
RLineP17.SetDefaultColor(Color.LIGHT_RED);
RLineP17.SetLineWeight(1);
RLineP17.HideBubble();
#----------------------------------------------------------------------------------
RLine18 = if !IsNaN(ResistanceLevel) and RLineCount == 18 then ResistanceLevel else if !IsNaN(RLine18[1]) and high >= RLine18[1] then Double.NaN else RLine18[1];
plot RLineP18 = if RLine18 > 0 then RLine18 else Double.NaN;
RLineP18.SetStyle(Curve.POINTS);
RLineP18.SetDefaultColor(Color.LIGHT_RED);
RLineP18.SetLineWeight(1);
RLineP18.HideBubble();
#----------------------------------------------------------------------------------
RLine19 = if !IsNaN(ResistanceLevel) and RLineCount == 19 then ResistanceLevel else if !IsNaN(RLine19[1]) and high >= RLine19[1] then Double.NaN else RLine19[1];
plot RLineP19 = if RLine19 > 0 then RLine19 else Double.NaN;
RLineP19.SetStyle(Curve.POINTS);
RLineP19.SetDefaultColor(Color.LIGHT_RED);
RLineP19.SetLineWeight(1);
RLineP19.HideBubble();
#----------------------------------------------------------------------------------
RLine20 = if !IsNaN(ResistanceLevel) and RLineCount == 20 then ResistanceLevel else if !IsNaN(RLine20[1]) and high >= RLine20[1] then Double.NaN else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_RED);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
#####################################################################################
I'll check this out in the morning.. thanks!
 
Had to update code in post #33 already, left in a test condition.
Code in post #33 is now updated.

Last updated at 2:57 a.m. EST.
If you have trouble with plots stopping short, lengthen your chart by a day or two.
 
Last edited:
@lolreconlol
The colored bars are ranges above ATR with a body height greater than a percentage of the bars overall range.
You could trade with the bars buying at open after a green bar and selling at open after a red bar.

But.. You can do the opposite. Buy at close after a red bar and sell when price returns to the plotted line from the red bar. Or sell at close after a green bar and buy when price returns to the plot from the green bar.

The latter has so far proved to be a 100% win strat, but WHEN the price returns to the plot is the issue. Could be within 1 min, 10min, 1 month, 1 year.

Personally, I Think the latter with a trailing stop works well.

If you choose the latter then change:
def RedBar = imBody and redCandle ;#and low[1]>close;
def GreenBar = imBody and greenCandle ;#and high[1]<close;
To:
def RedBar = imBody and redCandle and low[1]>close;
def GreenBar = imBody and greenCandle and high[1]<close;
 
Last edited:
@lolreconlol
The colored bars are ranges above ATR with a body height greater than a percentage of the bars overall range.
You could trade with the bars buying at open after a green bar and selling at open after a red bar.

But.. You can do the opposite. Buy at close after a red bar and sell when price returns to the plotted line from the red bar. Or sell at close after a green bar and buy when price returns to the plot from the green bar.

The latter has so far proved to be a 100% win strat, but WHEN the price returns to the plot is the issue. Could be within 1 min, 10min, 1 month, 1 year.

Personally, I Think the latter with a trailing stop works well.

If you choose the latter then change:
def RedBar = imBody and redCandle ;#and low[1]>close;
def GreenBar = imBody and greenCandle ;#and high[1]<close
To:
def RedBar = imBody and redCandle and low[1]>close;
def GreenBar = imBody and greenCandle and high[1]<close
Interesting.. I will check it out in depth after work! I noticed that I have yellowish candles.. do I need to adjust something on my end or is that normal? Do they need to be adjusted to green? Or is that the correct color and that's the 'green'? Do you recommend any certain timeframe? Does it matter if extended hours are on or off? Thanks!

 
Last edited:
@lolreconlol
They are called green, but actually Lime colored. Makes them stand out more.

If you're going to trade with the signals, (green=long, red=short), I highly recommend a 30 minute bar.

If you trade against the signals, (green=short, red=long), it works in any time frame.

Keep extended hours on for both. It will stop the plots if you don't.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
154 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top