Discretionary Support and Resistance Levels For ThinkOrSwim

Clark2001

New member
Hello Everyone, in my quest for searching for a way to make a support and resistance indicator that plots across the screen I ended up with this. I took a levels script that I found on thinkscript here by Trading51 and the Mobius Wolf Waves indicator and combined them. With it I went ahead and added the options for zones as well. I had to add it on my studies a few times to capture a few higher and lower levels but it turned out pretty well.
Screenshot 2024-04-10 202442.png

Code:
#Support and Resistance Levels
#Uses Mobius Wolf Waves & Levels Script
#Information for Scripted Levels found @ https://usethinkscript.com/threads/discretionary-supply-zones-across-a-specific-discretionary-price-level.1507/
#All credits for levels scripting logic goes to Trading51
#Modifed by Clark2001

# Wolf Waves
# Mobius
# V01.05.22.2018

# User Inputs

input n = 10;

# Internal Script Reference

script LinePlot {

    input BarID = 0;

    input Value = 0;

    input BarOrigin = 0;

    def ThisBar = HighestAll(BarOrigin);

    def ValueLine = if BarOrigin == ThisBar

                then Value

                else Double.NaN;

    plot P = if ThisBar - BarID <= BarOrigin

             then HighestAll(ValueLine)

             else Double.NaN;

}

# Variables

def o = open;

def h = high;

def l = low;

def c = close;

def x = BarNumber();

def xN = x == HighestAll(x);

# R1

def hh = fold i = 1 to n + 1

         with p = 1

         while p

         do h > GetValue(h, -i);

def PivotH = if (x > n and

                 h == Highest(h, n) and

                 hh)

             then h

             else Double.NaN;

def PHValue = if !IsNaN(PivotH)

              then PivotH

              else PHValue[1];

def PHBarOrigin = if !IsNaN(PivotH)

                  then x

                  else PHBarOrigin[1];

def PHBarID = x - PHBarOrigin;

# R2

def R2PHValue = if PHBarOrigin != PHBarOrigin[1]

                then PHValue[1]

                else R2PHValue[1];

def R2PHBarOrigin = if PHBarOrigin != PHBarOrigin[1]

                    then PHBarOrigin[1]

                    else R2PHBarOrigin[1];

def R2PHBarID = x - R2PHBarOrigin;

# R3

def R3PHValue = if R2PHBarOrigin != R2PHBarOrigin[1]

                then R2PHValue[1]

                else R3PHValue[1];

def R3PHBarOrigin = if R2PHBarOrigin != R2PHBarOrigin[1]

                    then R2PHBarOrigin[1]

                    else R3PHBarOrigin[1];

def R3PHBarID = x - R3PHBarOrigin;

# S1

def ll = fold j = 1 to n + 1

         with q = 1

         while q

         do l < GetValue(l, -j);

def PivotL = if (x > n and

                 l == Lowest(l, n) and

                 ll)

             then l

             else Double.NaN;

def PLValue = if !IsNaN(PivotL)

              then PivotL

              else PLValue[1];

def PLBarOrigin = if !IsNaN(PivotL)

                  then x

                  else PLBarOrigin[1];

def PLBarID = x - PLBarOrigin;

# S2

def S2PLValue = if PLBarOrigin != PLBarOrigin[1]

                then PLValue[1]

                else S2PLValue[1];

def S2PLBarOrigin = if PLBarOrigin != PLBarOrigin[1]

                    then PLBarOrigin[1]

                    else S2PLBarOrigin[1];

def S2PLBarID = x - S2PLBarOrigin;

# S3

def S3PLValue = if S2PLBarOrigin != S2PLBarOrigin[1]

                then S2PLValue[1]

                else S3PLValue[1];

def S3PLBarOrigin = if S2PLBarOrigin != S2PLBarOrigin[1]

                    then S2PLBarOrigin[1]

                    else S3PLBarOrigin[1];

def S3PLBarID = x - S3PLBarOrigin;

# S4

def S4PLValue = if S3PLBarOrigin != S3PLBarOrigin[1]

                then S3PLValue[1]

                else S4PLValue[1];

def S4PLBarOrigin = if S3PLBarOrigin != S3PLBarOrigin[1]

                    then S3PLBarOrigin[1]

                    else S4PLBarOrigin[1];

def S4PLBarID = x - S4PLBarOrigin;

# S5

def S5PLValue = if S4PLBarOrigin != S4PLBarOrigin[1]

                then S4PLValue[1]

                else S5PLValue[1];

def S5PLBarOrigin = if S4PLBarOrigin != S4PLBarOrigin[1]

                    then S4PLBarOrigin[1]

                    else S5PLBarOrigin[1];

def S5PLBarID = x - S5PLBarOrigin;

# Plots

plot R1 = LinePlot(BarID = PHBarID,

                   Value = PHValue,

                   BarOrigin = PHBarOrigin);

R1.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(PHBarOrigin), PHValue, "R1", Color.GREEN, 1);

plot R2 = LinePlot(BarID = R2PHBarID,

                   Value = R2PHValue,

                   BarOrigin = R2PHBarOrigin);

R2.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R2PHBarOrigin), PHValue, "R2", Color.GREEN, 1);

plot R3 = LinePlot(BarID = R3PHBarID,

                   Value = R3PHValue,

                   BarOrigin = R3PHBarOrigin);

R3.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot S1 = LinePlot(BarID = PLBarID,

                   Value = PLValue,

                   BarOrigin = PLBarOrigin);

S1.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(PLBarOrigin), PLValue, "S1", Color.RED, 0);

plot S2 = LinePlot(BarID = S2PLBarID,

                   Value = S2PLValue,

                   BarOrigin = S2PLBarOrigin);

S2.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S2PLBarOrigin), PLValue, "S2", Color.RED, 0);

plot S3 = LinePlot(BarID = S3PLBarID,

                   Value = S3PLValue,

                   BarOrigin = S3PLBarOrigin);

S3.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

# Trend Line

plot SupportLine2 = if x == HighestAll(S2PLBarOrigin)

                    then S2

                    else if x == HighestAll(PLBarOrigin)

                         then S1  #Parentlow

                         else Double.NaN;

SupportLine2.EnableApproximation();

SupportLine2.SetDefaultColor(Color.GRAY);

SupportLine2.SetLineWeight(1);

SupportLine2.SetStyle(Curve.LONG_DASH);

def slope2 = (S2 - S1) /

             (HighestAll(S2PLBarOrigin) - PLBarOrigin);

plot ExtLine2 = if x >= S2PLBarOrigin

                then (x - HighestAll(S2PLBarOrigin)) * slope2 + S2

                else Double.NaN;

ExtLine2.EnableApproximation();

ExtLine2.SetDefaultColor(Color.GRAY);

ExtLine2.SetLineWeight(1);

ExtLine2.SetStyle(Curve.LONG_DASH);

plot SupportLine3 = if x == HighestAll(R3PHBarOrigin)

                    then R3

                    else if x == PHBarOrigin

                         then R1

                         else Double.NaN;

SupportLine3.EnableApproximation();

SupportLine3.SetDefaultColor(Color.GRAY);

SupportLine3.SetLineWeight(1);

SupportLine3.SetStyle(Curve.LONG_DASH);

def slope3 = (R1 - R3) /

             (HighestAll(PHBarOrigin) - R3PHBarOrigin);

plot ExtLine3 = if x >= R3PHBarOrigin

                then (x - HighestAll(R3PHBarOrigin)) * slope3 + R3

                else Double.NaN;

ExtLine3.EnableApproximation();

ExtLine3.SetDefaultColor(Color.GRAY);

ExtLine3.SetLineWeight(1);

ExtLine3.SetStyle(Curve.LONG_DASH);


#######################################
###############Levels##################
#######################################
R1.Hide();
R2.Hide();
R3.Hide();
S1.Hide();
S2.Hide();
S3.Hide();
#######################################
#Just make cloud size zero to turn off clouds
input CloudSize = 0.0;
input Lineweight = 2;
input LineType = PaintingStrategy.HORIZONTAL;
DefineGlobalColor("CloudS", Color.GREEN);
DefineGlobalColor("CloudR", Color.RED);
#Global Color For Levels
DefineGlobalColor("LvlColor", Color.Gray);
#=====================================================================
def sLevel1 = R1;
def sLevel2 = R2;
def sLevel3 = R3;
def sLevel4 = S1;
def sLevel5 = S2;
def sLevel6 = S3;

#=====================================================================
plot cloud1_top = highestall(if isnan(close[-1])then round(sLevel1[1] / ticksize(),0) * ticksize()  else double.nan);
plot cloud1_bot = highestall(if isnan(close[-1])then round(sLevel1[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);

plot cloud2_top = highestall(if isnan(close[-1])then round(sLevel2[1] / ticksize(),0) * ticksize()  else double.nan);

plot cloud2_bot = highestall(if isnan(close[-1])then round(sLevel2[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);


AddCloud(cloud1_top, cloud1_bot, GlobalColor("CloudR"), GlobalColor("CloudR"), yes);
AddCloud(cloud2_top, cloud2_bot, GlobalColor("CloudR"), GlobalColor("CloudR"), yes);

#Global Levels (Color)
cloud1_top.AssignValueColor(GlobalColor("LvlColor"));
cloud1_bot.AssignValueColor(GlobalColor("LvlColor"));
cloud2_top.AssignValueColor(GlobalColor("LvlColor"));
cloud2_bot.AssignValueColor(GlobalColor("LvlColor"));


#cloud1_top.Hide();
#cloud1_bot.Hide();
#cloud2_top.Hide();
#cloud2_bot.Hide();
#=====================================================================
#=====================================================================
plot cloud3_top = highestall(if isnan(close[-1])then round(sLevel3[1] / ticksize(),0) * ticksize()   else double.nan);

plot cloud3_bot = highestall(if isnan(close[-1])then round(sLevel3[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);


plot cloud4_top = highestall(if isnan(close[-1])then round(sLevel4[1] / ticksize(),0) * ticksize()  else double.nan);

plot cloud4_bot = highestall(if isnan(close[-1])then round(sLevel4[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);


AddCloud(cloud3_top, cloud3_bot, GlobalColor("CloudR"), GlobalColor("CloudR"), yes);
AddCloud(cloud4_top, cloud4_bot, GlobalColor("CloudR"), GlobalColor("CloudR"), yes);

#Global Levels (Color)
cloud3_top.AssignValueColor(GlobalColor("LvlColor"));
cloud3_bot.AssignValueColor(GlobalColor("LvlColor"));
cloud4_top.AssignValueColor(GlobalColor("LvlColor"));
cloud4_bot.AssignValueColor(GlobalColor("LvlColor"));

#cloud3_top.Hide();
#cloud3_bot.Hide();
#cloud4_top.Hide();
#cloud4_bot.Hide();
#=====================================================================
#=====================================================================
plot cloud5_top = highestall(if isnan(close[-1])then round(sLevel5[1] / ticksize(),0) * ticksize()  else double.nan);

plot cloud5_bot = highestall(if isnan(close[-1])then round(sLevel5[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);


plot cloud6_top = highestall(if isnan(close[-1])then round(sLevel6[1] / ticksize(),0) * ticksize()  else double.nan);

plot cloud6_bot = highestall(if isnan(close[-1])then round(sLevel6[1] / ticksize(),0) * ticksize()  - CloudSize else double.nan);


AddCloud(cloud5_top, cloud5_bot, GlobalColor("CloudS"), GlobalColor("CloudS"), yes);
AddCloud(cloud6_top, cloud6_bot, GlobalColor("CloudS"), GlobalColor("CloudS"), yes);

#Global Levels (Color)
cloud5_top.AssignValueColor(GlobalColor("LvlColor"));
cloud5_bot.AssignValueColor(GlobalColor("LvlColor"));
cloud6_top.AssignValueColor(GlobalColor("LvlColor"));
cloud6_bot.AssignValueColor(GlobalColor("LvlColor"));

#cloud5_top.Hide();
#cloud5_bot.Hide();
#cloud6_top.Hide();
#cloud6_bot.Hide();
#=====================================================================
#=====================================================================

cloud1_top.SetPaintingStrategy(LineType);
cloud1_top.SetDefaultColor(Color.DARK_RED);
cloud1_top.SetLineWeight(Lineweight);

cloud1_bot.SetPaintingStrategy(LineType);
cloud1_bot.SetDefaultColor(Color.DARK_RED);
cloud1_bot.SetLineWeight(Lineweight);

cloud2_top.SetPaintingStrategy(LineType);
cloud2_top.SetDefaultColor(Color.DARK_RED);
cloud2_top.SetLineWeight(Lineweight);

cloud2_bot.SetPaintingStrategy(LineType);
cloud2_bot.SetDefaultColor(Color.DARK_RED);
cloud2_bot.SetLineWeight(Lineweight);

cloud3_top.SetPaintingStrategy(LineType);
cloud3_top.SetDefaultColor(Color.DARK_RED);
cloud3_top.SetLineWeight(Lineweight);

cloud3_bot.SetPaintingStrategy(LineType);
cloud3_bot.SetDefaultColor(Color.DARK_RED);
cloud3_bot.SetLineWeight(Lineweight);

cloud4_top.SetPaintingStrategy(LineType);
cloud4_top.SetDefaultColor(Color.DARK_RED);
cloud4_top.SetLineWeight(Lineweight);

cloud4_bot.SetPaintingStrategy(LineType);
cloud4_bot.SetDefaultColor(Color.DARK_RED);
cloud4_bot.SetLineWeight(Lineweight);

cloud5_top.SetPaintingStrategy(LineType);
cloud5_top.SetDefaultColor(Color.DARK_GREEN);
cloud5_top.SetLineWeight(Lineweight);

cloud5_bot.SetPaintingStrategy(LineType);
cloud5_bot.SetDefaultColor(Color.DARK_GREEN);
cloud5_bot.SetLineWeight(Lineweight);

cloud6_top.SetPaintingStrategy(LineType);
cloud6_top.SetDefaultColor(Color.DARK_GREEN);
cloud6_top.SetLineWeight(Lineweight);

cloud6_bot.SetPaintingStrategy(LineType);
cloud6_bot.SetDefaultColor(Color.DARK_GREEN);
cloud6_bot.SetLineWeight(Lineweight);
#=====================================================================
#=====================================================================

declare upper;

input level = yes;

#level 1
plot plevel1 = highestall(if isnan(close[-1])then round(sLevel1[1] / ticksize(),0) * ticksize() else double.nan);
plevel1.setpaintingStrategy(LineType);
plevel1.AssignValueColor(GlobalColor("LvlColor"));
plevel1.setlineWeight(LineWeight);
plevel1.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel1, text = "level2 " + plevel1, color = Color.White);

#level 2
plot plevel2 = highestall(if isnan(close[-1])then round(slevel2[1] / ticksize(),0) * ticksize() else double.nan);
plevel2.setpaintingStrategy(LineType);
plevel2.AssignValueColor(GlobalColor("LvlColor"));
plevel2.setlineWeight(LineWeight);
plevel2.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel2, text = "Level1 " + plevel2, color = Color.White);

#level 3
plot plevel3 = highestall(if isnan(close[-1])then round(slevel3[1] / ticksize(),0) * ticksize() else double.nan);
plevel3.setpaintingStrategy(LineType);
plevel3.AssignValueColor(Globalcolor("LvlColor"));
plevel3.setlineWeight(LineWeight);
plevel3.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel3, text = "Main Level " + plevel3, color = Color.White);

#level 4
plot plevel4 = highestall(if isnan(close[-1])then round(slevel4[1] / ticksize(),0) * ticksize() else double.nan);
plevel4.setpaintingStrategy(LineType);
plevel4.AssignValueColor(GlobalColor("LvlColor"));
plevel4.setlineWeight(LineWeight);
plevel4.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel4, text = "Main Level " + plevel4, color = Color.White);

#level 5
plot plevel5 = highestall(if isnan(close[-1])then round(slevel5[1] / ticksize(),0) * ticksize() else double.nan);
plevel5.setpaintingStrategy(LineType);
plevel5.AssignValueColor(GlobalColor("LvlColor"));
plevel5.setlineWeight(LineWeight);
plevel5.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel5, text = "Main Level " + plevel5, color = Color.White);

#level 6
plot plevel6 = highestall(if isnan(close[-1])then round(slevel6[1] / ticksize(),0) * ticksize() else double.nan);
plevel6.setpaintingStrategy(LineType);
plevel6.AssignValueColor(GlobalColor("LvlColor"));
plevel6.setlineWeight(LineWeight);
plevel6.SetHiding(!level > 0);
#addchartBubble(isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel6, text = "Main Level " + plevel6, color = Color.White);

I also realized that in this case the cloud function can cause extreme lag. So here is the standalone levels script without any zones implemented. This one also has levels up to 10 for support and resistance to capture more levels.
Screenshot 2024-04-11 204424.png

Code:
#Support and Resistance Levels
#Uses Mobius Wolf Waves & Levels Script
#Information for Scripted Levels found @ https://usethinkscript.com/threads/discretionary-supply-zones-across-a-specific-discretionary-price-level.1507/
#All credits for levels scripting logic goes to Trading51
#Modifed by Clark2001

# Wolf Waves
# Mobius
# V01.05.22.2018

# User Inputs

input n = 30;

# Internal Script Reference

script LinePlot {

    input BarID = 0;

    input Value = 0;

    input BarOrigin = 0;

    def ThisBar = HighestAll(BarOrigin);

    def ValueLine = if BarOrigin == ThisBar

                then Value

                else Double.NaN;

    plot P = if ThisBar - BarID <= BarOrigin

             then HighestAll(ValueLine)

             else Double.NaN;

}

# Variables

def o = open;

def h = high;

def l = low;

def c = close;

def x = BarNumber();

def xN = x == HighestAll(x);

##########################
#### Resistance Logic ####
##########################

# R1

def hh = fold i = 1 to n + 1

         with p = 1

         while p

         do h > GetValue(h, -i);

def PivotH = if (x > n and

                 h == Highest(h, n) and

                 hh)

             then h

             else Double.NaN;

def PHValue = if !IsNaN(PivotH)

              then PivotH

              else PHValue[1];

def PHBarOrigin = if !IsNaN(PivotH)

                  then x

                  else PHBarOrigin[1];

def PHBarID = x - PHBarOrigin;

# R2

def R2PHValue = if PHBarOrigin != PHBarOrigin[1]

                then PHValue[1]

                else R2PHValue[1];

def R2PHBarOrigin = if PHBarOrigin != PHBarOrigin[1]

                    then PHBarOrigin[1]

                    else R2PHBarOrigin[1];

def R2PHBarID = x - R2PHBarOrigin;

# R3

def R3PHValue = if R2PHBarOrigin != R2PHBarOrigin[1]

                then R2PHValue[1]

                else R3PHValue[1];

def R3PHBarOrigin = if R2PHBarOrigin != R2PHBarOrigin[1]

                    then R2PHBarOrigin[1]

                    else R3PHBarOrigin[1];

def R3PHBarID = x - R3PHBarOrigin;

# R4

def R4PHValue = if R3PHBarOrigin != R3PHBarOrigin[1]

                then R3PHValue[1]

                else R4PHValue[1];

def R4PHBarOrigin = if R3PHBarOrigin != R3PHBarOrigin[1]

                    then R3PHBarOrigin[1]

                    else R4PHBarOrigin[1];

def R4PHBarID = x - R4PHBarOrigin;

# R5

def R5PHValue = if R4PHBarOrigin != R4PHBarOrigin[1]

                then R4PHValue[1]

                else R5PHValue[1];

def R5PHBarOrigin = if R4PHBarOrigin != R4PHBarOrigin[1]

                    then R4PHBarOrigin[1]

                    else R5PHBarOrigin[1];

def R5PHBarID = x - R5PHBarOrigin;

# R6

def R6PHValue = if R5PHBarOrigin != R5PHBarOrigin[1]

                then R5PHValue[1]

                else R6PHValue[1];

def R6PHBarOrigin = if R5PHBarOrigin != R5PHBarOrigin[1]

                    then R5PHBarOrigin[1]

                    else R6PHBarOrigin[1];

def R6PHBarID = x - R6PHBarOrigin;

# R7

def R7PHValue = if R6PHBarOrigin != R6PHBarOrigin[1]

                then R6PHValue[1]

                else R7PHValue[1];

def R7PHBarOrigin = if R6PHBarOrigin != R6PHBarOrigin[1]

                    then R6PHBarOrigin[1]

                    else R7PHBarOrigin[1];

def R7PHBarID = x - R7PHBarOrigin;

# R8

def R8PHValue = if R7PHBarOrigin != R7PHBarOrigin[1]

                then R7PHValue[1]

                else R8PHValue[1];

def R8PHBarOrigin = if R7PHBarOrigin != R7PHBarOrigin[1]

                    then R7PHBarOrigin[1]

                    else R8PHBarOrigin[1];

def R8PHBarID = x - R8PHBarOrigin;

# R9

def R9PHValue = if R8PHBarOrigin != R8PHBarOrigin[1]

                then R8PHValue[1]

                else R9PHValue[1];

def R9PHBarOrigin = if R8PHBarOrigin != R8PHBarOrigin[1]

                    then R8PHBarOrigin[1]

                    else R9PHBarOrigin[1];

def R9PHBarID = x - R9PHBarOrigin;

# R9

def R10PHValue = if R9PHBarOrigin != R9PHBarOrigin[1]

                then R9PHValue[1]

                else R10PHValue[1];

def R10PHBarOrigin = if R9PHBarOrigin != R9PHBarOrigin[1]

                    then R9PHBarOrigin[1]

                    else R10PHBarOrigin[1];

def R10PHBarID = x - R10PHBarOrigin;


##########################
##### Support Logic ######
##########################

# S1

def ll = fold j = 1 to n + 1

         with q = 1

         while q

         do l < GetValue(l, -j);

def PivotL = if (x > n and

                 l == Lowest(l, n) and

                 ll)

             then l

             else Double.NaN;

def PLValue = if !IsNaN(PivotL)

              then PivotL

              else PLValue[1];

def PLBarOrigin = if !IsNaN(PivotL)

                  then x

                  else PLBarOrigin[1];

def PLBarID = x - PLBarOrigin;

# S2

def S2PLValue = if PLBarOrigin != PLBarOrigin[1]

                then PLValue[1]

                else S2PLValue[1];

def S2PLBarOrigin = if PLBarOrigin != PLBarOrigin[1]

                    then PLBarOrigin[1]

                    else S2PLBarOrigin[1];

def S2PLBarID = x - S2PLBarOrigin;

# S3

def S3PLValue = if S2PLBarOrigin != S2PLBarOrigin[1]

                then S2PLValue[1]

                else S3PLValue[1];

def S3PLBarOrigin = if S2PLBarOrigin != S2PLBarOrigin[1]

                    then S2PLBarOrigin[1]

                    else S3PLBarOrigin[1];

def S3PLBarID = x - S3PLBarOrigin;

# S4

def S4PLValue = if S3PLBarOrigin != S3PLBarOrigin[1]

                then S3PLValue[1]

                else S4PLValue[1];

def S4PLBarOrigin = if S3PLBarOrigin != S3PLBarOrigin[1]

                    then S3PLBarOrigin[1]

                    else S4PLBarOrigin[1];

def S4PLBarID = x - S4PLBarOrigin;

# S5

def S5PLValue = if S4PLBarOrigin != S4PLBarOrigin[1]

                then S4PLValue[1]

                else S5PLValue[1];

def S5PLBarOrigin = if S4PLBarOrigin != S4PLBarOrigin[1]

                    then S4PLBarOrigin[1]

                    else S5PLBarOrigin[1];

def S5PLBarID = x - S5PLBarOrigin;

# S6

def S6PLValue = if S5PLBarOrigin != S5PLBarOrigin[1]

                then S5PLValue[1]

                else S6PLValue[1];

def S6PLBarOrigin = if S5PLBarOrigin != S5PLBarOrigin[1]

                    then S5PLBarOrigin[1]

                    else S6PLBarOrigin[1];

def S6PLBarID = x - S6PLBarOrigin;

# S7

def S7PLValue = if S6PLBarOrigin != S6PLBarOrigin[1]

                then S6PLValue[1]

                else S7PLValue[1];

def S7PLBarOrigin = if S6PLBarOrigin != S6PLBarOrigin[1]

                    then S6PLBarOrigin[1]

                    else S7PLBarOrigin[1];

def S7PLBarID = x - S7PLBarOrigin;

# S8

def S8PLValue = if S7PLBarOrigin != S7PLBarOrigin[1]

                then S7PLValue[1]

                else S8PLValue[1];

def S8PLBarOrigin = if S7PLBarOrigin != S7PLBarOrigin[1]

                    then S7PLBarOrigin[1]

                    else S8PLBarOrigin[1];

def S8PLBarID = x - S8PLBarOrigin;

# S9

def S9PLValue = if S8PLBarOrigin != S8PLBarOrigin[1]

                then S8PLValue[1]

                else S9PLValue[1];

def S9PLBarOrigin = if S8PLBarOrigin != S8PLBarOrigin[1]

                    then S8PLBarOrigin[1]

                    else S9PLBarOrigin[1];

def S9PLBarID = x - S9PLBarOrigin;

# S10

def S10PLValue = if S9PLBarOrigin != S9PLBarOrigin[1]

                then S9PLValue[1]

                else S10PLValue[1];

def S10PLBarOrigin = if S9PLBarOrigin != S9PLBarOrigin[1]

                    then S9PLBarOrigin[1]

                    else S10PLBarOrigin[1];

def S10PLBarID = x - S10PLBarOrigin;


#############################
##### Resistance Plots ######
#############################

plot R1 = LinePlot(BarID = PHBarID,

                   Value = PHValue,

                   BarOrigin = PHBarOrigin);

R1.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(PHBarOrigin), PHValue, "R1", Color.GREEN, 1);

plot R2 = LinePlot(BarID = R2PHBarID,

                   Value = R2PHValue,

                   BarOrigin = R2PHBarOrigin);

R2.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R2PHBarOrigin), PHValue, "R2", Color.GREEN, 1);

plot R3 = LinePlot(BarID = R3PHBarID,

                   Value = R3PHValue,

                   BarOrigin = R3PHBarOrigin);

R3.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R4 = LinePlot(BarID = R4PHBarID,

                   Value = R4PHValue,

                   BarOrigin = R4PHBarOrigin);

R4.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R5 = LinePlot(BarID = R5PHBarID,

                   Value = R5PHValue,

                   BarOrigin = R5PHBarOrigin);

R5.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R6 = LinePlot(BarID = R6PHBarID,

                   Value = R6PHValue,

                   BarOrigin = R6PHBarOrigin);

R6.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R7 = LinePlot(BarID = R7PHBarID,

                   Value = R7PHValue,

                   BarOrigin = R7PHBarOrigin);

R7.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R8 = LinePlot(BarID = R8PHBarID,

                   Value = R8PHValue,

                   BarOrigin = R8PHBarOrigin);

R8.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R9 = LinePlot(BarID = R9PHBarID,

                   Value = R9PHValue,

                   BarOrigin = R9PHBarOrigin);

R9.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);

plot R10 = LinePlot(BarID = R10PHBarID,

                   Value = R10PHValue,

                   BarOrigin = R10PHBarOrigin);

R10.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(R3PHBarOrigin), PHValue, "R3", Color.GREEN, 1);


##########################
##### Support Plots ######
##########################

plot S1 = LinePlot(BarID = PLBarID,

                   Value = PLValue,

                   BarOrigin = PLBarOrigin);

S1.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(PLBarOrigin), PLValue, "S1", Color.RED, 0);

plot S2 = LinePlot(BarID = S2PLBarID,

                   Value = S2PLValue,

                   BarOrigin = S2PLBarOrigin);

S2.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S2PLBarOrigin), PLValue, "S2", Color.RED, 0);

plot S3 = LinePlot(BarID = S3PLBarID,

                   Value = S3PLValue,

                   BarOrigin = S3PLBarOrigin);

S3.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S4 = LinePlot(BarID = S4PLBarID,

                   Value = S4PLValue,

                   BarOrigin = S4PLBarOrigin);

S4.SetDefaultColor(Color.YELLOW);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S5 = LinePlot(BarID = S5PLBarID,

                   Value = S5PLValue,

                   BarOrigin = S5PLBarOrigin);

S5.SetDefaultColor(Color.ORANGE);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S6 = LinePlot(BarID = S6PLBarID,

                   Value = S6PLValue,

                   BarOrigin = S6PLBarOrigin);

S6.SetDefaultColor(Color.CYAN);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S7 = LinePlot(BarID = S7PLBarID,

                   Value = S7PLValue,

                   BarOrigin = S7PLBarOrigin);

S7.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S8 = LinePlot(BarID = S8PLBarID,

                   Value = S8PLValue,

                   BarOrigin = S8PLBarOrigin);

S8.SetDefaultColor(Color.RED);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S9 = LinePlot(BarID = S9PLBarID,

                   Value = S9PLValue,

                   BarOrigin = S9PLBarOrigin);

S9.SetDefaultColor(Color.VIOLET);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);

plot S10 = LinePlot(BarID = S10PLBarID,

                   Value = S10PLValue,

                   BarOrigin = S10PLBarOrigin);

S10.SetDefaultColor(Color.GREEN);

#AddChartBubble(x == HighestAll(S3PLBarOrigin), PLValue, "S3", Color.RED, 0);


# Trend Line

plot SupportLine2 = if x == HighestAll(S2PLBarOrigin)

                    then S2

                    else if x == HighestAll(PLBarOrigin)

                         then S1  #Parentlow

                         else Double.NaN;

SupportLine2.EnableApproximation();

SupportLine2.SetDefaultColor(Color.GRAY);

SupportLine2.SetLineWeight(1);

SupportLine2.SetStyle(Curve.LONG_DASH);

def slope2 = (S2 - S1) /

             (HighestAll(S2PLBarOrigin) - PLBarOrigin);

plot ExtLine2 = if x >= S2PLBarOrigin

                then (x - HighestAll(S2PLBarOrigin)) * slope2 + S2

                else Double.NaN;

ExtLine2.EnableApproximation();

ExtLine2.SetDefaultColor(Color.GRAY);

ExtLine2.SetLineWeight(1);

ExtLine2.SetStyle(Curve.LONG_DASH);

plot SupportLine3 = if x == HighestAll(R3PHBarOrigin)

                    then R3

                    else if x == PHBarOrigin

                         then R1

                         else Double.NaN;

SupportLine3.EnableApproximation();

SupportLine3.SetDefaultColor(Color.GRAY);

SupportLine3.SetLineWeight(1);

SupportLine3.SetStyle(Curve.LONG_DASH);

def slope3 = (R1 - R3) /

             (HighestAll(PHBarOrigin) - R3PHBarOrigin);

plot ExtLine3 = if x >= R3PHBarOrigin

                then (x - HighestAll(R3PHBarOrigin)) * slope3 + R3

                else Double.NaN;

ExtLine3.EnableApproximation();

ExtLine3.SetDefaultColor(Color.GRAY);

ExtLine3.SetLineWeight(1);

ExtLine3.SetStyle(Curve.LONG_DASH);


#######################################
#Information for Scripted Levels found @ https://usethinkscript.com/threads/discretionary-supply-zones-across-a-specific-discretionary-price-level.1507/
#All credits for levels scripting logic goes to Trading51
#Modifed by Clark2001
#######################################

###################
##### Levels ######
###################

R1.Hide();
R2.Hide();
R3.Hide();
R4.Hide();
R5.Hide();
R6.Hide();
R7.Hide();
R8.Hide();
R9.Hide();
R10.Hide();

S1.Hide();
S2.Hide();
S3.Hide();
S4.Hide();
S5.Hide();
S6.Hide();
S7.Hide();
S8.Hide();
S9.Hide();
S10.Hide();

#######################################
#Just make cloud size zero to turn off clouds
input Lineweight = 4;
input LineType = PaintingStrategy.HORIZONTAL;
input Bubbles_On = yes;
#Global Color For Levels
DefineGlobalColor("LvlColor", Color.GRAY); 
#=====================================================================
def sLevel1 = R1;
def sLevel2 = R2;
def sLevel3 = R3;
def sLevel4 = R4;
def sLevel5 = R5;
def sLevel6 = R6;
def sLevel7 = R7;
def sLevel8 = R8;
def sLevel9 = R9;
def sLevel10 = R10;
#====================
def sLevel11 = S1;
def sLevel12 = S2;
def sLevel13 = S3;
def sLevel14 = S4;
def sLevel15 = S5;
def sLevel16 = S6;
def sLevel17 = S7;
def sLevel18 = S8;
def sLevel19 = S9;
def sLevel20 = S10;
#=====================================================================
#=====================================================================

declare upper;

input level = yes;

#level 1
plot plevel1 = HighestAll(if IsNaN(close[-1]) then Round(sLevel1[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel1.SetPaintingStrategy(LineType);
plevel1.AssignValueColor(GlobalColor("LvlColor"));
plevel1.SetLineWeight(Lineweight);
plevel1.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel1, text = "level " + plevel1, color = Color.White);

#level 2
plot plevel2 = HighestAll(if IsNaN(close[-1]) then Round(sLevel2[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel2.SetPaintingStrategy(LineType);
plevel2.AssignValueColor(GlobalColor("LvlColor"));
plevel2.SetLineWeight(Lineweight);
plevel2.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel2, text = "Level " + plevel2, color = Color.White);

#level 3
plot plevel3 = HighestAll(if IsNaN(close[-1]) then Round(sLevel3[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel3.SetPaintingStrategy(LineType);
plevel3.AssignValueColor(GlobalColor("LvlColor"));
plevel3.SetLineWeight(Lineweight);
plevel3.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel3, text = "Level " + plevel3, color = Color.White);

#level 4
plot plevel4 = HighestAll(if IsNaN(close[-1]) then Round(sLevel4[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel4.SetPaintingStrategy(LineType);
plevel4.AssignValueColor(GlobalColor("LvlColor"));
plevel4.SetLineWeight(Lineweight);
plevel4.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel4, text = "Level " + plevel4, color = Color.White);

#level 5
plot plevel5 = HighestAll(if IsNaN(close[-1]) then Round(sLevel5[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel5.SetPaintingStrategy(LineType);
plevel5.AssignValueColor(GlobalColor("LvlColor"));
plevel5.SetLineWeight(Lineweight);
plevel5.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel5, text = "Level " + plevel5, color = Color.White);

#level 6
plot plevel6 = HighestAll(if IsNaN(close[-1]) then Round(sLevel6[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel6.SetPaintingStrategy(LineType);
plevel6.AssignValueColor(GlobalColor("LvlColor"));
plevel6.SetLineWeight(Lineweight);
plevel6.SetHiding(!level > 0);
addchartBubble(Bubbles_On and isnaN(close[3]) && !isnaN(close[4]),"price location" = plevel6, text = "Level " + plevel6, color = Color.White);

#level 7
plot plevel7 = HighestAll(if IsNaN(close[-1]) then Round(sLevel7[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel7.SetPaintingStrategy(LineType);
plevel7.AssignValueColor(GlobalColor("LvlColor"));
plevel7.SetLineWeight(Lineweight);
plevel7.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel7, text = "Level " + plevel7, color = Color.WHITE);

#level 8
plot plevel8 = HighestAll(if IsNaN(close[-1]) then Round(sLevel8[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel8.SetPaintingStrategy(LineType);
plevel8.AssignValueColor(GlobalColor("LvlColor"));
plevel8.SetLineWeight(Lineweight);
plevel8.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel8, text = "Level " + plevel8, color = Color.WHITE);

#level 9
plot plevel9 = HighestAll(if IsNaN(close[-1]) then Round(sLevel9[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel9.SetPaintingStrategy(LineType);
plevel9.AssignValueColor(GlobalColor("LvlColor"));
plevel9.SetLineWeight(Lineweight);
plevel9.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel9, text = "Level " + plevel9, color = Color.WHITE);

#level 10
plot plevel10 = HighestAll(if IsNaN(close[-1]) then Round(sLevel10[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel10.SetPaintingStrategy(LineType);
plevel10.AssignValueColor(GlobalColor("LvlColor"));
plevel10.SetLineWeight(Lineweight);
plevel10.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel10, text = "Level " + plevel10, color = Color.WHITE);

#level 11
plot plevel11 = HighestAll(if IsNaN(close[-1]) then Round(sLevel11[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel11.SetPaintingStrategy(LineType);
plevel11.AssignValueColor(GlobalColor("LvlColor"));
plevel11.SetLineWeight(Lineweight);
plevel11.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel11, text = "Level " + plevel11, color = Color.WHITE);

#level 12
plot plevel12 = HighestAll(if IsNaN(close[-1]) then Round(sLevel11[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel12.SetPaintingStrategy(LineType);
plevel12.AssignValueColor(GlobalColor("LvlColor"));
plevel12.SetLineWeight(Lineweight);
plevel12.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel12, text = "Level " + plevel12, color = Color.WHITE);

#level 13
plot plevel13 = HighestAll(if IsNaN(close[-1]) then Round(sLevel13[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel13.SetPaintingStrategy(LineType);
plevel13.AssignValueColor(GlobalColor("LvlColor"));
plevel13.SetLineWeight(Lineweight);
plevel13.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel13, text = "Level " + plevel13, color = Color.WHITE);

#level 14
plot plevel14 = HighestAll(if IsNaN(close[-1]) then Round(sLevel14[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel14.SetPaintingStrategy(LineType);
plevel14.AssignValueColor(GlobalColor("LvlColor"));
plevel14.SetLineWeight(Lineweight);
plevel14.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel14, text = "Level " + plevel14, color = Color.WHITE);

#level 15
plot plevel15 = HighestAll(if IsNaN(close[-1]) then Round(sLevel15[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel15.SetPaintingStrategy(LineType);
plevel15.AssignValueColor(GlobalColor("LvlColor"));
plevel15.SetLineWeight(Lineweight);
plevel15.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel15, text = "Level " + plevel15, color = Color.WHITE);

#level 16
plot plevel16 = HighestAll(if IsNaN(close[-1]) then Round(sLevel16[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel16.SetPaintingStrategy(LineType);
plevel16.AssignValueColor(GlobalColor("LvlColor"));
plevel16.SetLineWeight(Lineweight);
plevel16.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel16, text = "Level " + plevel16, color = Color.WHITE);

#level 17
plot plevel17 = HighestAll(if IsNaN(close[-1]) then Round(sLevel17[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel17.SetPaintingStrategy(LineType);
plevel17.AssignValueColor(GlobalColor("LvlColor"));
plevel17.SetLineWeight(Lineweight);
plevel17.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel17, text = "Level " + plevel17, color = Color.WHITE);

#level 18
plot plevel18 = HighestAll(if IsNaN(close[-1]) then Round(sLevel18[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel18.SetPaintingStrategy(LineType);
plevel18.AssignValueColor(GlobalColor("LvlColor"));
plevel18.SetLineWeight(Lineweight);
plevel18.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel18, text = "Level " + plevel18, color = Color.WHITE);

#level 19
plot plevel19 = HighestAll(if IsNaN(close[-1]) then Round(sLevel19[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel19.SetPaintingStrategy(LineType);
plevel19.AssignValueColor(GlobalColor("LvlColor"));
plevel19.SetLineWeight(Lineweight);
plevel19.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel19, text = "Level " + plevel19, color = Color.WHITE);

#level 20
plot plevel20 = HighestAll(if IsNaN(close[-1]) then Round(sLevel20[1] / TickSize(), 0) * TickSize() else Double.NaN);
plevel20.SetPaintingStrategy(LineType);
plevel20.AssignValueColor(GlobalColor("LvlColor"));
plevel20.SetLineWeight(Lineweight);
plevel20.SetHiding(!level > 0);
AddChartBubble(Bubbles_On and IsNaN(close[3]) && !IsNaN(close[4]), "price location" = plevel20, text = "Level " + plevel20, color = Color.WHITE);
######
 
Last edited:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
342 Online
Create Post

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