Support and Resistance Backtester [SS]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//  /$$$$$$   /$$                                                         /$$                                            
// /$$__  $$ | $$                                                        | $$                                            
//| $$  \__//$$$$$$    /$$$$$$  /$$    /$$ /$$$$$$   /$$$$$$   /$$$$$$$ /$$$$$$    /$$$$$$  /$$    /$$ /$$$$$$   /$$$$$$$
//|  $$$$$$|_  $$_/   /$$__  $$|  $$  /$$//$$__  $$ /$$__  $$ /$$_____/|_  $$_/   /$$__  $$|  $$  /$$//$$__  $$ /$$_____/
// \____  $$ | $$    | $$$$$$$$ \  $$/$$/| $$$$$$$$| $$  \__/|  $$$$$$   | $$    | $$$$$$$$ \  $$/$$/| $$$$$$$$|  $$$$$$ 
// /$$  \ $$ | $$ /$$| $$_____/  \  $$$/ | $$_____/| $$       \____  $$  | $$ /$$| $$_____/  \  $$$/ | $$_____/ \____  $$
//|  $$$$$$/ |  $$$$/|  $$$$$$$   \  $/  |  $$$$$$$| $$       /$$$$$$$/  |  $$$$/|  $$$$$$$   \  $/  |  $$$$$$$ /$$$$$$$/
// \______/   \___/   \_______/    \_/    \_______/|__/      |_______/    \___/   \_______/    \_/    \_______/|_______/ 

//       ___________________
//      /                   \
//     /  _____        _____ \
//    /  /     \      /     \  \
// __/__/       \____/       \__\_____
//|           ___________           ____|
// \_________/           \_________/
//            \  /////// /
//             \/////////
// © Steversteves
//@version=5
indicator("Support and Resistance Backtester [SS]", shorttitle = "S/R Backtester [SS]", overlay=true, max_labels_count = 500)

// Groups // 
g1 = "Settings" 
g2 = "Support and Resistance Levels" 
g3 = "Backtest Parameters"

// Tooltips // 
t1 = "This will plot the price labels beside the support and resistance levels" // labels 
t2 = "This will extend the support and resistance area to encompass the support and resistance zone +/- the threshold value inputted" // Threshold Plot
t3 = "This will extend the support and resistance to a general 'area' in which you are comfortable holding. Suggested value is the value in which you are willing to let the stock extend past your support or resistance level before stopping out."
t4 = "The number of candles you wish to lookback to test the support and resistance levels. Suggested values for optimization: \n Hourly: 300 \n Daily: 500"
t5 = "Will plot labels on each of the support and resistance passes." 
t6 = "Will plot labels on each of the support and resistance fails." 
t7 = "Determines the source you wish to look at. Suggested value is close."

// User inputs // 

pltsr =     input.bool(true, "Plot Support and Resistance Levels", group = g1)
pltlbl =    input.bool(true, "Plot Labels", tooltip = t1, group=g1)
pltthresh = input.bool(false, "Plot Threshold Limits", tooltip = t2, group = g1)
chrt =      input.bool(true, "Display Chart", group=g1) 
sr1 =       input.float(100, "Support/Resistance 1", group = g2)
sr2 =       input.float(0, "Support/Resistance 2", group = g2) 
sr3 =       input.float(0, "Support/Resistance 3", group = g2) 
sr4 =       input.float(0, "Support/Resistance 4", group = g2) 
sr5 =       input.float(0, "Support/Resistance 5", group = g2) 
src =       input.source(close, "Source",tooltip = t7, group = g3) 
len =       input.int(500, "Lookback", tooltip = t4, group = g3) 
margin =    input.float(0.50, "Threshold parameter", tooltip = t3,  group = g3) 
pltpasses = input.bool(false, "Plot Passes", tooltip = t5) 
pltfails =  input.bool(false, "Plot Fails", tooltip = t6) 


// Support and Resistance 1 
bool sr1_support = src[3] > sr1 and src[2] >= sr1 - margin and src[2] <= sr1 + margin and src > sr1 + margin 
bool sr1_resistance = src[3] < sr1 and src[2] >= sr1 - margin and src[2] <= sr1 + margin and src < sr1 - margin  
bool sr1_resistance_fail = src[3] < sr1 and src[2] > sr1 and src[1] > sr1 and src > sr1 + margin 
bool sr1_support_fail = src[3] > sr1 and src[2] < sr1 and src[1] < sr1 and src < sr1 - margin 
bool sr1_touch = src >= sr1 - margin and src <= sr1 + margin 

// Support and Resistance 2 
bool sr2_support = src[3] > sr2 and src[2] >= sr2 - margin and src[2] <= sr2 + margin and src > sr2 + margin 
bool sr2_resistance = src[3] < sr2 and src[2] >= sr2 - margin and src[2] <= sr2 + margin and src < sr2  - margin 
bool sr2_resistance_fail = src[3] < sr2 and src[2] > sr2 and src[1] > sr2 and src > sr2 + margin 
bool sr2_support_fail = src[3] > sr2 and src[2] < sr2 and src[1] < sr2 and src < sr2 - margin 
bool sr2_touch = src >= sr2 - margin and src <= sr2 + margin 

// Support and Resistance 3
bool sr3_support = src[3] > sr3 and src[2] >= sr3 - margin and src[2] <= sr3 + margin and src > sr3 + margin 
bool sr3_resistance = src[3] < sr3 and src[2] >= sr3 - margin and src[2] <= sr3 + margin and src < sr3  - margin 
bool sr3_resistance_fail = src[3] < sr3 and src[2] > sr3 and src[1] > sr3 and src > sr3 + margin 
bool sr3_support_fail = src[3] > sr3 and src[2] < sr3 and src[1] < sr3 and src < sr3 - margin 
bool sr3_touch = src >= sr3 - margin and src <= sr3 + margin 

// Support and Resistance 4
bool sr4_support = src[3] > sr4 and src[2] >= sr4 - margin and src[2] <= sr4 + margin and src > sr4 + margin 
bool sr4_resistance = src[3] < sr4 and src[2] >= sr4 - margin and src[2] <= sr4 + margin and src < sr4  - margin 
bool sr4_resistance_fail = src[3] < sr4 and src[2] > sr4 and src[1] > sr4 and src > sr4 + margin 
bool sr4_support_fail = src[3] > sr4 and src[2] < sr4 and src[1] < sr4 and src < sr4 - margin 
bool sr4_touch = src >= sr4 - margin and src <= sr4 + margin 

// Support and Resistance 5
bool sr5_support = src[3] > sr5 and src[2] >= sr5 - margin and src[2] <= sr5 + margin and src > sr5 + margin 
bool sr5_resistance = src[3] < sr5 and src[2] >= sr5 - margin and src[2] <= sr5 + margin and src < sr5 - margin 
bool sr5_resistance_fail = src[3] < sr5 and src[2] > sr5 and src[1] > sr5 and src > sr5 + margin 
bool sr5_support_fail = src[3] > sr5 and src[2] < sr5 and src[1] < sr5 and src < sr5 - margin 
bool sr5_touch = src >= sr5 - margin and src <= sr5 + margin 



int sr1_support_count = 0 
int sr1_resistance_count = 0 
int sr1_resistance_fail_count = 0 
int sr1_support_fail_count = 0 
int sr1_touch_count = 0 

int sr2_support_count = 0 
int sr2_resistance_count = 0 
int sr2_resistance_fail_count = 0 
int sr2_support_fail_count = 0 
int sr2_touch_count = 0 

int sr3_support_count = 0 
int sr3_resistance_count = 0 
int sr3_resistance_fail_count = 0 
int sr3_support_fail_count = 0 
int sr3_touch_count = 0 

int sr4_support_count = 0 
int sr4_resistance_count = 0 
int sr4_resistance_fail_count = 0 
int sr4_support_fail_count = 0 
int sr4_touch_count = 0 

int sr5_support_count = 0 
int sr5_resistance_count = 0 
int sr5_resistance_fail_count = 0 
int sr5_support_fail_count = 0 
int sr5_touch_count = 0 

for i = 0 to len 
    if sr1_support[i] and barstate.islast 
        sr1_support_count := sr1_support_count + 1 
    if sr1_resistance[i] and barstate.islast 
        sr1_resistance_count := sr1_resistance_count + 1 
    if sr1_resistance_fail[i] and barstate.islast 
        sr1_resistance_fail_count := sr1_resistance_fail_count + 1 
    if sr1_support_fail[i] and barstate.islast 
        sr1_support_fail_count := sr1_support_fail_count + 1 
    if sr1_touch[i] and barstate.islast 
        sr1_touch_count := sr1_touch_count + 1 

    if sr2_support[i] and barstate.islast 
        sr2_support_count := sr2_support_count + 1 
    if sr2_resistance[i] and barstate.islast 
        sr2_resistance_count := sr2_resistance_count + 1 
    if sr2_resistance_fail[i] and barstate.islast 
        sr2_resistance_fail_count := sr2_resistance_fail_count + 1 
    if sr2_support_fail[i] and barstate.islast 
        sr2_support_fail_count := sr2_support_fail_count + 1 
    if sr2_touch[i] and barstate.islast 
        sr2_touch_count := sr2_touch_count + 1 

    if sr3_support[i] and barstate.islast 
        sr3_support_count := sr3_support_count + 1 
    if sr3_resistance[i] and barstate.islast 
        sr3_resistance_count := sr3_resistance_count + 1 
    if sr3_resistance_fail[i] and barstate.islast 
        sr3_resistance_fail_count := sr3_resistance_fail_count + 1 
    if sr3_support_fail[i] and barstate.islast 
        sr3_support_fail_count := sr3_support_fail_count + 1 
    if sr3_touch[i] and barstate.islast 
        sr3_touch_count := sr3_touch_count + 1 

    if sr4_support[i] and barstate.islast 
        sr4_support_count := sr4_support_count + 1 
    if sr4_resistance[i] and barstate.islast 
        sr4_resistance_count := sr4_resistance_count + 1 
    if sr4_resistance_fail[i] and barstate.islast 
        sr4_resistance_fail_count := sr4_resistance_fail_count + 1 
    if sr4_support_fail[i] and barstate.islast 
        sr4_support_fail_count := sr4_support_fail_count + 1 
    if sr4_touch[i] and barstate.islast 
        sr4_touch_count := sr4_touch_count + 1 

    if sr5_support[i] and barstate.islast 
        sr5_support_count := sr5_support_count + 1 
    if sr5_resistance[i] and barstate.islast 
        sr5_resistance_count := sr5_resistance_count + 1 
    if sr5_resistance_fail[i] and barstate.islast 
        sr5_resistance_fail_count := sr5_resistance_fail_count + 1 
    if sr5_support_fail[i] and barstate.islast 
        sr5_support_fail_count := sr5_support_fail_count + 1 
    if sr5_touch[i] and barstate.islast 
        sr5_touch_count := sr5_touch_count + 1 

f_perc(support_pass, resistance_pass, support_fail, resistance_fail) => 
    a = support_pass + resistance_pass 
    b = support_fail + resistance_fail 
    c = a / (a + b) * 100 
f_success(input1, input2) => 
    input1 / (input1 + input2) * 100 

sr1_perc = f_perc(sr1_support_count, sr1_resistance_count, sr1_support_fail_count, sr1_resistance_fail_count) 
sr2_perc = f_perc(sr2_support_count, sr2_resistance_count, sr2_support_fail_count, sr2_resistance_fail_count) 
sr3_perc = f_perc(sr3_support_count, sr3_resistance_count, sr3_support_fail_count, sr3_resistance_fail_count)
sr4_perc = f_perc(sr4_support_count, sr4_resistance_count, sr4_support_fail_count, sr4_resistance_fail_count) 
sr5_perc = f_perc(sr5_support_count, sr5_resistance_count, sr5_support_fail_count, sr5_resistance_fail_count)  

sr1_support_suc = f_success(sr1_support_count, sr1_support_fail_count) 
sr1_resistance_suc = f_success(sr1_resistance_count, sr1_resistance_fail_count)
sr2_support_suc = f_success(sr2_support_count, sr2_support_fail_count) 
sr2_resistance_suc = f_success(sr2_resistance_count, sr2_resistance_fail_count)
sr3_support_suc = f_success(sr3_support_count, sr3_support_fail_count) 
sr3_resistance_suc = f_success(sr3_resistance_count, sr3_resistance_fail_count)
sr4_support_suc = f_success(sr4_support_count, sr4_support_fail_count) 
sr4_resistance_suc = f_success(sr4_resistance_count, sr4_resistance_fail_count)
sr5_support_suc = f_success(sr5_support_count, sr5_support_fail_count) 
sr5_resistance_suc = f_success(sr5_resistance_count, sr5_resistance_fail_count)


// Colours 

color black =       color.rgb(0, 0, 0) 
color white =       color.white 
color csr1 =        color.aqua 
color csr1fill =    color.new(color.aqua, 75)
color csr2 =        color.purple 
color csr2fill =    color.new(color.purple, 75) 
color csr3 =        color.gray 
color csr3fill =    color.new(color.gray, 75) 
color csr4 =        color.blue 
color csr4fill =    color.new(color.blue, 75) 
color csr5 =        color.fuchsia
color csr5fill =    color.new(color.fuchsia, 75) 
color transp =      color.new(color.white, 100) 
color green =       color.lime 
color red =         color.red 

// Plot table
var table datatable = table.new(position.top_right, 10, 10, bgcolor=black, frame_color = white, frame_width = 1, border_color = white, border_width = 1) 

if chrt 
    table.cell(datatable, 1, 1, text = "Support/ \n Resistance Level", bgcolor=black, text_color=white) 
if sr1 > 0 and chrt  
    table.cell(datatable, 1, 2, text = str.tostring(sr1), bgcolor=csr1, text_color=white) 
if sr2 > 0 and chrt 
    table.cell(datatable, 1, 3, text = str.tostring(sr2), bgcolor=csr2, text_color=white) 
if sr3 > 0 and chrt 
    table.cell(datatable, 1, 4, text = str.tostring(sr3), bgcolor=csr3, text_color=white) 
if sr4 > 0 and chrt 
    table.cell(datatable, 1, 5, text = str.tostring(sr4), bgcolor=csr4, text_color=white)
if sr5 > 0  and chrt 
    table.cell(datatable, 1, 6, text = str.tostring(sr5), bgcolor=csr5, text_color=white) 
if chrt 
    table.cell(datatable, 2, 1, text = "Support Pass", bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 1, text = "Support Fail", bgcolor=black, text_color=white)
    table.cell(datatable, 4, 1, text = "% Support \n Success", bgcolor=black, text_color=white, tooltip = "The sum of total support passes divided by total passes and fails")
    table.cell(datatable, 5, 1, text = "Resistance Pass", bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 1, text = "Resistance Fail", bgcolor=black, text_color=white)
    table.cell(datatable, 7, 1, text = "% Resistance \n Success", bgcolor=black, text_color=white, tooltip = "The sum of total resistance passes divided by total passes and fails")
    table.cell(datatable, 8, 1, text = "# of Touches", bgcolor=black, text_color=white, tooltip = "The number of times the stock has reached a support area +/- the threshold value")
    table.cell(datatable, 9, 1, text = "Cumulative \n Success", bgcolor=black, text_color=white, tooltip = "Cumulates the Support and Resistance Passes over the Total Passes and Fails")
// SR1 
if sr1 > 0 and chrt 
    table.cell(datatable, 2, 2, text = str.tostring(sr1_support_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 2, text = str.tostring(sr1_support_fail_count), bgcolor=black, text_color=white)
    table.cell(datatable, 4, 2, text = str.tostring(math.round(sr1_support_suc,2)) + "%", bgcolor=black, text_color=sr1_support_suc > 51 ? green : red)  
    table.cell(datatable, 5, 2, text = str.tostring(sr1_resistance_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 2, text = str.tostring(sr1_resistance_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 7, 2, text = str.tostring(math.round(sr1_resistance_suc,2)) + "%", bgcolor=black, text_color= sr1_resistance_suc > 51 ? green : red) 
    table.cell(datatable, 8, 2, text = str.tostring(sr1_touch_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 9, 2, text = str.tostring(math.round(sr1_perc,2)) + "%", bgcolor=black, text_color=sr1_perc > 51 ? green : red) 
// SR2
if sr2 > 0 and chrt 
    table.cell(datatable, 2, 3, text = str.tostring(sr2_support_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 3, text = str.tostring(sr2_support_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 4, 3, text = str.tostring(math.round(sr2_support_suc,2)) + "%", bgcolor=black, text_color=sr2_support_suc > 51 ? green : red) 
    table.cell(datatable, 5, 3, text = str.tostring(sr2_resistance_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 3, text = str.tostring(sr2_resistance_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 7, 3, text = str.tostring(math.round(sr2_resistance_suc,2)) + "%", bgcolor=black, text_color=sr2_resistance_suc > 51 ? green : red) 
    table.cell(datatable, 8, 3, text = str.tostring(sr2_touch_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 9, 3, text = str.tostring(math.round(sr2_perc,2)) + "%", bgcolor=black, text_color=sr2_perc > 51 ? green : red) 
// SR3
if sr3 > 0 and chrt 
    table.cell(datatable, 2, 4, text = str.tostring(sr3_support_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 4, text = str.tostring(sr3_support_fail_count), bgcolor=black, text_color=white)
    table.cell(datatable, 4, 4, text = str.tostring(math.round(sr3_support_suc,2)) + "%", bgcolor=black, text_color=sr3_support_suc > 51 ? green : red) 
    table.cell(datatable, 5, 4, text = str.tostring(sr3_resistance_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 4, text = str.tostring(sr3_resistance_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 7, 4, text = str.tostring(math.round(sr3_resistance_suc,2)) + "%", bgcolor=black, text_color=sr3_resistance_suc > 51 ? green : red) 
    table.cell(datatable, 8, 4, text = str.tostring(sr3_touch_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 9, 4, text = str.tostring(math.round(sr3_perc,2)) + "%", bgcolor=black, text_color= sr3_perc > 51 ? green : red) 
// SR4
if sr4 > 0 and chrt 
    table.cell(datatable, 2, 5, text = str.tostring(sr4_support_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 5, text = str.tostring(sr4_support_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 4, 5, text = str.tostring(math.round(sr4_support_suc,2)) + "%", bgcolor=black, text_color=sr4_support_suc > 51 ? green : red) 
    table.cell(datatable, 5, 5, text = str.tostring(sr4_resistance_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 5, text = str.tostring(sr4_resistance_fail_count), bgcolor=black, text_color=white)
    table.cell(datatable, 7, 5, text = str.tostring(math.round(sr4_resistance_suc,2)) + "%", bgcolor=black, text_color=sr4_resistance_suc > 51 ? green : red) 
    table.cell(datatable, 8, 5, text = str.tostring(sr4_touch_count), bgcolor=black, text_color=white)
    table.cell(datatable, 9, 5, text = str.tostring(math.round(sr4_perc,2)) + "%", bgcolor=black, text_color=sr4_perc > 51 ? green : red)  
// SR4
if sr5 > 0 and chrt 
    table.cell(datatable, 2, 6, text = str.tostring(sr5_support_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 3, 6, text = str.tostring(sr5_support_fail_count), bgcolor=black, text_color=white)
    table.cell(datatable, 4, 6, text = str.tostring(math.round(sr5_support_suc,2)) + "%", bgcolor=black, text_color=sr5_support_suc > 51 ? green : red)  
    table.cell(datatable, 5, 6, text = str.tostring(sr5_resistance_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 6, 6, text = str.tostring(sr5_resistance_fail_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 7, 6, text = str.tostring(math.round(sr5_resistance_suc,2)) + "%", bgcolor=black, text_color=sr5_resistance_suc > 51 ? green : red) 
    table.cell(datatable, 8, 6, text = str.tostring(sr5_touch_count), bgcolor=black, text_color=white) 
    table.cell(datatable, 9, 6, text = str.tostring(math.round(sr5_perc,2)) + "%", bgcolor=black, text_color=sr5_perc > 51 ? green : red) 

// Plots// 

plot(pltsr ? sr1 : na, "Support / Resistance #1", color = csr1, linewidth=3)
a = plot(pltsr and pltthresh ? sr1 + margin : na, "SR1 Threshold", color=csr1)
b = plot(pltsr and pltthresh ? sr1 - margin : na, "SR1 Threshold", color=csr1)
fill(a, b, color=csr1fill)

plot(pltsr ? sr2 : na, "Support / Resistance #2", color = csr2, linewidth=3)
c = plot(pltsr and pltthresh ? sr2 + margin : na, "SR2 Threshold", color=csr2)
d = plot(pltsr and pltthresh ? sr2 - margin : na, "SR2 Threshold", color=csr2)
fill(c, d, color=csr2fill) 

plot(pltsr ? sr3 : na, "Support / Resistance #3", color = csr3, linewidth=3)
e = plot(pltsr and pltthresh ? sr3 + margin : na, "SR3 Threshold", color=csr3)
f = plot(pltsr and pltthresh ? sr3 - margin : na, "SR3 Threshold", color=csr3)
fill(e, f, color=csr3fill) 

plot(pltsr ? sr4 : na, "Support / Resistance #4", color = csr4, linewidth=3)
g = plot(pltsr and pltthresh ? sr4 + margin : na, "SR4 Threshold", color=csr4)
h = plot(pltsr and pltthresh ? sr4 - margin : na, "SR4 Threshold", color=csr4)
fill(g, h, color=csr4fill) 

plot(pltsr ? sr5 : na, "Support / Resistance #5", color = csr5, linewidth=3)
i = plot(pltsr and pltthresh ? sr5 + margin : na, "SR5 Threshold", color=csr5)
j = plot(pltsr and pltthresh ? sr5 - margin : na, "SR5 Threshold", color=csr5)
fill(i, j, color=csr5fill) 

// Label plots //

var label sr1_label = na 
var label sr2_label = na 
var label sr3_label = na 
var label sr4_label = na 
var label sr5_label = na 


if pltlbl
    label.delete(sr1_label) 
    label.delete(sr2_label)
    label.delete(sr3_label) 
    label.delete(sr4_label) 
    label.delete(sr5_label) 
    sr1_label := label.new(bar_index + 15, y=sr1, text = str.tostring(sr1), color = transp, style=label.style_label_right, textcolor = csr1, size = size.large)
    sr2_label := label.new(bar_index + 15, y=sr2, text = str.tostring(sr2), color = transp, style=label.style_label_right, textcolor = csr2, size = size.large)
    sr3_label := label.new(bar_index + 15, y=sr3, text = str.tostring(sr3), color = transp, style=label.style_label_right, textcolor = csr3, size = size.large)
    sr4_label := label.new(bar_index + 15, y=sr4, text = str.tostring(sr4), color = transp, style=label.style_label_right, textcolor = csr4, size = size.large)
    sr5_label := label.new(bar_index + 15, y=sr5, text = str.tostring(sr5), color = transp, style=label.style_label_right, textcolor = csr5, size = size.large)

// Plotting Passes and Fails // 

if pltpasses and sr1_support 
    label.new(bar_index, sr1, text = str.tostring(sr1) + "\n ✔️ \n Support Pass", color = csr1, style=label.style_label_up, textcolor = white) 
if pltpasses and sr1_resistance
    label.new(bar_index, sr1, text = str.tostring(sr1) + "\n ✔️ \n Resistance Pass", color = csr1, textcolor = white) 
if pltpasses and sr2_support 
    label.new(bar_index, sr2, text = str.tostring(sr2) + "\n ✔️ \n Support Pass", color = csr2, style=label.style_label_up, textcolor = white) 
if pltpasses and sr2_resistance
    label.new(bar_index, sr2, text = str.tostring(sr2) + "\n ✔️ \n Resistance Pass", color = csr2, textcolor = white) 
if pltpasses and sr3_support 
    label.new(bar_index, sr3, text = str.tostring(sr3) + "\n ✔️ \n Support Pass", color = csr3, style=label.style_label_up, textcolor = white) 
if pltpasses and sr3_resistance
    label.new(bar_index, sr3, text = str.tostring(sr3) + "\n ✔️ \n Resistance Pass", color = csr3, textcolor = white) 
if pltpasses and sr4_support 
    label.new(bar_index, sr4, text = str.tostring(sr4) + "\n ✔️ \n Support Pass", color = csr4, style=label.style_label_up, textcolor = white) 
if pltpasses and sr4_resistance
    label.new(bar_index, sr4, text = str.tostring(sr4) + "\n ✔️ \n Resistance Pass", color = csr4, textcolor = white) 
if pltpasses and sr5_support 
    label.new(bar_index, sr5, text = str.tostring(sr5) + "\n ✔️ \n Support Pass", color = csr5, style=label.style_label_up, textcolor = white) 
if pltpasses and sr5_resistance
    label.new(bar_index, sr5, text = str.tostring(sr5) + "\n ✔️ \n Resistance Pass", color = csr5, textcolor = white) 

if pltfails and sr1_support_fail 
    label.new(bar_index, sr1, text = str.tostring(sr1) + "\n ❌ \n Support Fail", color = csr1, style=label.style_label_down, textcolor = white) 
if pltfails and sr1_resistance_fail 
    label.new(bar_index, sr1, text = str.tostring(sr1) + "\n ❌ \n Resistance Fail", color = csr1, style=label.style_label_up, textcolor = white) 
if pltfails and sr2_support_fail 
    label.new(bar_index, sr2, text = str.tostring(sr2) + "\n ❌ \n Support Fail", color = csr2, style=label.style_label_down, textcolor = white) 
if pltfails and sr2_resistance_fail 
    label.new(bar_index, sr2, text = str.tostring(sr2) + "\n ❌ \n Resistance Fail", color = csr2, style=label.style_label_up, textcolor = white) 
if pltfails and sr3_support_fail 
    label.new(bar_index, sr3, text = str.tostring(sr3) + "\n ❌ \n Support Fail", color = csr3, style=label.style_label_down, textcolor = white) 
if pltfails and sr3_resistance_fail 
    label.new(bar_index, sr3, text = str.tostring(sr3) + "\n ❌ \n Resistance Fail", color = csr3, style=label.style_label_up, textcolor = white) 
if pltfails and sr4_support_fail 
    label.new(bar_index, sr4, text = str.tostring(sr4) + "\n ❌ \n Support Fail", color = csr4, style=label.style_label_down, textcolor = white) 
if pltfails and sr4_resistance_fail 
    label.new(bar_index, sr4, text = str.tostring(sr4) + "\n ❌ \n Resistance Fail", color = csr4, style=label.style_label_up, textcolor = white) 
if pltfails and sr5_support_fail 
    label.new(bar_index, sr5, text = str.tostring(sr5) + "\n ❌ \n Support Fail", color = csr5, style=label.style_label_down, textcolor = white) 
if pltfails and sr5_resistance_fail 
    label.new(bar_index, sr5, text = str.tostring(sr5) + "\n ❌ \n Resistance Fail", color = csr5, style=label.style_label_up, textcolor = white) 