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...
@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
Tried to switch the code to 'do the opposite' and I got this error:

 
@Trader_Rich
The code in post #16, contains a strategy with screencap of it running on /MES.
The plots in that code are not as sequenced as the latest update, but that doesn't matter as that strategy is trading with the signals, it doesn't need plots.

Even the latest plot update still has a bug or two to work out. Hopefully I can get it straightened out soon.

Again if your going to trade with signals then a 30 minute bar is the way to go.
If you go against the signals then any time frame will work.
 
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();
#####################################################################################
Hello, I've arisen from the dead hope all is swell. Glad to see the code has made progress here and that the lines hopefully load fully with this new transition.
Explaination of how the code/strategy works:
No idea what the new sellhighopen | buyopenlow | buy body | sell body | bsmulti, definitions are for
1. Criteria: Find candles that are significant = have high volatility
2. Criteria: We want large bodied candles = big body with minimum wick
3. Criteria: not in code Isolate for important volume through ranking system = check last few candles, rank them 1-#, then select only highest x candle. This filters out noise and increases chance of price target being exact.
4. Strategy Use Case: These lines mark key retracement levels. They are to be used as price targets not entries or exits. Once touched no longer relevent (Daily price levels may turn into support & resistance - use own judgement)
5. Intraday Trading Strategy: 1. Wait for price target to be created 2. Wait for trend that created candle to stop 3. Enter for reversal and set profit target at price level 4. determining entry for reversal is up to the user. I am a discretionary trader. If you must use an indicator any trend indicator should work on basic settings - I recommend MACD => wait for candle close showing histogram reversal (red to green, or green to red) target nearest price level (if reasonably close [max 2-2.5] candle bodies away - use the colored candle bodies).
5.1. Timing the Reversal: The proper way to time the reversal for this strategy is through volume analysis. However, I have no idea how to explain it adequately in words but I'll try. The premise is to look at consolidation, look for candles going away from the price target (if price target is above focus on red (down) candles, if target below focus on green (up) candles), and look for extremely low volume. Enter on this candle. - Stop below low of consolidation range, target at price target line drawn.
5.2. Larger Time Frame Use on Intraday: 1. Locate nearest price levels 2. treat as profit targets & support & resistance 3. Intraday levels take priority for targets.
6. Larger Time Frame Strategy: There is no strategy here! Use as profit targets and support & resistance for other trading strategies! Possibility of reaching target is unknown and not a risk worth taking. Could take days, weeks, months, years.
7. What to use it on: Developed for and most consistent on low float, high volume stocks
8. Can it be used for other markets (futures, forex, large caps)?: Profitably, probably not. Principles behind why this works is most prevalent in small caps. However, underlying factors cause it to look fairly accurate in any market and in some cases works 100%. Unfortunately, it can only be applied in very specific market conditions and thus is not adequate for using as a strategy 98% of the time in other markets.
_______________________________________________________________________________________________________________________________________________________________
Feel free to ask me anything else. I should be quick to respond until Feb 28th, 2022.
 
@Department
Great Timing!!!
Just finished fixing the last bug in the plots a few days ago.
Also added in code to test the theoretical closing of every plot.
The new variables from the original are for a study with signals that were extrapolated from the original.

The following code contains three studies and can be selected from the study customizing window.
SJPoQD9.png


The first "Original Signals" has all plotting bugs fixed.
cwNd8vz.png


The second "Theoretical Trade Against Direction Of Signal" simulates buying/selling the bar after every plot in the opposite direction then closing the position when target is reached.
It is good for determining how often a stock returns to a retracement level.
Just make sure none of the plotted line are in orange or cyan, if so then the plotting sequence has been maxed out and plots are being reused. This corrupts the data. Reduce the number of days in the chart or change to a larger time frame.
npJ2l9v.png


The third "Extrapolated Signals" is a test of signal derived from your original.
Seems to be good at showing potential reversals,
i4cGRbH.png


Ruby:
#######################################################################################
#Define Start Date. (Second day shown on chart) #######################################
#######################################################################################
input Start_Date = 20210607;
def Days = DaysFromDate(Start_Date);
AddCloud(if Days == 0 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, Color.LIGHT_GRAY);

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

input Indicator = {default "Original Signals","Theoritical Trade against direction of signal","Extrapolated Signals"};
input Show_Level_Value = no;
input history = 10;
input Original_Signal_Multiplier = 1.5;
input Extrapolated_Signal_Multiplier = 1.1;

def Study;
Switch (Indicator) {
case "Original Signals":
    Study = 1;
case "Theoritical Trade against direction of signal":
    Study = 2;
case "Extrapolated Signals":
    Study = 3;
}

def greenCandle = open < close;
def redCandle = close < open;
def body = BodyHeight();
def volatility = ATR(history, AverageType.WILDERS);

def highLow = high-low;
def imBody = (body > highLow * 0.5) and (highLow >= volatility * Original_Signal_Multiplier);

def highopen = high-open;
def SimBody = (body > highopen * 0.5) and (highopen >= volatility * Extrapolated_Signal_Multiplier);

def openlow = open-low;
def BimBody = (body > openlow * 0.5) and (openlow >= volatility * Extrapolated_Signal_Multiplier);

AssignPriceColor(if if(Study==3,BimBody,imbody) and greenCandle then Color.LIME else Color.CURRENT);
AssignPriceColor(if if(Study==3,SimBody,imbody) and redCandle then Color.DARK_RED else Color.CURRENT);

plot B = Bimbody and greencandle;
B.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
B.AssignValueColor(Color.GREEN);
B.SetLineWeight(5);
B.SetHiding(Study==1 or Study==2);

plot A = Simbody and redcandle;
A.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
A.AssignValueColor(Color.RED);
A.SetLineWeight(5);
A.SetHiding(Study==1 or Study==2);


#######################################################################################
#Define Level Plot Triggers..##########################################################
#######################################################################################
def GreenBar = If(Study==3,BimBody and greenCandle  and days>0 and high[1]<close,imBody and greenCandle and Days>0 and high[1]<close);
def RedBar = If(Study==3,SimBody and redCandle and Days>0 and low[1]>close,imBody and redCandle and Days>0 and low[1]>close);;


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

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

}else if (!IsNaN(SupportLevel) and SLine0[1]<>0 and low<=SLine0[1]) { SLineCount=0;
}else if (!IsNaN(SupportLevel) and SLine1[1]<>0 and low<=SLine1[1]) { SLineCount=1;
}else if (!IsNaN(SupportLevel) and SLine2[1]<>0 and low<=SLine2[1]) { SLineCount=2;
}else if (!IsNaN(SupportLevel) and SLine3[1]<>0 and low<=SLine3[1]) { SLineCount=3;
}else if (!IsNaN(SupportLevel) and SLine4[1]<>0 and low<=SLine4[1]) { SLineCount=4;
}else if (!IsNaN(SupportLevel) and SLine5[1]<>0 and low<=SLine5[1]) { SLineCount=5;
}else if (!IsNaN(SupportLevel) and SLine6[1]<>0 and low<=SLine6[1]) { SLineCount=6;
}else if (!IsNaN(SupportLevel) and SLine7[1]<>0 and low<=SLine7[1]) { SLineCount=7;
}else if (!IsNaN(SupportLevel) and SLine8[1]<>0 and low<=SLine8[1]) { SLineCount=8;
}else if (!IsNaN(SupportLevel) and SLine9[1]<>0 and low<=SLine9[1]) { SLineCount=9;
}else if (!IsNaN(SupportLevel) and SLine10[1]<>0 and low<=SLine10[1]) { SLineCount=10;
}else if (!IsNaN(SupportLevel) and SLine11[1]<>0 and low<=SLine11[1]) { SLineCount=11;
}else if (!IsNaN(SupportLevel) and SLine12[1]<>0 and low<=SLine12[1]) { SLineCount=12;
}else if (!IsNaN(SupportLevel) and SLine13[1]<>0 and low<=SLine13[1]) { SLineCount=13;
}else if (!IsNaN(SupportLevel) and SLine14[1]<>0 and low<=SLine14[1]) { SLineCount=14;
}else if (!IsNaN(SupportLevel) and SLine15[1]<>0 and low<=SLine15[1]) { SLineCount=15;
}else if (!IsNaN(SupportLevel) and SLine16[1]<>0 and low<=SLine16[1]) { SLineCount=16;
}else if (!IsNaN(SupportLevel) and SLine17[1]<>0 and low<=SLine17[1]) { SLineCount=17;
}else if (!IsNaN(SupportLevel) and SLine18[1]<>0 and low<=SLine18[1]) { SLineCount=18;
}else if (!IsNaN(SupportLevel) and SLine19[1]<>0 and low<=SLine19[1]) { SLineCount=19;
}else if (!IsNaN(SupportLevel) and SLine20[1]<>0 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();
def SLine0EndCount = if !IsNaN(SLineP0[1]) and SLine0[1]!=SLine0 then SLine0EndCount[1]+1 else SLine0EndCount[1];
def SLine0Length = if SLine0 != SLine0[1] then 1 else if !IsNaN(SLine0[1]) and IsNaN(SLine0) then 0 else if !IsNaN(SLine0) then SLine0Length[1] + 1 else 0;
def SLine0Long = if !IsNaN(SLineP0[1]) and SLine0[1]!=SLine0 then (GetValue(open,(SLine0Length[1]-1))-SLine0[1]) + SLine0Long[1] else SLine0Long[1];
#----------------------------------------------------------------------------------
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();
def SLine1EndCount = if !IsNaN(SLineP1[1]) and SLine1[1]!=SLine1 then SLine1EndCount[1]+1 else SLine1EndCount[1];
def SLine1Length = if SLine1 != SLine1[1] then 1 else if !IsNaN(SLine1[1]) and IsNaN(SLine1) then 0 else if !IsNaN(SLine1) then SLine1Length[1] + 1 else 0;
def SLine1Long = If !IsNaN(SLineP1[1]) and IsNaN(SLineP1) then (GetValue(open,(SLine1Length[1]-1))-SLine1[1]) + SLine1Long[1] else SLine1Long[1];
#----------------------------------------------------------------------------------
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();
def SLine2EndCount = if !IsNaN(SLineP2[1]) and SLine2[1]!=SLine2 then SLine2EndCount[1]+1 else SLine2EndCount[1];
def SLine2Length = if SLine2 != SLine2[1] then 1 else if !IsNaN(SLine2[1]) and IsNaN(SLine2) then 0 else if !IsNaN(SLine2) then SLine2Length[1] + 1 else 0;
def SLine2Long = if !IsNaN(SLineP2[1]) and SLine2[1]!=SLine2 then (GetValue(open,(SLine2Length[1]-1))-SLine2[1]) + SLine2Long[1] else SLine2Long[1];
#----------------------------------------------------------------------------------
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();
def SLine3EndCount = if !IsNaN(SLineP3[1]) and SLine3[1]!=SLine3 then SLine3EndCount[1]+1 else SLine3EndCount[1];
def SLine3Length = if SLine3 != SLine3[1] then 1 else if !IsNaN(SLine3[1]) and IsNaN(SLine3) then 0 else if !IsNaN(SLine3) then SLine3Length[1] + 1 else 0;
def SLine3Long = if !IsNaN(SLineP3[1]) and SLine3[1]!=SLine3 then (GetValue(open,(SLine3Length[1]-1))-SLine3[1]) + SLine3Long[1] else SLine3Long[1];
#----------------------------------------------------------------------------------
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 SLine4EndCount = if !IsNaN(SLineP4[1]) and SLine4[1]!=SLine4 then SLine4EndCount[1]+1 else SLine4EndCount[1];
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;
def SLine4Long = if !IsNaN(SLineP4[1]) and SLine4[1]!=SLine4 then (GetValue(open,(SLine4Length[1]-1))-SLine4[1]) + SLine4Long[1] else SLine4Long[1];
#----------------------------------------------------------------------------------
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();
def SLine5EndCount = if !IsNaN(SLineP5[1]) and SLine5[1]!=SLine5 then SLine5EndCount[1]+1 else SLine5EndCount[1];
def SLine5Length = if SLine5 != SLine5[1] then 1 else if !IsNaN(SLine5[1]) and IsNaN(SLine5) then 0 else if !IsNaN(SLine5) then SLine5Length[1] + 1 else 0;
def SLine5Long = if !IsNaN(SLineP5[1]) and SLine5[1]!=SLine5 then (GetValue(open,(SLine5Length[1]-1))-SLine5[1]) + SLine5Long[1] else SLine5Long[1];
#----------------------------------------------------------------------------------
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();
def SLine6EndCount = if !IsNaN(SLineP6[1]) and SLine6[1]!=SLine6 then SLine6EndCount[1]+1 else SLine6EndCount[1];
def SLine6Length = if SLine6 != SLine6[1] then 1 else if !IsNaN(SLine6[1]) and IsNaN(SLine6) then 0 else if !IsNaN(SLine6) then SLine6Length[1] + 1 else 0;
def SLine6Long = if !IsNaN(SLineP6[1]) and SLine6[1]!=SLine6 then (GetValue(open,(SLine6Length[1]-1))-SLine6[1]) + SLine6Long[1] else SLine6Long[1];
#----------------------------------------------------------------------------------
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();
def SLine7EndCount = if !IsNaN(SLineP7[1]) and SLine7[1]!=SLine7 then SLine7EndCount[1]+1 else SLine7EndCount[1];
def SLine7Length = if SLine7 != SLine7[1] then 1 else if !IsNaN(SLine7[1]) and IsNaN(SLine7) then 0 else if !IsNaN(SLine7) then SLine7Length[1] + 1 else 0;
def SLine7Long = if !IsNaN(SLineP7[1]) and SLine7[1]!=SLine7 then (GetValue(open,(SLine7Length[1]-1))-SLine7[1]) + SLine7Long[1] else SLine7Long[1];
#----------------------------------------------------------------------------------
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.HideBubble();
def SLine8EndCount = if !IsNaN(SLineP8[1]) and SLine8[1]!=SLine8 then SLine8EndCount[1]+1 else SLine8EndCount[1];
def SLine8Length = if SLine8 != SLine8[1] then 1 else if !IsNaN(SLine8[1]) and IsNaN(SLine8) then 0 else if !IsNaN(SLine8) then SLine8Length[1] + 1 else 0;
def SLine8Long = if !IsNaN(SLineP8[1]) and SLine8[1]!=SLine8 then (GetValue(open,(SLine8Length[1]-1))-SLine8[1]) + SLine8Long[1] else SLine8Long[1];
#----------------------------------------------------------------------------------
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();
def SLine9EndCount = if !IsNaN(SLineP9[1]) and SLine9[1]!=SLine9 then SLine9EndCount[1]+1 else SLine9EndCount[1];
def SLine9Length = if SLine9 != SLine9[1] then 1 else if !IsNaN(SLine9[1]) and IsNaN(SLine9) then 0 else if !IsNaN(SLine9) then SLine9Length[1] + 1 else 0;
def SLine9Long = if !IsNaN(SLineP9[1]) and SLine9[1]!=SLine9 then (GetValue(open,(SLine9Length[1]-1))-SLine9[1]) + SLine9Long[1] else SLine9Long[1];
#----------------------------------------------------------------------------------
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();
def SLine10EndCount = if !IsNaN(SLineP10[1]) and SLine10[1]!=SLine10 then SLine10EndCount[1]+1 else SLine10EndCount[1];
def SLine10Length = if SLine10 != SLine10[1] then 1 else if !IsNaN(SLine10[1]) and IsNaN(SLine10) then 0 else if !IsNaN(SLine10) then SLine10Length[1] + 1 else 0;
def SLine10Long = if !IsNaN(SLineP10[1]) and SLine10[1]!=SLine10 then (GetValue(open,(SLine10Length[1]-1))-SLine10[1]) + SLine10Long[1] else SLine10Long[1];
#----------------------------------------------------------------------------------
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();
def SLine11EndCount = if !IsNaN(SLineP11[1]) and SLine11[1]!=SLine11 then SLine11EndCount[1]+1 else SLine11EndCount[1];
def SLine11Length = if SLine11 != SLine11[1] then 1 else if !IsNaN(SLine11[1]) and IsNaN(SLine11) then 0 else if !IsNaN(SLine11) then SLine11Length[1] + 1 else 0;
def SLine11Long = if !IsNaN(SLineP11[1]) and SLine11[1]!=SLine11 then (GetValue(open,(SLine11Length[1]-1))-SLine11[1]) + SLine11Long[1] else SLine11Long[1];
#----------------------------------------------------------------------------------
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();
def SLine12EndCount = if !IsNaN(SLineP12[1]) and SLine12[1]!=SLine12 then SLine12EndCount[1]+1 else SLine12EndCount[1];
def SLine12Length = if SLine12 != SLine12[1] then 1 else if !IsNaN(SLine12[1]) and IsNaN(SLine12) then 0 else if !IsNaN(SLine12) then SLine12Length[1] + 1 else 0;
def SLine12Long =  if !IsNaN(SLineP12[1]) and SLine12[1]!=SLine12 then (GetValue(open,(SLine12Length[1]-1))-SLine12[1]) + SLine12Long[1] else SLine12Long[1];
#----------------------------------------------------------------------------------
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();
def SLine13EndCount = if !IsNaN(SLineP13[1]) and SLine13[1]!=SLine13 then SLine13EndCount[1]+1 else SLine13EndCount[1];
def SLine13Length = if SLine13 != SLine13[1] then 1 else if !IsNaN(SLine13[1]) and IsNaN(SLine13) then 0 else if !IsNaN(SLine13) then SLine13Length[1] + 1 else 0;
def SLine13Long = if !IsNaN(SLineP13[1]) and SLine13[1]!=SLine13 then (GetValue(open,(SLine13Length[1]-1))-SLine13[1]) + SLine13Long[1] else SLine13Long[1];
#----------------------------------------------------------------------------------
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();
def SLine14EndCount = if !IsNaN(SLineP14[1]) and SLine14[1]!=SLine14 then SLine14EndCount[1]+1 else SLine14EndCount[1];
def SLine14Length = if SLine14 != SLine14[1] then 1 else if !IsNaN(SLine14[1]) and IsNaN(SLine14) then 0 else if !IsNaN(SLine14) then SLine14Length[1] + 1 else 0;
def SLine14Long = if !IsNaN(SLineP14[1]) and SLine14[1]!=SLine14 then (GetValue(open,(SLine14Length[1]-1))-SLine14[1]) + SLine14Long[1] else SLine14Long[1];
#----------------------------------------------------------------------------------
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();
def SLine15EndCount = if !IsNaN(SLineP15[1]) and SLine15[1]!=SLine15 then SLine15EndCount[1]+1 else SLine15EndCount[1];
def SLine15Length = if SLine15 != SLine15[1] then 1 else if !IsNaN(SLine15[1]) and IsNaN(SLine15) then 0 else if !IsNaN(SLine15) then SLine15Length[1] + 1 else 0;
def SLine15Long = if !IsNaN(SLineP15[1]) and SLine15[1]!=SLine15 then (GetValue(open,(SLine15Length[1]-1))-SLine15[1]) + SLine15Long[1] else SLine15Long[1];
#----------------------------------------------------------------------------------
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();
def SLine16EndCount = if !IsNaN(SLineP16[1]) and SLine16[1]!=SLine16 then SLine16EndCount[1]+1 else SLine16EndCount[1];
def SLine16Length = if SLine16 != SLine16[1] then 1 else if !IsNaN(SLine16[1]) and IsNaN(SLine16) then 0 else if !IsNaN(SLine16) then SLine16Length[1] + 1 else 0;
def SLine16Long = if !IsNaN(SLineP16[1]) and SLine16[1]!=SLine16 then (GetValue(open,(SLine16Length[1]-1))-SLine16[1]) + SLine16Long[1] else SLine16Long[1];
#----------------------------------------------------------------------------------
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();
def SLine17EndCount = if !IsNaN(SLineP17[1]) and SLine17[1]!=SLine17 then SLine17EndCount[1]+1 else SLine17EndCount[1];
def SLine17Length = if SLine17 != SLine17[1] then 1 else if !IsNaN(SLine17[1]) and IsNaN(SLine17) then 0 else if !IsNaN(SLine17) then SLine17Length[1] + 1 else 0;
def SLine17Long = if !IsNaN(SLineP17[1]) and SLine17[1]!=SLine17 then (GetValue(open,(SLine17Length[1]-1))-SLine17[1]) + SLine17Long[1] else SLine17Long[1];
#----------------------------------------------------------------------------------
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();
def SLine18EndCount = if !IsNaN(SLineP18[1]) and SLine18[1]!=SLine18 then SLine18EndCount[1]+1 else SLine18EndCount[1];
def SLine18Length = if SLine18 != SLine18[1] then 1 else if !IsNaN(SLine18[1]) and IsNaN(SLine18) then 0 else if !IsNaN(SLine18) then SLine18Length[1] + 1 else 0;
def SLine18Long = if !IsNaN(SLineP18[1]) and SLine18[1]!=SLine18 then (GetValue(open,(SLine18Length[1]-1))-SLine18[1]) + SLine18Long[1] else SLine18Long[1];
#----------------------------------------------------------------------------------
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();
def SLine19EndCount = if !IsNaN(SLineP19[1]) and SLine19[1]!=SLine19 then SLine19EndCount[1]+1 else SLine19EndCount[1];
def SLine19Length = if SLine19 != SLine19[1] then 1 else if !IsNaN(SLine19[1]) and IsNaN(SLine19) then 0 else if !IsNaN(SLine19) then SLine19Length[1] + 1 else 0;
def SLine19Long = if !IsNaN(SLineP19[1]) and SLine19[1]!=SLine19 then (GetValue(open,(SLine19Length[1]-1))-SLine19[1]) + SLine19Long[1] else SLine19Long[1];
#----------------------------------------------------------------------------------
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.CYAN);
SLineP20.SetLineWeight(1);
SLineP20.HideBubble();
def SLine20EndCount = if !IsNaN(SLineP20[1]) and SLine20[1]!=SLine20 then SLine20EndCount[1]+1 else SLine20EndCount[1];
def SLine20Length = if SLine20 != SLine20[1] then 1 else if !IsNaN(SLine20[1]) and IsNaN(SLine20) then 0 else if !IsNaN(SLine20) then SLine20Length[1] + 1 else 0;
def SLine20Long = if !IsNaN(SLineP20[1]) and SLine20[1]!=SLine20 then (GetValue(open,(SLine20Length[1]-1))-SLine20[1]) + SLine20Long[1] else SLine20Long[1];
#----------------------------------------------------------------------------------
#####################################################################################
########################################################################################
#####################################################################################
def TotalSCloses = SLine0EndCount + SLine1EndCount + SLine2EndCount + SLine3EndCount
+ SLine4EndCount + SLine5EndCount + SLine6EndCount + SLine7EndCount + SLine8EndCount + SLine9EndCount
+ SLine10EndCount + SLine11EndCount + SLine12EndCount + SLine13EndCount + SLine14EndCount + SLine15EndCount + SLine16EndCount
+ SLine17EndCount + SLine18EndCount + SLine19EndCount + SLine20EndCount;
#####################################################################################
def TotalShortClosed = SLine0Long + SLine1Long + SLine2Long + SLine3Long + SLine4Long + SLine5Long + SLine6Long + SLine7Long + SLine8Long + SLine9Long +
    SLine10Long + SLine11Long + SLine12Long + SLine13Long + SLine14Long + SLine15Long + SLine16Long + SLine17Long + SLine18Long + SLine19Long + SLine20Long;
#####################################################################################
def TotalShortOpen = If !IsNaN(close) and IsNaN(close[-1]) then(If(!IsNaN(SLineP0),SLine0-close,0) + If(!IsNaN(SLineP1),SLine1-close,0)
 + If(!IsNaN(SLineP1),SLine1-close,0) + If(!IsNaN(SLineP2),SLine2-close,0) + If(!IsNaN(SLineP3),SLine3-close,0) + If(!IsNaN(SLineP4),SLine4-close,0)
 + If(!IsNaN(SLineP5),SLine5-close,0) + If(!IsNaN(SLineP6),SLine6-close,0) + If(!IsNaN(SLineP7),SLine7-close,0) + If(!IsNaN(SLineP8),SLine8-close,0)
 + If(!IsNaN(SLineP9),SLine9-close,0) + If(!IsNaN(SLineP10),SLine10-close,0) + If(!IsNaN(SLineP11),SLine11-close,0) + If(!IsNaN(SLineP12),SLine12-close,0)
 + If(!IsNaN(SLineP13),SLine13-close,0) + If(!IsNaN(SLineP14),SLine14-close,0) + If(!IsNaN(SLineP15),SLine15-close,0) + If(!IsNaN(SLineP16),SLine16-close,0)
 + If(!IsNaN(SLineP17),SLine17-close,0) + If(!IsNaN(SLineP18),SLine18-close,0) + If(!IsNaN(SLineP19),SLine19-close,0) + If(!IsNaN(SLineP20),SLine20-close,0)) else 0;

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

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

}else if (!IsNaN(ResistanceLevel) and RLine0[1]<>0 and high>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and RLine1[1]<>0 and high>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and RLine2[1]<>0 and high>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and RLine3[1]<>0 and high>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and RLine4[1]<>0 and high>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and RLine5[1]<>0 and high>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and RLine6[1]<>0 and high>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and RLine7[1]<>0 and high>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and RLine8[1]<>0 and high>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and RLine9[1]<>0 and high>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and RLine10[1]<>0 and high>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and RLine11[1]<>0 and high>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and RLine12[1]<>0 and high>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and RLine13[1]<>0 and high>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and RLine14[1]<>0 and high>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and RLine15[1]<>0 and high>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and RLine16[1]<>0 and high>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and RLine17[1]<>0 and high>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and RLine18[1]<>0 and high>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and RLine19[1]<>0 and high>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and RLine20[1]<>0 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 0 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 RLine0EndCount = if !IsNaN(RLineP0[1]) and RLine0[1]!=RLine0 then RLine0EndCount[1]+1 else RLine0EndCount[1];
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;
def RLine0Long = If !IsNaN(RLineP0[1]) and IsNaN(RLineP0) then (RLine0[1]-GetValue(open,(RLine0Length[1]-1))) + RLine0Long[1] else RLine0Long[1];
#----------------------------------------------------------------------------------
RLine1 = if !IsNaN(ResistanceLevel) and RLineCount == 1 then ResistanceLevel else if !IsNaN(RLine1[1]) and high >= RLine1[1] then 0 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 RLine1EndCount = if !IsNaN(RLineP1[1]) and RLine1[1]!=RLine1 then RLine1EndCount[1]+1 else RLine1EndCount[1];
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;
def RLine1Long = If !IsNaN(RLineP1[1]) and IsNaN(RLineP1) then (RLine1[1]-GetValue(open,(RLine1Length[1]-1))) + RLine1Long[1] else RLine1Long[1];
#----------------------------------------------------------------------------------
RLine2 = if !IsNaN(ResistanceLevel) and RLineCount == 2 then ResistanceLevel else if !IsNaN(RLine2[1]) and high >= RLine2[1] then 0 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 RLine2EndCount = if !IsNaN(RLineP2[1]) and RLine2[1]!=RLine2 then RLine2EndCount[1]+1 else RLine2EndCount[1];
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;
def RLine2Long = If !IsNaN(RLineP2[1]) and IsNaN(RLineP2) then (RLine2[1]-GetValue(open,(RLine2Length[1]-1))) + RLine2Long[1] else RLine2Long[1];
#----------------------------------------------------------------------------------
RLine3 = if !IsNaN(ResistanceLevel) and RLineCount == 3 then ResistanceLevel else if !IsNaN(RLine3[1]) and high >= RLine3[1] then 0 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 RLine3EndCount = if !IsNaN(RLineP3[1]) and RLine3[1]!=RLine3 then RLine3EndCount[1]+1 else RLine3EndCount[1];
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;
def RLine3Long = If !IsNaN(RLineP3[1]) and IsNaN(RLineP3) then (RLine3[1]-GetValue(open,(RLine3Length[1]-1))) + RLine3Long[1] else RLine3Long[1];
#----------------------------------------------------------------------------------
RLine4 = if !IsNaN(ResistanceLevel) and RLineCount == 4 then ResistanceLevel else if !IsNaN(RLine4[1]) and high >= RLine4[1] then 0 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 RLine4EndCount = if !IsNaN(RLineP4[1]) and RLine4[1]!=RLine4 then RLine4EndCount[1]+1 else RLine4EndCount[1];
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;
def RLine4Long = If !IsNaN(RLineP4[1]) and IsNaN(RLineP4) then (RLine4[1]-GetValue(open,(RLine4Length[1]-1))) + RLine4Long[1] else RLine4Long[1];
#----------------------------------------------------------------------------------
RLine5 = if !IsNaN(ResistanceLevel) and RLineCount == 5 then ResistanceLevel else if !IsNaN(RLine5[1]) and high >= RLine5[1] then 0 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 RLine5EndCount = if !IsNaN(RLineP5[1]) and RLine5[1]!=RLine5 then RLine5EndCount[1]+1 else RLine5EndCount[1];
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;
def RLine5Long = If !IsNaN(RLineP5[1]) and IsNaN(RLineP5) then (RLine5[1]-GetValue(open,(RLine5Length[1]-1))) + RLine5Long[1] else RLine5Long[1];
#----------------------------------------------------------------------------------
RLine6 = if !IsNaN(ResistanceLevel) and RLineCount == 6 then ResistanceLevel else if !IsNaN(RLine6[1]) and high >= RLine6[1] then 0 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();
def RLine6EndCount = if !IsNaN(RLineP6[1]) and RLine6[1]!=RLine6 then RLine6EndCount[1]+1 else RLine6EndCount[1];
def RLine6Length = if RLine6 != RLine6[1] then 1 else if !IsNaN(RLine6[1]) and IsNaN(RLine6) then 0 else if !IsNaN(RLine6) then RLine6Length[1] + 1 else 0;
def RLine6Long = If !IsNaN(RLineP6[1]) and IsNaN(RLineP6) then (RLine6[1]-GetValue(open,(RLine6Length[1]-1))) + RLine6Long[1] else RLine6Long[1];
#----------------------------------------------------------------------------------
RLine7 = if !IsNaN(ResistanceLevel) and RLineCount == 7 then ResistanceLevel else if !IsNaN(RLine7[1]) and high >= RLine7[1] then 0 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();
def RLine7EndCount = if !IsNaN(RLineP7[1]) and RLine7[1]!=RLine7 then RLine7EndCount[1]+1 else RLine7EndCount[1];
def RLine7Length = if RLine7 != RLine7[1] then 1 else if !IsNaN(RLine7[1]) and IsNaN(RLine7) then 0 else if !IsNaN(RLine7) then RLine7Length[1] + 1 else 0;
def RLine7Long = If !IsNaN(RLineP7[1]) and IsNaN(RLineP7) then (RLine7[1]-GetValue(open,(RLine7Length[1]-1))) + RLine7Long[1] else RLine7Long[1];
#----------------------------------------------------------------------------------
RLine8 = if !IsNaN(ResistanceLevel) and RLineCount == 8 then ResistanceLevel else if !IsNaN(RLine8[1]) and high >= RLine8[1] then 0 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();
def RLine8EndCount = if !IsNaN(RLineP8[1]) and RLine8[1]!=RLine8 then RLine8EndCount[1]+1 else RLine8EndCount[1];
def RLine8Length = if RLine8 != RLine8[1] then 1 else if !IsNaN(RLine8[1]) and IsNaN(RLine8) then 0 else if !IsNaN(RLine8) then RLine8Length[1] + 1 else 0;
def RLine8Long = If !IsNaN(RLineP8[1]) and IsNaN(RLineP8) then (RLine8[1]-GetValue(open,(RLine8Length[1]-1))) + RLine8Long[1] else RLine8Long[1];
#----------------------------------------------------------------------------------
RLine9 = if !IsNaN(ResistanceLevel) and RLineCount == 9 then ResistanceLevel else if !IsNaN(RLine9[1]) and high >= RLine9[1] then 0 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();
def RLine9EndCount = if !IsNaN(RLineP9[1]) and RLine9[1]!=RLine9 then RLine9EndCount[1]+1 else RLine9EndCount[1];
def RLine9Length = if RLine9 != RLine9[1] then 1 else if !IsNaN(RLine9[1]) and IsNaN(RLine9) then 0 else if !IsNaN(RLine9) then RLine9Length[1] + 1 else 0;
def RLine9Long = If !IsNaN(RLineP9[1]) and IsNaN(RLineP9) then (RLine9[1]-GetValue(open,(RLine9Length[1]-1))) + RLine9Long[1] else RLine9Long[1];
#----------------------------------------------------------------------------------
RLine10 = if !IsNaN(ResistanceLevel) and RLineCount == 10 then ResistanceLevel else if !IsNaN(RLine10[1]) and high >= RLine10[1] then 0 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();
def RLine10EndCount = if !IsNaN(RLineP10[1]) and RLine10[1]!=RLine10 then RLine10EndCount[1]+1 else RLine10EndCount[1];
def RLine10Length = if RLine10 != RLine10[1] then 1 else if !IsNaN(RLine10[1]) and IsNaN(RLine10) then 0 else if !IsNaN(RLine10) then RLine10Length[1] + 1 else 0;
def RLine10Long = If !IsNaN(RLineP10[1]) and IsNaN(RLineP10) then (RLine10[1]-GetValue(open,(RLine10Length[1]-1))) + RLine10Long[1] else RLine10Long[1];
#----------------------------------------------------------------------------------
RLine11 = if !IsNaN(ResistanceLevel) and RLineCount == 11 then ResistanceLevel else if !IsNaN(RLine11[1]) and high >= RLine11[1] then 0 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();
def RLine11EndCount = if !IsNaN(RLineP11[1]) and RLine11[1]!=RLine11 then RLine11EndCount[1]+1 else RLine11EndCount[1];
def RLine11Length = if RLine11 != RLine11[1] then 1 else if !IsNaN(RLine11[1]) and IsNaN(RLine11) then 0 else if !IsNaN(RLine11) then RLine11Length[1] + 1 else 0;
def RLine11Long = If !IsNaN(RLineP11[1]) and IsNaN(RLineP11) then (RLine11[1]-GetValue(open,(RLine11Length[1]-1))) + RLine11Long[1] else RLine11Long[1];
#----------------------------------------------------------------------------------
RLine12 = if !IsNaN(ResistanceLevel) and RLineCount == 12 then ResistanceLevel else if !IsNaN(RLine12[1]) and high >= RLine12[1] then 0 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();
def RLine12EndCount = if !IsNaN(RLineP12[1]) and RLine12[1]!=RLine12 then RLine12EndCount[1]+1 else RLine12EndCount[1];
def RLine12Length = if RLine12 != RLine12[1] then 1 else if !IsNaN(RLine12[1]) and IsNaN(RLine12) then 0 else if !IsNaN(RLine12) then RLine12Length[1] + 1 else 0;
def RLine12Long = If !IsNaN(RLineP12[1]) and IsNaN(RLineP12) then (RLine12[1]-GetValue(open,(RLine12Length[1]-1))) + RLine12Long[1] else RLine12Long[1];
#----------------------------------------------------------------------------------
RLine13 = if !IsNaN(ResistanceLevel) and RLineCount == 13 then ResistanceLevel else if !IsNaN(RLine13[1]) and high >= RLine13[1] then 0 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();
def RLine13EndCount = if !IsNaN(RLineP13[1]) and RLine13[1]!=RLine13 then RLine13EndCount[1]+1 else RLine13EndCount[1];
def RLine13Length = if RLine13 != RLine13[1] then 1 else if !IsNaN(RLine13[1]) and IsNaN(RLine13) then 0 else if !IsNaN(RLine13) then RLine13Length[1] + 1 else 0;
def RLine13Long = If !IsNaN(RLineP13[1]) and IsNaN(RLineP13) then (RLine13[1]-GetValue(open,(RLine13Length[1]-1))) + RLine13Long[1] else RLine13Long[1];
#----------------------------------------------------------------------------------
RLine14 = if !IsNaN(ResistanceLevel) and RLineCount == 14 then ResistanceLevel else if !IsNaN(RLine14[1]) and high >= RLine14[1] then 0 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();
def RLine14EndCount = if !IsNaN(RLineP14[1]) and RLine14[1]!=RLine14 then RLine14EndCount[1]+1 else RLine14EndCount[1];
def RLine14Length = if RLine14 != RLine14[1] then 1 else if !IsNaN(RLine14[1]) and IsNaN(RLine14) then 0 else if !IsNaN(RLine14) then RLine14Length[1] + 1 else 0;
def RLine14Long = If !IsNaN(RLineP14[1]) and IsNaN(RLineP14) then (RLine14[1]-GetValue(open,(RLine14Length[1]-1))) + RLine14Long[1] else RLine14Long[1];
#----------------------------------------------------------------------------------
RLine15 = if !IsNaN(ResistanceLevel) and RLineCount == 15 then ResistanceLevel else if !IsNaN(RLine15[1]) and high >= RLine15[1] then 0 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();
def RLine15EndCount = if !IsNaN(RLineP15[1]) and RLine15[1]!=RLine15 then RLine15EndCount[1]+1 else RLine15EndCount[1];
def RLine15Length = if RLine15 != RLine15[1] then 1 else if !IsNaN(RLine15[1]) and IsNaN(RLine15) then 0 else if !IsNaN(RLine15) then RLine15Length[1] + 1 else 0;
def RLine15Long = If !IsNaN(RLineP15[1]) and IsNaN(RLineP15) then (RLine15[1]-GetValue(open,(RLine15Length[1]-1))) + RLine15Long[1] else RLine15Long[1];
#----------------------------------------------------------------------------------
RLine16 = if !IsNaN(ResistanceLevel) and RLineCount == 16 then ResistanceLevel else if !IsNaN(RLine16[1]) and high >= RLine16[1] then 0 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();
def RLine16EndCount = if !IsNaN(RLineP16[1]) and RLine16[1]!=RLine16 then RLine16EndCount[1]+1 else RLine16EndCount[1];
def RLine16Length = if RLine16 != RLine16[1] then 1 else if !IsNaN(RLine16[1]) and IsNaN(RLine16) then 0 else if !IsNaN(RLine16) then RLine16Length[1] + 1 else 0;
def RLine16Long = If !IsNaN(RLineP16[1]) and IsNaN(RLineP16) then (RLine16[1]-GetValue(open,(RLine16Length[1]-1))) + RLine16Long[1] else RLine16Long[1];
#----------------------------------------------------------------------------------
RLine17 = if !IsNaN(ResistanceLevel) and RLineCount == 17 then ResistanceLevel else if !IsNaN(RLine17[1]) and high >= RLine17[1] then 0 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();
def RLine17EndCount = if !IsNaN(RLineP17[1]) and RLine17[1]!=RLine17 then RLine17EndCount[1]+1 else RLine17EndCount[1];
def RLine17Length = if RLine17 != RLine17[1] then 1 else if !IsNaN(RLine17[1]) and IsNaN(RLine17) then 0 else if !IsNaN(RLine17) then RLine17Length[1] + 1 else 0;
def RLine17Long = If !IsNaN(RLineP17[1]) and IsNaN(RLineP17) then (RLine17[1]-GetValue(open,(RLine17Length[1]-1))) + RLine17Long[1] else RLine17Long[1];
#----------------------------------------------------------------------------------
RLine18 = if !IsNaN(ResistanceLevel) and RLineCount == 18 then ResistanceLevel else if !IsNaN(RLine18[1]) and high >= RLine18[1] then 0 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();
def RLine18EndCount = if !IsNaN(RLineP18[1]) and RLine18[1]!=RLine18 then RLine18EndCount[1]+1 else RLine18EndCount[1];
def RLine18Length = if RLine18 != RLine18[1] then 1 else if !IsNaN(RLine18[1]) and IsNaN(RLine18) then 0 else if !IsNaN(RLine18) then RLine18Length[1] + 1 else 0;
def RLine18Long = If !IsNaN(RLineP18[1]) and IsNaN(RLineP18) then (RLine18[1]-GetValue(open,(RLine18Length[1]-1))) + RLine18Long[1] else RLine18Long[1];
#----------------------------------------------------------------------------------
RLine19 = if !IsNaN(ResistanceLevel) and RLineCount == 19 then ResistanceLevel else if !IsNaN(RLine19[1]) and high >= RLine19[1] then 0 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();
def RLine19EndCount = if !IsNaN(RLineP19[1]) and RLine19[1]!=RLine19 then RLine19EndCount[1]+1 else RLine19EndCount[1];
def RLine19Length = if RLine19 != RLine19[1] then 1 else if !IsNaN(RLine19[1]) and IsNaN(RLine19) then 0 else if !IsNaN(RLine19) then RLine19Length[1] + 1 else 0;
def RLine19Long = If !IsNaN(RLineP19[1]) and IsNaN(RLineP19) then (RLine19[1]-GetValue(open,(RLine19Length[1]-1))) + RLine19Long[1] else RLine19Long[1];
#----------------------------------------------------------------------------------
RLine20 = if !IsNaN(ResistanceLevel) and RLineCount == 20 then ResistanceLevel else if !IsNaN(RLine20[1]) and high >= RLine20[1] then 0 else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_ORANGE);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
def RLine20EndCount = if !IsNaN(RLineP20[1]) and RLine20[1]!=RLine20 then RLine20EndCount[1]+1 else RLine20EndCount[1];
def RLine20Length = if RLine20 != RLine20[1] then 1 else if !IsNaN(RLine20[1]) and IsNaN(RLine20) then 0 else if !IsNaN(RLine20) then RLine20Length[1] + 1 else 0;
def RLine20Long = If !IsNaN(RLineP20[1]) and IsNaN(RLineP20) then (RLine20[1]-GetValue(open,(RLine20Length[1]-1))) + RLine20Long[1] else RLine20Long[1];
#####################################################################################
#####################################################################################
def TotalRCloses = RLine0EndCount + RLine1EndCount + RLine2EndCount + RLine3EndCount
+ RLine4EndCount + RLine5EndCount + RLine6EndCount + RLine7EndCount + RLine8EndCount + RLine9EndCount
+ RLine10EndCount + RLine11EndCount + RLine12EndCount + RLine13EndCount + RLine14EndCount + RLine15EndCount + RLine16EndCount
+ RLine17EndCount + RLine18EndCount + RLine19EndCount + RLine20EndCount;
#######################################################################################
def TotalLongClosed = RLine0Long + RLine1Long + RLine2Long + RLine3Long + RLine4Long + RLine5Long + RLine6Long + RLine7Long + RLine8Long + RLine9Long +    
    RLine10Long + RLine11Long + RLine12Long + RLine13Long + RLine14Long + RLine15Long + RLine16Long + RLine17Long + RLine18Long + RLine19Long + RLine20Long;
#######################################################################################
def TotalLongOpen = If !IsNaN(close) and IsNaN(close[-1]) then(If(!IsNaN(RLineP0),RLine0-close,0) + If(!IsNaN(RLineP1),RLine1-close,0)
 + If(!IsNaN(RLineP1),RLine1-close,0) + If(!IsNaN(RLineP2),RLine2-close,0) + If(!IsNaN(RLineP3),RLine3-close,0) + If(!IsNaN(RLineP4),RLine4-close,0)
 + If(!IsNaN(RLineP5),RLine5-close,0) + If(!IsNaN(RLineP6),RLine6-close,0) + If(!IsNaN(RLineP7),RLine7-close,0) + If(!IsNaN(RLineP8),RLine8-close,0)
 + If(!IsNaN(RLineP9),RLine9-close,0) + If(!IsNaN(RLineP10),RLine10-close,0) + If(!IsNaN(RLineP11),RLine11-close,0) + If(!IsNaN(RLineP12),RLine12-close,0)
 + If(!IsNaN(RLineP13),RLine13-close,0) + If(!IsNaN(RLineP14),RLine14-close,0) + If(!IsNaN(RLineP15),RLine15-close,0) + If(!IsNaN(RLineP16),RLine16-close,0)
 + If(!IsNaN(RLineP17),RLine17-close,0) + If(!IsNaN(RLineP18),RLine18-close,0) + If(!IsNaN(RLineP19),RLine19-close,0) + If(!IsNaN(RLineP20),RLine20-close,0)) else 0;

#######################################################################################

def RStart = if !IsNaN(ResistanceLevel) and Days>0 then RStart[1]+1 else RStart[1];
def GStart = if !IsNaN(SupportLevel) and Days>0 then GStart[1]+1 else GStart[1];
Addlabel(Study==2,"Long Positions Opened: "+RStart,color.CYAN);
Addlabel(Study==2,"Long Positions Closed: "+TotalRCloses,color.CYAN);
AddLabel(Study==2,RStart-TotalRCloses+" Long Positions Still Open",color.CYAN );
Addlabel(Study==2,"Short Positions Opened: "+GStart,color.YELLOW);
Addlabel(Study==2,"Short Positions Closed: "+TotalSCloses,color.YELLOW);
AddLabel(Study==2,GStart-TotalSCloses+" Short Positions Still Open",color.YELLOW);
Addlabel(Study==2,"Total Short Gain: " + ((AbsValue(TotalShortClosed)/ticksize())*tickvalue()),color.WHITE);
Addlabel(Study==2,"Running Short Loss " + ((AbsValue(TotalShortOpen)/ticksize())*tickvalue()),color.white);
Addlabel(Study==2,"Total Long Gain: " + ((TotalLongClosed/ticksize())*tickvalue()),color.WHITE);
Addlabel(Study==2,"Running Long Loss: " + ((TotalLongOpen/ticksize())*tickvalue()),color.white);
AddLabel(Study==2,"Total Gain: "+ (((TotalLongClosed+TotalShortClosed)/ticksize())*tickvalue()),color.LIGHT_GREEN);
AddLabel(Study==2,"Total Still Open: "+ (((AbsValue(TotalShortOpen)+TotalLongOpen)/ticksize())*tickvalue()),color.LIGHT_ORANGE);

#End of Code#
 
Last edited:
@Department
3. Criteria: not in code Isolate for important volume through ranking system = check last few candles, rank them 1-#, then select only highest x candle. This filters out noise and increases chance of price target being exact.
5.1. Timing the Reversal: The proper way to time the reversal for this strategy is through volume analysis. However, I have no idea how to explain it adequately in words but I'll try. The premise is to look at consolidation, look for candles going away from the price target (if price target is above focus on red (down) candles, if target below focus on green (up) candles), and look for extremely low volume. Enter on this candle. - Stop below low of consolidation range, target at price target line drawn.

Can you show an example of either one? I may have some existing scripts that can be modified to help with these criteria.
 
@Department



Can you show an example of either one? I may have some existing scripts that can be modified to help with these criteria.
well apparently Imgur won't let me upload images so that is awkward.
3.Volume Classification
def vol = volume;
def pos5 = if vol[4] < vol then 1 else 0; #Adds 1 to rank if current candle has higher volume
def pos4 = if vol[3] < vol then 1 else 0;
def pos3 = if vol[2] < vol then 1 else 0;
def pos2 = if vol[1] < vol then 1 else 0;

def rank = pos5 + pos4 + pos3 + pos2; #Higher rank = more important
probably want to adjust rank for up to 8-15 bars (I don't know what the robust # would be)
Proposed changes to this code:
1. Have it only compare the x last green candles volume bars if current candle green
2. Have it only compare the x last red candles volume bars if current candle red
Why?: Because usually red bars come after a streak of large green volume thus the restriction ends up being a bias and misses important candles.

5.1. Timing the Reversal
Apparently I cannot upload images so made this section difficult.
Code would ideally find oddly low volume bars in a consolidation. I cannot think of a way to effectively code this besides using the above volume classification system but in reverse. However, I'm not sure how robust that would be given the difficulty of knowing how long a consolidation is (# of candles in the consolidation region to compare too) - would probably depend on market/symbol traded.
 
Example-1.png

Example-2.png


Mini grey ovals for which candles to look at. Its BKKT in the 7 days ago and 5 days ago (1min chart).
imgur just didn't let me upload any files... it says wrong file type no matter what file I use. It doesn't like me :(
 
@Department
Right now I have two scripts that look to be a good fit for what you are describing.
These are scripts I wrote for other users.

The first acts upon only bars meeting a defined criteria (ex: bars with close>open).
The amount of bars to look for can be adjusted how far back to look can be adjusted.
It currently averages volume, but I've already started to adapt it.
dR0zWpH.png


The seconds is a rolling ranking of the last 10 volume bars.
JjDARC0.png



There is also a script for volume anomalies (not mine) somewhere on the forums.
 
Last edited:
@Department
Right now I have two scripts that look to be a good fit for what you are describing.
These are scripts I wrote for other users.

The first acts upon only bars meeting a defined criteria (ex: bars with close>open).
The amount of bars to look for can be adjusted how far back to look can be adjusted.
It currently averages volume, but I've already started to adapt it.
dR0zWpH.png


The seconds is a rolling ranking of the last 10 volume bars.
JjDARC0.png



There is also a script for volume anomalies (not mine) somewhere on the forums.
Rolling rank of the last 10 bars is perfect. In the script you only allow for a candle that is rank 8 or higher for green, or 5 and higher for red. (They both should be 8 however on average large red comes after large green so it usually ends up not marking unless given this large allowance) Is there a possibility you could share the code? If you want to take it a step further could you figure out how to rank last 10 green bars and last 10 red bars? (Might be difficult because you could in theory get 20 one color bars in a row... I don't know what the robust historical look back for that is). However, your first screen shot seems to deal with that well enough :)

In terms of the volume anomalies might be helpful depending on what it does. Searching it just gives me the anna coulling threads which are not what would be useful for the reversal timings.
 
@Department

Ruby:
declare lower;

def Look_Back = 10;

plot v = volume;
v.setpaintingStrategy(paintingStrategy.HISTOGRAM);
plot zl = 0;

#Rank Last Bar;
def rank = fold i=1 to Look_Back-1 with rankcounter=1 do if volume>GetValue(volume,i) then rankcounter+1 else rankcounter;
addlabel(yes,"Ranking: "+rank,color.white);

#Rolling Rank
def VBar = if !IsNaN(close) then HighestAll(Barnumber()) else VBar[1];

def FinalBar = fold b=0 to VBar while !IsNaN(GetValue(close,-b)) do GetValue(BarNumber(),-b);
AddChartBubble(FinalBar-BarNumber()<Look_Back,volume,fold r=0-(FinalBar-BarNumber()) to Look_Back-(FinalBar-BarNumber()) with rcounter=1 do if volume > GetValue(volume,r) then rcounter+1 else rcounter, color.white);
 
Last edited:
Went ahead and put the rank criteria in for signaling bars.
Insomnia suxks...

syC6ybC.png


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 Greenbar_Minimum_Rank = 8;
input RedBar_Minimum_Rank = 5;
input Ranking_Look_Back_Period = 10;
def greenCandle = open < close;
def redCandle = close < open;
def body = BodyHeight();
def volatility = ATR(history, AverageType.WILDERS);

def highLow = high-low;
def imBody = (body > highLow * 0.5) and (highLow >= volatility * Multiplier);
def VBar = if !IsNaN(close) then HighestAll(Barnumber()) else VBar[1];
def FinalBar = fold b=0 to VBar while !IsNaN(GetValue(close,-b)) do GetValue(BarNumber(),-b);
def rank = fold i=1 to Ranking_Look_Back_Period-1 with rankcounter=1 do if volume>GetValue(volume,i) then rankcounter+1 else rankcounter;

plot RankPlot = if IsNaN(close[-1]) then Rank else Double.NaN;
RankPlot.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

AssignPriceColor(if imbody and greenCandle and rank>=Greenbar_Minimum_Rank and high[1]<close then Color.LIME else Color.CURRENT);
AssignPriceColor(if imbody and redCandle and rank>=RedBar_Minimum_Rank and low[1]>close then Color.DARK_RED else Color.CURRENT);

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

plot GreenBarRank = if GreenBar then rank else Double.NaN;
GreenBarRank.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot RedBarRank = if RedBar then rank else Double.NaN;
RedBarRank.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

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

}else if (!IsNaN(SupportLevel) and SLine0[1]<>0 and low<=SLine0[1]) { SLineCount=0;
}else if (!IsNaN(SupportLevel) and SLine1[1]<>0 and low<=SLine1[1]) { SLineCount=1;
}else if (!IsNaN(SupportLevel) and SLine2[1]<>0 and low<=SLine2[1]) { SLineCount=2;
}else if (!IsNaN(SupportLevel) and SLine3[1]<>0 and low<=SLine3[1]) { SLineCount=3;
}else if (!IsNaN(SupportLevel) and SLine4[1]<>0 and low<=SLine4[1]) { SLineCount=4;
}else if (!IsNaN(SupportLevel) and SLine5[1]<>0 and low<=SLine5[1]) { SLineCount=5;
}else if (!IsNaN(SupportLevel) and SLine6[1]<>0 and low<=SLine6[1]) { SLineCount=6;
}else if (!IsNaN(SupportLevel) and SLine7[1]<>0 and low<=SLine7[1]) { SLineCount=7;
}else if (!IsNaN(SupportLevel) and SLine8[1]<>0 and low<=SLine8[1]) { SLineCount=8;
}else if (!IsNaN(SupportLevel) and SLine9[1]<>0 and low<=SLine9[1]) { SLineCount=9;
}else if (!IsNaN(SupportLevel) and SLine10[1]<>0 and low<=SLine10[1]) { SLineCount=10;
}else if (!IsNaN(SupportLevel) and SLine11[1]<>0 and low<=SLine11[1]) { SLineCount=11;
}else if (!IsNaN(SupportLevel) and SLine12[1]<>0 and low<=SLine12[1]) { SLineCount=12;
}else if (!IsNaN(SupportLevel) and SLine13[1]<>0 and low<=SLine13[1]) { SLineCount=13;
}else if (!IsNaN(SupportLevel) and SLine14[1]<>0 and low<=SLine14[1]) { SLineCount=14;
}else if (!IsNaN(SupportLevel) and SLine15[1]<>0 and low<=SLine15[1]) { SLineCount=15;
}else if (!IsNaN(SupportLevel) and SLine16[1]<>0 and low<=SLine16[1]) { SLineCount=16;
}else if (!IsNaN(SupportLevel) and SLine17[1]<>0 and low<=SLine17[1]) { SLineCount=17;
}else if (!IsNaN(SupportLevel) and SLine18[1]<>0 and low<=SLine18[1]) { SLineCount=18;
}else if (!IsNaN(SupportLevel) and SLine19[1]<>0 and low<=SLine19[1]) { SLineCount=19;
}else if (!IsNaN(SupportLevel) and SLine20[1]<>0 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();
#----------------------------------------------------------------------------------
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.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.CYAN);
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 = 0;
}else if (IsNaN(ResistanceLevel) and RLine0[1]<>0 and high>=RLine0[1]) { RLineCount=20;
}else if (IsNaN(ResistanceLevel) and RLine1[1]<>0 and high>=RLine1[1]) { RLineCount=0;
}else if (IsNaN(ResistanceLevel) and RLine2[1]<>0 and high>=RLine2[1]) { RLineCount=1;
}else if (IsNaN(ResistanceLevel) and RLine3[1]<>0 and high>=RLine3[1]) { RLineCount=2;
}else if (IsNaN(ResistanceLevel) and RLine4[1]<>0 and high>=RLine4[1]) { RLineCount=3;
}else if (IsNaN(ResistanceLevel) and RLine5[1]<>0 and high>=RLine5[1]) { RLineCount=4;
}else if (IsNaN(ResistanceLevel) and RLine6[1]<>0 and high>=RLine6[1]) { RLineCount=5;
}else if (IsNaN(ResistanceLevel) and RLine7[1]<>0 and high>=RLine7[1]) { RLineCount=6;
}else if (IsNaN(ResistanceLevel) and RLine8[1]<>0 and high>=RLine8[1]) { RLineCount=7;
}else if (IsNaN(ResistanceLevel) and RLine9[1]<>0 and high>=RLine9[1]) { RLineCount=8;
}else if (IsNaN(ResistanceLevel) and RLine10[1]<>0 and high>=RLine10[1]) { RLineCount=9;
}else if (IsNaN(ResistanceLevel) and RLine11[1]<>0 and high>=RLine11[1]) { RLineCount=10;
}else if (IsNaN(ResistanceLevel) and RLine12[1]<>0 and high>=RLine12[1]) { RLineCount=11;
}else if (IsNaN(ResistanceLevel) and RLine13[1]<>0 and high>=RLine13[1]) { RLineCount=12;
}else if (IsNaN(ResistanceLevel) and RLine14[1]<>0 and high>=RLine14[1]) { RLineCount=13;
}else if (IsNaN(ResistanceLevel) and RLine15[1]<>0 and high>=RLine15[1]) { RLineCount=14;
}else if (IsNaN(ResistanceLevel) and RLine16[1]<>0 and high>=RLine16[1]) { RLineCount=15;
}else if (IsNaN(ResistanceLevel) and RLine17[1]<>0 and high>=RLine17[1]) { RLineCount=16;
}else if (IsNaN(ResistanceLevel) and RLine18[1]<>0 and high>=RLine18[1]) { RLineCount=17;
}else if (IsNaN(ResistanceLevel) and RLine19[1]<>0 and high>=RLine19[1]) { RLineCount=18;
}else if (IsNaN(ResistanceLevel) and RLine20[1]<>0 and high>=RLine20[1]) { RLineCount=19;

}else if (!IsNaN(ResistanceLevel) and RLine0[1]<>0 and high>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and RLine1[1]<>0 and high>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and RLine2[1]<>0 and high>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and RLine3[1]<>0 and high>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and RLine4[1]<>0 and high>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and RLine5[1]<>0 and high>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and RLine6[1]<>0 and high>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and RLine7[1]<>0 and high>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and RLine8[1]<>0 and high>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and RLine9[1]<>0 and high>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and RLine10[1]<>0 and high>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and RLine11[1]<>0 and high>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and RLine12[1]<>0 and high>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and RLine13[1]<>0 and high>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and RLine14[1]<>0 and high>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and RLine15[1]<>0 and high>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and RLine16[1]<>0 and high>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and RLine17[1]<>0 and high>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and RLine18[1]<>0 and high>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and RLine19[1]<>0 and high>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and RLine20[1]<>0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 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 0 else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_ORANGE);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
#####################################################################################
#####################################################################################

#End of Code#
 
Last edited:
@Department
Noticed using the rolling rank to identifying bars for creating plots from was not working unless the bar held a rank above the minimum for the full look back period.
This was causing bars that met criteria to not plot.

Changed the above code to only rank the last bar for minimum rank.
Seems to work correctly now.
 
@Department
Noticed using the rolling rank to identifying bars for creating plots from was not working unless the bar held a rank above the minimum for the full look back period.
This was causing bars that met criteria to not plot.

Changed the above code to only rank the last bar for minimum rank.
Seems to work correctly now.
Yeah if I understood correctly that is how I have my code set up as well. Only care about the rank of the current candle. I think the code there is essentially done. Anything else is just luxury. Have to say thank you for taking so much time to work on this project. I hope people on this forum learn something from your work or get new ideas as I have!

If there is anything else I'll try to keep an eye on this thread. In about a month I might be for a while working on a futures projects :)
 
Finally got a chance to set down and code this out the way I wanted it.
If anyone is interested here is two scripts:
The first plots a line for average buy volume or sell volume for a number of bars defined by input.
The second is a rolling rank of buy volume and sell volume separately for a number of bars defined by input.
Currently neither count volume for a bar that has a close price equal to open. (Should I change that and count it for both???)
Combine both scripts on the same lower chart and it looks very interesting.

This is plots of the last 5 bars average buy (Green Line) and sell (Red Line) volume and rolling rank of the last 5 bars of
buy volume and sell volume separately.
dTISlKW.png


Seperate Average Plots.
Ruby:
#Plot of volume averages
#Coded by Svanoy
declare lower;

input Candle = {default "Green Candle", "Red Candle"};
input Number_Of_Signals_To_Be_Averaged = 5;
input Value_To_Be_Averaged = volume;
def BarNumber_Offset = 1000;
def bar = BarNumber();
def barNum = if !IsNaN(close) and BarNumber()>0 then bar else barNum[1];
def VBar = if if(!IsNaN(close[-BarNumber_Offset]),!IsNaN(close[-BarNumber_Offset]),IsNaN(close[-BarNumber_Offset])) then barNum[-BarNumber_Offset] else VBar[1];

def LastBarNumber = fold lbn = 0 to VBar while !IsNaN(GetValue(close, -lbn)) do GetValue(BarNum, -lbn);
def Look_Back_Period = VBar;
def GreenCandle = close > open;
def RedCandle = close < open;
def Signal;
switch (Candle) {
case "Green Candle":
    Signal = GreenCandle;
case "Red Candle":
    Signal = RedCandle;
}
def TotalSignalCount = if Signal then TotalSignalCount[1] + 1 else TotalSignalCount[1];
def SignalBarNumber = if Signal then BarNum else SignalBarNumber[1];
def FinalCount = fold fc = 0 to VBar while !IsNaN(GetValue(close, -fc)) do GetValue(TotalSignalCount, -fc);

def SignalRangeTotal;
def SignalStop;
if barNum == 0 {
    SignalRangeTotal = 0;
    SignalStop = Number_Of_Signals_To_Be_Averaged;
} else if FinalCount - TotalSignalCount < Number_Of_Signals_To_Be_Averaged and LastBarNumber - SignalBarNumber > Look_Back_Period {
    SignalRangeTotal = 0;
    SignalStop = FinalCount - TotalSignalCount;
} else if  FinalCount - TotalSignalCount < Number_Of_Signals_To_Be_Averaged and LastBarNumber - SignalBarNumber <= Look_Back_Period and Signal {
    SignalRangeTotal = SignalRangeTotal[1] + Value_To_Be_Averaged;
    SignalStop = SignalStop[1];
} else {
    SignalRangeTotal = SignalRangeTotal[1];
    SignalStop = SignalStop[1];
}

def RangeAverage;
if (SignalRangeTotal / SignalStop) > 0 and (FinalCount - TotalSignalCount) <= 0 {
    RangeAverage = (SignalRangeTotal / SignalStop);
} else {
    RangeAverage = Double.NaN;
}

def FinalAverage = fold c = 0 to VBar while !IsNaN(GetValue(close, -c)) do GetValue(RangeAverage, -c);

plot GRangeAveragePlot;
plot RRangeAveragePlot;
switch (Candle) {
case "Green Candle":
    GRangeAveragePlot = if((LastBarNumber-barNum)<=Number_Of_Signals_To_Be_Averaged and FinalAverage>0, FinalAverage, Double.NaN);
    RRangeAveragePlot = Double.NaN;
case "Red Candle":
    GRangeAveragePlot = Double.NaN;
    RRangeAveragePlot = if((LastBarNumber-barNum)<=Number_Of_Signals_To_Be_Averaged and FinalAverage>0, FinalAverage, Double.NaN);
}

GRangeAveragePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
GRangeAveragePlot.AssignValueColor(Color.LIGHT_GREEN);
GRangeAveragePlot.SetLineWeight(1);

RRangeAveragePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RRangeAveragePlot.AssignValueColor(Color.LIGHT_RED);
RRangeAveragePlot.SetLineWeight(1);

plot v = volume;
v.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
v.AssignValueColor(if close>open then Color.GREEN else if close<open then Color.RED else color.gray);

Rolling Volume Ranking .
Ruby:
#Rank volume of last red or green bars separately
#Coded by Svanoy

plot v = volume;
v.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
v.AssignValueColor(if close>open then Color.GREEN else if close<open then Color.RED else color.gray);

declare lower;

input Number_Of_Signals_To_Be_Ranked = 5;
input BarNumber_Offset = 1000;
input Show_Last_Bar_Rank_Label = no;
input Show_Last_Bar_Rank_Bubble = no;
input Show_Rolling_Rank = yes;
def GreenCandle = close > open;
def RedCandle = close < open;
def GreenVLine = if GreenCandle then volume else GreenVLine[1];
def RedVLine = if RedCandle then volume else RedVLine[1];
def RollGVLine = if GreenCandle then volume else 0;
def RollRVLine = if RedCandle then volume else 0;
def LastBar = !IsNan(volume) and IsNaN(volume[-1]);
def GLastBar = LastBar and GreenCandle;
def RLastBar = LastBar and RedCandle;

def bar = BarNumber();
def BarNum = if !IsNaN(close) and BarNumber()>0 then bar else BarNum[1];
def VBar = if IsNaN(close[-BarNumber_Offset]) then barNum[-BarNumber_Offset] else VBar[1];
def LastBarNumber = VBar;

def GSignal = GreenCandle;
def RSignal = RedCandle;

##############################################################################
#Rank Last Green Bar;
def TotalGSignalCount = if BarNum==1 then 1 else if GSignal then TotalGSignalCount[1] + 1 else TotalGSignalCount[1];
def FinalGCount = fold g = 0 to VBar while !IsNaN(GetValue(close, -g)) do GetValue(TotalGSignalCount, -g);
def FirstGBarNumber = if FinalGCount-TotalGSignalCount==Number_Of_Signals_To_Be_Ranked then BarNum else FirstGBarNumber[1];
def RankGRange = if !IsNaN(close) then (LastBarNumber-FirstGBarNumber) else RankGRange[1];
def GRank = fold gg=0 to RankGRange with grankcounter=1 do if GreenVLine>GetValue(GreenVLine,gg) and GetValue(GreenCandle,gg) then grankcounter+1 else grankcounter;
def FinalGRank = fold fgr = 0 to VBar while !IsNaN(GetValue(close, -fgr)) do GetValue(GRank, -fgr);

addlabel(Show_Last_Bar_Rank_Label,"Last Green Bar Rank of Last "+Number_Of_Signals_To_Be_Ranked+" Green Bars: "+FinalGRank,color.white);
addchartbubble((Show_Last_Bar_Rank_Bubble and FinalGCount==TotalGSignalCount and GreenCandle and RLastBar) or (Show_Last_Bar_Rank_Bubble and FinalGCount==TotalGSignalCount and GreenCandle and !GLastBar) or (Show_Last_Bar_Rank_Bubble and FinalGCount==TotalGSignalCount and GLastBar),volume,FinalGRank,color.LIGHT_GREEN,yes);

##############################################################################
#Rolling Green Bar Rank
def GRollingRank = fold groll=0-(VBar-BarNum) to (RankGRange)-(VBar-BarNum) with gcounter=1 do if GetValue(GreenVLine,0) > GetValue(GreenVLine,groll) and GetValue(GreenCandle,groll)==1 then gcounter+1 else gcounter;

addchartbubble(Show_Rolling_Rank and GreenCandle and (FinalGCount-TotalgSignalCount)<Number_Of_Signals_To_Be_Ranked,volume,GRollingRank,color.light_green);

##############################################################################
#Rank Last Red Bar;
def TotalRSignalCount = if BarNum==1 then 1 else if RSignal then TotalRSignalCount[1] + 1 else TotalRSignalCount[1];
def FinalRCount = fold r = 0 to VBar while !IsNaN(GetValue(close, -r)) do GetValue(TotalRSignalCount, -r);
def FirstRBarNumber = if FinalRCount-TotalRSignalCount==Number_Of_Signals_To_Be_Ranked then BarNum else FirstRBarNumber[1];
def RankRRange = if !IsNaN(close) then (LastBarNumber-FirstRBarNumber) else RankRRange[1];
def RRank = fold rr=0 to RankRRange with rrankcounter=1 do if RedVLine>GetValue(RedVLine,rr) and GetValue(RedCandle,rr) then rrankcounter+1 else rrankcounter;
def FinalRRank = fold frr = 0 to VBar while !IsNaN(GetValue(close, -frr)) do GetValue(RRank, -frr);

addlabel(Show_Last_Bar_Rank_Label,"Last Red Bar Rank of Last "+Number_Of_Signals_To_Be_Ranked+" Red Bars: "+FinalRRank,color.white);
addchartbubble((Show_Last_Bar_Rank_Bubble and FinalRCount==TotalRSignalCount and RedCandle and GLastBar) or (Show_Last_Bar_Rank_Bubble and FinalRCount==TotalRSignalCount and RedCandle and !RLastBar) or (Show_Last_Bar_Rank_Bubble and FinalRCount==TotalRSignalCount and RLastBar),volume,FinalRRank,color.LIGHT_RED,yes);

##############################################################################
#Rolling Red Bar Rank
def RRollingRank = fold rroll=0-(VBar-BarNum) to (RankRRange)-(VBar-BarNum) with rcounter=1 do if GetValue(RedVLine,0) > GetValue(RedVLine,rroll) and GetValue(RedCandle,rroll)==1 then rcounter+1 else rcounter;

addchartbubble(Show_Rolling_Rank and RedCandle and (FinalRCount-TotalRSignalCount)<Number_Of_Signals_To_Be_Ranked,volume,RRollingRank,color.light_red);
 
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
124 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