#######################################################################################
#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#