Breakout Probability (Expo) For ThinkOrSwim

Does anyone have anything like this for TOS that has made its way through this forum in the past?
https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
check out the below. Not exact conversion but this what I am able to code :).
qqLFDwa.png


CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#// © Zeiierman
#https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
#indicator("Breakout Probability (Expo)"
# Converted and mod by Sam4Cok@Samer800 "Not typical Conv" - 11/2022
#/ ~~ Inputs {
input ShowLabel = yes;
input ShowBubbles = yes;
input perc = 0.0;    # "Percentage Step"

def na = Double.NaN;
def bar = BarNumber();

#--------------------------------------------------------
#// ~~ Variables {
def b = BarNumber();
def o = open;
def h = high;
def l = low;
def c = close;
def step = c * (perc / 100);
#/ ~~ Save Number Of Green & Red Candles {
def green = if IsNaN(c[1] > o[1]) then 1 else Max(c[1], o[1]) == c[1];
def red   = if IsNaN(c[1] < o[1]) then 1 else Min(c[1], o[1]) == c[1];
def totalG;
def totalR;
totalG = If(green, totalG[1] + 1, totalG[1]);
totalR = If(red  , totalR[1] + 1, totalR[1]);
script score {
    input x = 0;
    def l = low;
    def h = high;
    def c = close;
    def o = open;
    def green = if IsNaN(green[1]) then 1 else c[1] > o[1];
    def red   = if IsNaN(red[1]) then 1 else c[1] < o[1];
    def totalG = If(green, totalG[1] + 1, totalG[1]);
    def totalR = If(red  , totalR[1] + 1, totalR[1]);
    def ghh;
    def a11;
    def gll;
    def b11;
    def rhh;
    def a22;
    def rll;
    def b22;
    def hh;
    def ll;
    hh = if IsNaN(hh[1]) then 1 else h >= (h[1] + x);
    ll = if IsNaN(ll[1]) then 1 else l <= (l[1] - x);
    if green and hh {
        ghh = ghh[1] + 1;
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = Round((ghh + 1) / totalG * 100, 2);
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    } else
        if green and ll {
        ghh = ghh[1];
        gll = gll[1] + 1;
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = Round((gll + 1) / totalG * 100, 2);
        a22 = a22[1];
        b22 = b22[1];
    } else
            if red and hh {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1] + 1;
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = Round((rhh + 1) / totalR * 100, 2);
        b22 = b22[1];
    } else
            if red and ll {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1] + 1;
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = Round((rll + 1) / totalR * 100, 2);
    } else {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    }
    plot a1 = a11;
    plot b1 = b11;
    plot a2 = a22;
    plot b2 = b22;
}

#def a1 = Score(0).a1;
def a1 = Score(step).a1;
def b1 = Score(step).b1;
def a2 = Score(step).a2;
def b2 = Score(step).b2;

#----------------------------
#def Score(step*4,4)
AddLabel (ShowLabel and green, "BullBar" , Color.GREEN);
AddLabel (ShowLabel and red,  "BearBar" , Color.RED);
AddLabel (ShowLabel and green, a1 + "%" , Color.GREEN);
AddLabel (ShowLabel and green, b1 + "%" , Color.RED);
AddLabel (ShowLabel and red, a2 + "%" , Color.GREEN);
AddLabel (ShowLabel and red, b2 + "%" , Color.RED);


def counpek = if b < 1 then na else if IsNaN(c) and !IsNaN(h[1]) then 1 else counpek[1] + 1;
def hii = GetValue(h, counpek + 1);
def counbot = if b < 1 then na else if IsNaN(c) and !IsNaN(l[1]) then 1 else counbot[1] + 1;
def loo = GetValue(l, counbot + 1);

def upLine = if IsNaN(c) then na else hii[-1];

def DnLine = if IsNaN(c) then na else loo[-1];


AddChartBubble(ShowBubbles and Max(c[2], o[2]) == c[2], upLine[1], a1 + "%", Color.LIME, yes);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == c[2], DnLine[1], b1 + "%" , Color.PINK, no);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == o[2], upLine[1], a2 + "%", Color.LIME, yes);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == o[2], DnLine[1], b2 + "%", Color.PINK, no);

def PrevH = CompoundValue(1, if IsNaN(upLine) then PrevH[1] else h[1], na);
def PrevL = CompoundValue(1, if IsNaN(DnLine) then PrevL[1] else l[1], na);

plot PrevLineH = if !IsNaN(c[1]) then PrevH[-1] else na;
PrevLineH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLineH.SetDefaultColor(Color.LIME);
PrevLineH.SetHiding(!ShowBubbles);

plot PrevLineL = if !IsNaN(c[1]) then PrevL[-1] else na;
PrevLineL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLineL.SetDefaultColor(Color.PINK);
PrevLineL.SetHiding(!ShowBubbles);

script Backtest {
    input v = close;
    def h = high;
    def l = low;
    def p1;
    def p2;
    if v == h[1] {
        if h >= v {
            p1 = p1[1] + 1;
            p2 = p2[1];
        } else {
            p1 = p1[1];
            p2 = p2[1] + 1;
        }
    } else
        if l <= v {
        p1 = p1[1] + 1;
        p2 = p2[1];
    } else {
        p1 = p1[1];
        p2 = p2[1] + 1;
    }

    plot p11 = p1;
    plot p22 = p2;
}
#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#//Run Backtest Function
def p1 = Backtest(if green then (if Max(a1, b1) == a1 then h[1] else l[1])
            else (if Max(a2, b2) == a2 then h[1] else l[1])).p11;
def p2 = Backtest(if green then (if Max(a1, b1) == a1 then h[1] else l[1])
            else (if Max(a2, b2) == a2 then h[1] else l[1])).p22;

#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#// ~~ Table {
#if barstate.islast and array.get(bools,1)
#    //Calulate WinRatio
def Win  = p1;
def Lose  = p2;
def total  = Win + Lose;
def WR = Round(Win / total * 100, 2);

AddLabel(ShowLabel, "Win(" + WR + "%)", Color.WHITE);
AddLabel(ShowLabel, "Size(" + total + ")", Color.WHITE);

#---- END

arJTgQf.png

added 5 breakout levels . the results may vary from TV and on the time aggregation.
CSS:
#// © Zeiierman
#https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
#indicator("Breakout Probability (Expo)"
# Converted and mod by Sam4Cok@Samer800 "Not typical Conv" - 11/2022
# Update - Added 5 brakout Probability lines
#/ ~~ Inputs {
input ShowLabel      = yes;
input ShowBubbles    = yes;
input NumberOfLines  = 5;       # max 5 lines
input NumberOfLabels = 5;      # max 5 Labels
input PercentageStep = 0.1;    # "Percentage Step"

def na = Double.NaN;
#--- Color---
DefineGlobalColor("Green1" , CreateColor(0,255,0));
DefineGlobalColor("Green2" , CreateColor(48,255,48));
DefineGlobalColor("Green3" , CreateColor(96,255,96));
DefineGlobalColor("Green4" , CreateColor(143,255,143));
DefineGlobalColor("Green5" , CreateColor(191,255,191));
DefineGlobalColor("Red1" , CreateColor(255,0,0));
DefineGlobalColor("Red2" , CreateColor(255,48,48));
DefineGlobalColor("Red3" , CreateColor(255,96,96));
DefineGlobalColor("Red4" , CreateColor(255,143,143));
DefineGlobalColor("Red5" , CreateColor(255,191,191));
#-------------
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
def bar = BarNumber();
def lines = if NumberOfLines < 2 then na else
            if NumberOfLines > 5 then 5 else NumberOfLines;
def labels = if NumberOfLabels < 2 then na else
             if NumberOfLabels > 5 then 5 else NumberOfLabels;
def o; def c; def h; def l;
    o = open;
    h = high;
    l = low;
    c = close;
#--------------------------------------------------------
#// ~~ Variables {
def b = BarNumber();

def perStep = if PercentageStep >= 0 then PercentageStep else 0;
def step = c * (perStep / 100);
#/ ~~ Save Number Of Green & Red Candles {
def gr   = if IsNaN(c[1] > o[1]) then c[1] > c[2] else (c[1] > o[1]);
def re   = if IsNaN(c[1] < o[1]) then c[1] < c[2] else (c[1] < o[1]);
def green = if gr != yes then na else gr;
def red   = if re != yes then na else re;

def totalG;
def totalR;
if green {
    totalG = nz(totalG[1] + 1, 1);
    totalR = nz(totalR[1]);
} else {
    if red {
        totalG = nz(totalG[1]);
        totalR = nz(totalR[1] + 1, 1);
    } else {
        totalG = nz(totalG[1]);
        totalR = nz(totalR[1]);
    }
}
script score {
    input x1 = 0;
    input l  = low;
    input h  = high;
    input green1 = no;
    input red1   = no;
    input totalG1 = 0;
    input totalR1 = 0;
    def x = x1;
    def green = green1;
    def red   = red1;
    def totalG = totalG1;
    def totalR = totalR1;
    def ghh;
    def a11;
    def gll;
    def b11;
    def rhh;
    def a22;
    def rll;
    def b22;
    def hh;
    def ll;
    hh = if IsNaN(hh[1]) then 0 else h >= (h[1] + x);
    ll = if IsNaN(ll[1]) then 0 else l <= (l[1] - x);
    if green and hh {
        ghh = ghh[1] + 1;
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = Round((ghh + 1) / totalG * 100, 2);
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    } else
        if green and ll {
        ghh = ghh[1];
        gll = gll[1] + 1;
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = Round((gll + 1) / totalG * 100, 2);
        a22 = a22[1];
        b22 = b22[1];
    } else
            if red and hh {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1] + 1;
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = Round((rhh + 1) / totalR * 100, 2);
        b22 = b22[1];
    } else
            if red and ll {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1] + 1;
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = Round((rll + 1) / totalR * 100, 2);
    } else {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    }
    plot a1 = a11;
    plot b1 = b11;
    plot a2 = a22;
    plot b2 = b22;
}
#-----
def a0  = Score(0, l, h, green, red, totalG, totalR).a1;
def b0  = Score(0, l, h, green, red, totalG, totalR).b1;
def a00 = Score(0, l, h, green, red, totalG, totalR).a2;
def b00 = Score(0, l, h, green, red, totalG, totalR).b2;
#-----
def a1  = Score(step, l, h, green, red, totalG, totalR).a1;
def b1  = Score(step, l, h, green, red, totalG, totalR).b1;
def a11 = Score(step, l, h, green, red, totalG, totalR).a2;
def b11 = Score(step, l, h, green, red, totalG, totalR).b2;
#------
def a2  = Score(step * 2, l, h, green, red, totalG, totalR).a1;
def b2  = Score(step * 2, l, h, green, red, totalG, totalR).b1;
def a22 = Score(step * 2, l, h, green, red, totalG, totalR).a2;
def b22 = Score(step * 2, l, h, green, red, totalG, totalR).b2;
#-----
def a3  = Score(step * 3, l, h, green, red, totalG, totalR).a1;
def b3  = Score(step * 3, l, h, green, red, totalG, totalR).b1;
def a33 = Score(step * 3, l, h, green, red, totalG, totalR).a2;
def b33 = Score(step * 3, l, h, green, red, totalG, totalR).b2;
#-----
def a4  = Score(step * 4, l, h, green, red, totalG, totalR).a1;
def b4  = Score(step * 4, l, h, green, red, totalG, totalR).b1;
def a44 = Score(step * 4, l, h, green, red, totalG, totalR).a2;
def b44 = Score(step * 4, l, h, green, red, totalG, totalR).b2;
#--------Labels-----------------
AddLabel(ShowLabel and green[1], a0 + "%" + " - " + b0 + "%", GlobalColor("Green1"));
AddLabel(ShowLabel and red[1], a00 + "%" + " - " + b00 + "%", GlobalColor("red1"));

AddLabel(ShowLabel and labels>1 and green[1], a1 + "%" + " - " + b1 + "%", GlobalColor("Green2"));
AddLabel(ShowLabel and labels>1 and red[1], a11 + "%" + " - " + b11 + "%", GlobalColor("red2"));

AddLabel(ShowLabel and labels>2 and green[1], a2 + "%" + " - " + b2 + "%", GlobalColor("Green3"));
AddLabel(ShowLabel and labels>2 and red[1], a22 + "%" + " - " + b22 + "%", GlobalColor("red3"));

AddLabel(ShowLabel and labels>3 and green[1], a3 + "%" + " - " + b3 + "%", GlobalColor("Green4"));
AddLabel(ShowLabel and labels>3 and red[1], a33 + "%" + " - " + b33 + "%", GlobalColor("red4"));

AddLabel(ShowLabel and labels>4 and green[1], a4 + "%" + " - " + b4 + "%", GlobalColor("Green5"));
AddLabel(ShowLabel and labels>4 and red[1], a44 + "%" + " - " + b44 + "%", GlobalColor("red5"));

AddLabel(ShowLabel and !green[1] and !red[1], "No Data" , Color.GRAY);
#---- Line 00
def countHi = if b < 1 then na else if IsNaN(c) and !IsNaN(h[1]) then 1 else countHi[1] + 1;
def hi = GetValue(h, countHi + 1);
def countLo = if b < 1 then na else if IsNaN(c) and !IsNaN(l[1]) then 1 else countLo[1] + 1;
def lo = GetValue(l, countLo + 1);
def upLine = if IsNaN(c) then na else hi[-1];
def DnLine = if IsNaN(c) then na else lo[-1];
def PrevH = CompoundValue(1, if IsNaN(upLine) then PrevH[1] else h[1], na);
def PrevL = CompoundValue(1, if IsNaN(DnLine) then PrevL[1] else l[1], na);

plot LineH0 = if !IsNaN(c[1]) then PrevH[-1] else na;
LineH0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineH0.SetDefaultColor(GlobalColor("Green1"));
LineH0.SetHiding(!ShowBubbles);

plot LineL0 = if !IsNaN(c[1]) then PrevL[-1] else na;
LineL0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineL0.SetDefaultColor(GlobalColor("Red1"));
LineL0.SetHiding(!ShowBubbles);

AddChartBubble(ShowBubbles and green[1], upLine[1], a0 + "%", GlobalColor("Green1"), yes);
AddChartBubble(ShowBubbles and green[1], DnLine[1], b0 + "%" , GlobalColor("Red1"), no);
AddChartBubble(ShowBubbles and red[1], upLine[1], a00 + "%", GlobalColor("Green1"), yes);
AddChartBubble(ShowBubbles and red[1], DnLine[1], b00 + "%", GlobalColor("Red1"), no);
#--- Line 11
def stepH1 = if !IsNaN(LineH0) then (LineH0 + step) else na;
def stepL1 = if !IsNaN(LineL0) then (LineL0 - step) else na;

plot LineH1 = if lines > 1 then stepH1[1] else na;
LineH1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineH1.SetDefaultColor(GlobalColor("Green2"));
plot LineL1 = if lines > 1 then stepL1[1] else na;
LineL1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineL1.SetDefaultColor(Color.PINK);

AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH1[-1]), LineH1, a1 + "%", GlobalColor("Green2"), yes);
AddChartBubble(ShowBubbles and green[1] and IsNaN(LineL1[-1]), LineL1, b1 + "%" , GlobalColor("Red2"), no);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH1[-1]), LineH1, a11 + "%", GlobalColor("Green2"), yes);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineL1[-1]), LineL1, b11 + "%", GlobalColor("Red2"), no);
# ---Line 22
def stepH2 = if !IsNaN(LineH0) then (LineH0 + step * 2) else na;
def stepL2 = if !IsNaN(LineL0) then (LineL0 - step * 2) else na;

plot LineH2 = if lines > 2 then stepH2[1] else na;
LineH2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineH2.SetDefaultColor(GlobalColor("Green3"));
plot LineL2 = if lines > 2 then stepL2[1] else na;
LineL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineL2.SetDefaultColor(Color.PINK);

AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH2[-1]), LineH2, a2 + "%", GlobalColor("Green3"), yes);
AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH2[-1]), LineL2, b2 + "%" , GlobalColor("Red3"), no);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH2[-1]), LineH2, a22 + "%", GlobalColor("Green3"), yes);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH2[-1]), LineL2, b22 + "%", GlobalColor("Red3"), no);
# ----- Line 33
def stepH3 = if !IsNaN(LineH0) then (LineH0 + step * 3) else na;
def stepL3 = if !IsNaN(LineL0) then (LineL0 - step * 3) else na;

plot LineH3 = if lines > 3 then stepH3[1] else na;
LineH3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineH3.SetDefaultColor(GlobalColor("Green4"));
plot LineL3 = if lines > 3 then stepL3[1] else na;
LineL3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineL3.SetDefaultColor(Color.PINK);

AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH3[-1]), LineH3, a3 + "%", GlobalColor("Green4"), yes);
AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH3[-1]), LineL3, b3 + "%" , GlobalColor("Red4"), no);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH3[-1]), LineH3, a33 + "%", GlobalColor("Green4"), yes);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH3[-1]), LineL3, b33 + "%", GlobalColor("Red4"), no);
# ---- Line 44
def stepH4 = if !IsNaN(LineH0) then (LineH0 + step * 4) else na;
def stepL4 = if !IsNaN(LineL0) then (LineL0 - step * 4) else na;

plot LineH4 = if lines > 4 then stepH4[1] else na;
LineH4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineH4.SetDefaultColor(GlobalColor("Green5"));
plot LineL4 = if lines > 4 then stepL4[1] else na;
LineL4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LineL4.SetDefaultColor(Color.PINK);

AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH4[-1]), LineH4, a4 + "%", GlobalColor("Green5"), yes);
AddChartBubble(ShowBubbles and green[1] and IsNaN(LineH4[-1]), LineL4, b4 + "%" , GlobalColor("Red5"), no);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH4[-1]), LineH4, a44 + "%", GlobalColor("Green5"), yes);
AddChartBubble(ShowBubbles and red[1] and IsNaN(LineH4[-1]), LineL4, b44 + "%", GlobalColor("Red5"), no);

#--- Backtest
script Backtest {
    input v = close;
    def h = high;
    def h1 = high[1];
    def l = low;
    def p1;
    def p2;
    if v == h1 {
        if h >= v {
            p1 = p1[1] + 1;
            p2 = p2[1];
        } else {
            p1 = p1[1];
            p2 = p2[1] + 1;
        }
    } else
        if l <= v {
        p1 = p1[1] + 1;
        p2 = p2[1];
    } else {
        p1 = p1[1];
        p2 = p2[1] + 1;
    }

    plot p11 = p1;
    plot p22 = p2;
}
#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#//Run Backtest Function
def p1 = Backtest(if green then (if a0 >= b0 then h[1] else l[1])
            else (if a00 >= b00 then h[1] else l[1])).p11;
def p2 = Backtest(if green then (if a0 >= b0 then h[1] else l[1])
            else (if a00 >= b00 then h[1] else l[1])).p22;
#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#    //Calulate WinRatio
def Win  = p1;
def Lose  = p2;
def total  = Win + Lose;
def WR = Round(Win / total * 100, 2);

AddLabel(ShowLabel, "Win(" + WR + "%)", Color.WHITE);
AddLabel(ShowLabel, "Size(" + total + ")", Color.WHITE);

#---- END code
 
Last edited:
check out the below. Not exact conversion but this what I am able to code :).
qqLFDwa.png


CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0
#// © Zeiierman
#https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
#indicator("Breakout Probability (Expo)"
# Converted and mod by Sam4Cok@Samer800 "Not typical Conv" - 11/2022
#/ ~~ Inputs {
input ShowLabel = yes;
input ShowBubbles = yes;
input perc = 0.0;    # "Percentage Step"

def na = Double.NaN;
def bar = BarNumber();

#--------------------------------------------------------
#// ~~ Variables {
def b = BarNumber();
def o = open;
def h = high;
def l = low;
def c = close;
def step = c * (perc / 100);
#/ ~~ Save Number Of Green & Red Candles {
def green = if IsNaN(c[1] > o[1]) then 1 else Max(c[1], o[1]) == c[1];
def red   = if IsNaN(c[1] < o[1]) then 1 else Min(c[1], o[1]) == c[1];
def totalG;
def totalR;
totalG = If(green, totalG[1] + 1, totalG[1]);
totalR = If(red  , totalR[1] + 1, totalR[1]);
script score {
    input x = 0;
    def l = low;
    def h = high;
    def c = close;
    def o = open;
    def green = if IsNaN(green[1]) then 1 else c[1] > o[1];
    def red   = if IsNaN(red[1]) then 1 else c[1] < o[1];
    def totalG = If(green, totalG[1] + 1, totalG[1]);
    def totalR = If(red  , totalR[1] + 1, totalR[1]);
    def ghh;
    def a11;
    def gll;
    def b11;
    def rhh;
    def a22;
    def rll;
    def b22;
    def hh;
    def ll;
    hh = if IsNaN(hh[1]) then 1 else h >= (h[1] + x);
    ll = if IsNaN(ll[1]) then 1 else l <= (l[1] - x);
    if green and hh {
        ghh = ghh[1] + 1;
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = Round((ghh + 1) / totalG * 100, 2);
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    } else
        if green and ll {
        ghh = ghh[1];
        gll = gll[1] + 1;
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = Round((gll + 1) / totalG * 100, 2);
        a22 = a22[1];
        b22 = b22[1];
    } else
            if red and hh {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1] + 1;
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = Round((rhh + 1) / totalR * 100, 2);
        b22 = b22[1];
    } else
            if red and ll {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1] + 1;
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = Round((rll + 1) / totalR * 100, 2);
    } else {
        ghh = ghh[1];
        gll = gll[1];
        rhh = rhh[1];
        rll = rll[1];
        a11 = a11[1];
        b11 = b11[1];
        a22 = a22[1];
        b22 = b22[1];
    }
    plot a1 = a11;
    plot b1 = b11;
    plot a2 = a22;
    plot b2 = b22;
}

#def a1 = Score(0).a1;
def a1 = Score(step).a1;
def b1 = Score(step).b1;
def a2 = Score(step).a2;
def b2 = Score(step).b2;

#----------------------------
#def Score(step*4,4)
AddLabel (ShowLabel and green, "BullBar" , Color.GREEN);
AddLabel (ShowLabel and red,  "BearBar" , Color.RED);
AddLabel (ShowLabel and green, a1 + "%" , Color.GREEN);
AddLabel (ShowLabel and green, b1 + "%" , Color.RED);
AddLabel (ShowLabel and red, a2 + "%" , Color.GREEN);
AddLabel (ShowLabel and red, b2 + "%" , Color.RED);


def counpek = if b < 1 then na else if IsNaN(c) and !IsNaN(h[1]) then 1 else counpek[1] + 1;
def hii = GetValue(h, counpek + 1);
def counbot = if b < 1 then na else if IsNaN(c) and !IsNaN(l[1]) then 1 else counbot[1] + 1;
def loo = GetValue(l, counbot + 1);

def upLine = if IsNaN(c) then na else hii[-1];

def DnLine = if IsNaN(c) then na else loo[-1];


AddChartBubble(ShowBubbles and Max(c[2], o[2]) == c[2], upLine[1], a1 + "%", Color.LIME, yes);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == c[2], DnLine[1], b1 + "%" , Color.PINK, no);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == o[2], upLine[1], a2 + "%", Color.LIME, yes);
AddChartBubble(ShowBubbles and Max(c[2], o[2]) == o[2], DnLine[1], b2 + "%", Color.PINK, no);

def PrevH = CompoundValue(1, if IsNaN(upLine) then PrevH[1] else h[1], na);
def PrevL = CompoundValue(1, if IsNaN(DnLine) then PrevL[1] else l[1], na);

plot PrevLineH = if !IsNaN(c[1]) then PrevH[-1] else na;
PrevLineH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLineH.SetDefaultColor(Color.LIME);
PrevLineH.SetHiding(!ShowBubbles);

plot PrevLineL = if !IsNaN(c[1]) then PrevL[-1] else na;
PrevLineL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLineL.SetDefaultColor(Color.PINK);
PrevLineL.SetHiding(!ShowBubbles);

script Backtest {
    input v = close;
    def h = high;
    def l = low;
    def p1;
    def p2;
    if v == h[1] {
        if h >= v {
            p1 = p1[1] + 1;
            p2 = p2[1];
        } else {
            p1 = p1[1];
            p2 = p2[1] + 1;
        }
    } else
        if l <= v {
        p1 = p1[1] + 1;
        p2 = p2[1];
    } else {
        p1 = p1[1];
        p2 = p2[1] + 1;
    }

    plot p11 = p1;
    plot p22 = p2;
}
#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#//Run Backtest Function
def p1 = Backtest(if green then (if Max(a1, b1) == a1 then h[1] else l[1])
            else (if Max(a2, b2) == a2 then h[1] else l[1])).p11;
def p2 = Backtest(if green then (if Max(a1, b1) == a1 then h[1] else l[1])
            else (if Max(a2, b2) == a2 then h[1] else l[1])).p22;

#//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
#// ~~ Table {
#if barstate.islast and array.get(bools,1)
#    //Calulate WinRatio
def Win  = p1;
def Lose  = p2;
def total  = Win + Lose;
def WR = Round(Win / total * 100, 2);

AddLabel(ShowLabel, "Win(" + WR + "%)", Color.WHITE);
AddLabel(ShowLabel, "Size(" + total + ")", Color.WHITE);

#---- END


maybe this will help someone take @samer800 study to the next level...
i know it's a small part. there needs to be many more variables added to calculate all 10 of the %'s.

i have been studying the matrix function in pine, but will be awhile before i have time to try a full conversion.

this is a template, ( it doesn't do anything by itself )
for drawing 5 lines above and below , the prev bar and current bar.
draw bubbles to the right of the lines. this example has the price levels in the bubbles, not a %.


Code:
# breakout_lines_0

# draw 5 lines above and below , the prev bar and current bar

def bn = BarNumber();
def na = Double.NaN;

def o = open;
def h = high;
def l = low;
def c = close;

input perc = 1.0;
def step = c * (perc / 100);

def prevbar = (!IsNaN(close[0]) and !IsNaN(close[-1]) and IsNaN(close[-2]));
def currentbar = (!IsNaN(close[0]) and IsNaN(close[-1]));

def bubble_offset = 2;
def bubble_bar = (!IsNaN(close[bubble_offset]) and IsNaN(close[bubble_offset-1]));


#-------------------------

def hi1 = if bn == 1 then na
  else if prevbar then (h + (step * 0))
  else if currentbar then hi1[1]
  else na;
plot zhi1 = hi1;
zhi1.SetDefaultColor(Color.GREEN);
#zhi1.setlineweight(1);
#zhi1.HideBubble();

def hi2 = if bn == 1 then na
  else if prevbar then (h + (step * 1))
  else if currentbar then hi2[1]
  else na;
plot zhi2 = hi2;
zhi2.SetDefaultColor(Color.GREEN);
#zhi2.HideBubble();

def hi3 = if bn == 1 then na
  else if prevbar then (h + (step * 2))
  else if currentbar then hi3[1]
  else na;
plot zhi3 = hi3;
zhi3.SetDefaultColor(Color.GREEN);
#zhi3.HideBubble();

def hi4 = if bn == 1 then na
  else if prevbar then (h + (step * 3))
  else if currentbar then hi4[1]
  else na;
plot zhi4 = hi4;
zhi4.SetDefaultColor(Color.GREEN);
#zhi4.HideBubble();

def hi5 = if bn == 1 then na
  else if prevbar then (h + (step * 4))
  else if currentbar then hi5[1]
  else na;
plot zhi5 = hi5;
zhi5.SetDefaultColor(Color.GREEN);
#zhi5.HideBubble();

#-------------------------

def lo1 = if bn == 1 then na
  else if prevbar then (l - (step * 0))
  else if currentbar then lo1[1]
  else na;
plot zlo1 = lo1;
zlo1.SetDefaultColor(Color.red);
#zlo1.setlineweight(1);
#zlo1.HideBubble();

def lo2 = if bn == 1 then na
  else if prevbar then (l - (step * 1))
  else if currentbar then lo2[1]
  else na;
plot zlo2 = lo2;
zlo2.SetDefaultColor(Color.red);
#zlo2.HideBubble();

def lo3 = if bn == 1 then na
  else if prevbar then (l - (step * 2))
  else if currentbar then lo3[1]
  else na;
plot zlo3 = lo3;
zlo3.SetDefaultColor(Color.red);
#zlo3.HideBubble();

def lo4 = if bn == 1 then na
  else if prevbar then (l - (step * 3))
  else if currentbar then lo4[1]
  else na;
plot zlo4 = lo4;
zlo4.SetDefaultColor(Color.red);
#zlo4.HideBubble();

def lo5 = if bn == 1 then na
  else if prevbar then (l - (step * 4))
  else if currentbar then lo5[1]
  else na;
plot zlo5 = lo5;
zlo5.SetDefaultColor(Color.red);
#zlo5.HideBubble();

#------------------------

addchartbubble(bubble_bar, hi1[bubble_offset], hi1[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi2[bubble_offset], hi2[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi3[bubble_offset], hi3[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi4[bubble_offset], hi4[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi5[bubble_offset], hi5[bubble_offset], color.green, yes);

addchartbubble(bubble_bar, lo1[bubble_offset], lo1[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo2[bubble_offset], lo2[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo3[bubble_offset], lo3[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo4[bubble_offset], lo4[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo5[bubble_offset], lo5[bubble_offset], color.red, no);


#-----------------------------

# test shape placement, rt of line
input test1 = no;
plot zi = if test1 and bubble_bar then hi3[bubble_offset] else na;
zi.SetPaintingStrategy(PaintingStrategy.SQUARES);
zi.SetDefaultColor(Color.cyan);
zi.setlineweight(4);
zi.hidebubble();


# ref
# https://usethinkscript.com/threads/breakout-probability-expo-for-thinkorswim.12436/#post-111727
# Breakout Probability (Expo) For ThinkOrSwim
#
# https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
#

pLgB2bF.jpg
 
maybe this will help someone take @samer800 study to the next level...
i know it's a small part. there needs to be many more variables added to calculate all 10 of the %'s.

i have been studying the matrix function in pine, but will be awhile before i have time to try a full conversion.

this is a template, ( it doesn't do anything by itself )
for drawing 5 lines above and below , the prev bar and current bar.
draw bubbles to the right of the lines. this example has the price levels in the bubbles, not a %.


Code:
# breakout_lines_0

# draw 5 lines above and below , the prev bar and current bar

def bn = BarNumber();
def na = Double.NaN;

def o = open;
def h = high;
def l = low;
def c = close;

input perc = 1.0;
def step = c * (perc / 100);

def prevbar = (!IsNaN(close[0]) and !IsNaN(close[-1]) and IsNaN(close[-2]));
def currentbar = (!IsNaN(close[0]) and IsNaN(close[-1]));

def bubble_offset = 2;
def bubble_bar = (!IsNaN(close[bubble_offset]) and IsNaN(close[bubble_offset-1]));


#-------------------------

def hi1 = if bn == 1 then na
  else if prevbar then (h + (step * 0))
  else if currentbar then hi1[1]
  else na;
plot zhi1 = hi1;
zhi1.SetDefaultColor(Color.GREEN);
#zhi1.setlineweight(1);
#zhi1.HideBubble();

def hi2 = if bn == 1 then na
  else if prevbar then (h + (step * 1))
  else if currentbar then hi2[1]
  else na;
plot zhi2 = hi2;
zhi2.SetDefaultColor(Color.GREEN);
#zhi2.HideBubble();

def hi3 = if bn == 1 then na
  else if prevbar then (h + (step * 2))
  else if currentbar then hi3[1]
  else na;
plot zhi3 = hi3;
zhi3.SetDefaultColor(Color.GREEN);
#zhi3.HideBubble();

def hi4 = if bn == 1 then na
  else if prevbar then (h + (step * 3))
  else if currentbar then hi4[1]
  else na;
plot zhi4 = hi4;
zhi4.SetDefaultColor(Color.GREEN);
#zhi4.HideBubble();

def hi5 = if bn == 1 then na
  else if prevbar then (h + (step * 4))
  else if currentbar then hi5[1]
  else na;
plot zhi5 = hi5;
zhi5.SetDefaultColor(Color.GREEN);
#zhi5.HideBubble();

#-------------------------

def lo1 = if bn == 1 then na
  else if prevbar then (l - (step * 0))
  else if currentbar then lo1[1]
  else na;
plot zlo1 = lo1;
zlo1.SetDefaultColor(Color.red);
#zlo1.setlineweight(1);
#zlo1.HideBubble();

def lo2 = if bn == 1 then na
  else if prevbar then (l - (step * 1))
  else if currentbar then lo2[1]
  else na;
plot zlo2 = lo2;
zlo2.SetDefaultColor(Color.red);
#zlo2.HideBubble();

def lo3 = if bn == 1 then na
  else if prevbar then (l - (step * 2))
  else if currentbar then lo3[1]
  else na;
plot zlo3 = lo3;
zlo3.SetDefaultColor(Color.red);
#zlo3.HideBubble();

def lo4 = if bn == 1 then na
  else if prevbar then (l - (step * 3))
  else if currentbar then lo4[1]
  else na;
plot zlo4 = lo4;
zlo4.SetDefaultColor(Color.red);
#zlo4.HideBubble();

def lo5 = if bn == 1 then na
  else if prevbar then (l - (step * 4))
  else if currentbar then lo5[1]
  else na;
plot zlo5 = lo5;
zlo5.SetDefaultColor(Color.red);
#zlo5.HideBubble();

#------------------------

addchartbubble(bubble_bar, hi1[bubble_offset], hi1[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi2[bubble_offset], hi2[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi3[bubble_offset], hi3[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi4[bubble_offset], hi4[bubble_offset], color.green, yes);
addchartbubble(bubble_bar, hi5[bubble_offset], hi5[bubble_offset], color.green, yes);

addchartbubble(bubble_bar, lo1[bubble_offset], lo1[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo2[bubble_offset], lo2[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo3[bubble_offset], lo3[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo4[bubble_offset], lo4[bubble_offset], color.red, no);
addchartbubble(bubble_bar, lo5[bubble_offset], lo5[bubble_offset], color.red, no);


#-----------------------------

# test shape placement, rt of line
input test1 = no;
plot zi = if test1 and bubble_bar then hi3[bubble_offset] else na;
zi.SetPaintingStrategy(PaintingStrategy.SQUARES);
zi.SetDefaultColor(Color.cyan);
zi.setlineweight(4);
zi.hidebubble();


# ref
# https://usethinkscript.com/threads/breakout-probability-expo-for-thinkorswim.12436/#post-111727
# Breakout Probability (Expo) For ThinkOrSwim
#
# https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/
#

pLgB2bF.jpg
added 5 levels in the original post. pls check.
 
Breakout Probability (good for scalping)
I trade with VPOC but this indicator can aid your positioning. Worth it in my opinion:

Breakout Probability is a valuable indicator that calculates the probability of a new high or low and displays it as a level with its percentage. The probability of a new high and low is backtested, and the results are shown in a table— a simple way to understand the next candle's likelihood of a new high or low. In addition, the indicator displays an additional four levels above and under the candle with the probability of hitting these levels.

The indicator helps traders to understand the likelihood of the next candle's direction, which can be used to set your trading bias.


Calculations

The algorithm calculates all the green and red candles separately depending on whether the previous candle was red or green and assigns scores if one or more lines were reached. The algorithm then calculates how many candles reached those levels in history and displays it as a percentage value on each line.

Video:

Script:
https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/?aff_id=27627
 
Last edited by a moderator:
Breakout Probability (good for scalping)
I trade with VPOC but this indicator can aid your positioning. Worth it in my opinion:



Video:

Script:
https://www.tradingview.com/script/Qt7fqntR-Breakout-Probability-Expo/?aff_id=27627

Code:
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Zeiierman

//@version=5
indicator("Breakout Probability (Expo)",overlay=true,max_bars_back=5000)

// ~~ Tooltips {
t1 = "The space between the levels can be adjusted with a percentage step. 1% means that each level is located 1% above/under the previous one."
t2 = "Set the number of levels you want to display."
t3 = "If a level got 0 % likelihood of being hit, the level is not displayed as default. Enable the option if you want to see all levels regardless of their values."
t4 = "Enable this option if you want to display the backtest statistics for that a new high or low is made."
string [] tbl_tips = array.from("Number of times price has reached the first highest percentage level",
 "Number of times price failed to reach the first highest percentage level",
 "Win/Loss ratio")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Inputs {
perc                    = input.float(1.0,title="Percentage Step",step=.1,minval=0,group="Settings",tooltip=t1)
nbr                     = input.int(5, title="Number of Lines",maxval=5,minval=1,group="Settings",tooltip=t2)
upCol                   = input.color(color.new(color.green,0),title="",inline="col"),dnCol=input.color(color.new(color.red,0),title="",inline="col"),fill=input.bool(true,title="BG Color",inline="col")
var bool [] bools       = array.from(input.bool(true,title="Disable 0.00%",group="Settings",tooltip=t3),input.bool(true, title="Show Statistic Panel",group="Settings",tooltip=t4))
var bool [] alert_bool  = array.from(
 input.bool(true,title="Ticker ID",group="Any alert() function call"),
 input.bool(true,title="High/Low Price",group="Any alert() function call"),
 input.bool(true,title="Bullish/Bearish Bias",group="Any alert() function call"),
 input.bool(true,title="Bullish/Bearish Percentage",group="Any alert() function call"))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Variables {
b = bar_index
o = open
h = high
l = low
c = close
step = c*(perc/100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Save Values In Matrix {
var total  = matrix.new<int>(7,4,0)
var vals   = matrix.new<float>(5,4,0.0)
var lines  = matrix.new<line>(1,10,line(na))
var labels = matrix.new<label>(1,10,label(na))
var tbl    = matrix.new<table>(1,1,table.new(position.top_right,2,3,
 frame_color=color.new(color.gray,50),frame_width=3,
 border_color=chart.bg_color,border_width=-2))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Save Number Of Green & Red Candles {
green = c[1]>o[1]
red   = c[1]<o[1]
if green
    prev = matrix.get(total,5,0)
    matrix.set(total,5,0,prev+1)
if red
    prev = matrix.get(total,5,1)
    matrix.set(total,5,1,prev+1)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Functions {
//Lines
CreateLine(p,i,c)=>
    prevLine = matrix.get(lines,0,i)
    line.delete(prevLine)
    li = line.new(b[1],p,b,p,color=c,width=2)
    matrix.set(lines,0,i,li)
//Labels
CreateLabel(p,i,c,r,v)=>
    prevLabel = matrix.get(labels,0,i)
    label.delete(prevLabel)
    la = label.new(b+1,p,text=str.tostring(matrix.get(vals,r,v),format.percent),
     style=label.style_label_left,color=color.new(color.black,100),textcolor=c)
    matrix.set(labels,0,i,la)
//Score Calculation
Score(x,i)=>
    ghh = matrix.get(total,i,0)
    gll = matrix.get(total,i,1)
    rhh = matrix.get(total,i,2)
    rll = matrix.get(total,i,3)
    gtotal = matrix.get(total,5,0)
    rtotal = matrix.get(total,5,1)
    hh = h>=h[1] + x
    ll = l<=l[1] - x
    if green and hh
        matrix.set(total,i,0,ghh+1)
        matrix.set(vals,i,0,math.round(((ghh+1)/gtotal)*100,2))
    if green and ll
        matrix.set(total,i,1,gll+1)
        matrix.set(vals,i,1,math.round(((gll+1)/gtotal)*100,2))
    if red and hh
        matrix.set(total,i,2,rhh+1)
        matrix.set(vals,i,2,math.round(((rhh+1)/rtotal)*100,2))
    if red and ll
        matrix.set(total,i,3,rll+1)
        matrix.set(vals,i,3,math.round(((rll+1)/rtotal)*100,2))
//Backtest
Backtest(v)=>
    p1 = matrix.get(total,6,0)
    p2 = matrix.get(total,6,1)
    if v==h[1]
        if h>=v
            matrix.set(total,6,0,p1+1)
        else
            matrix.set(total,6,1,p2+1)
    else
        if l<=v
            matrix.set(total,6,0,p1+1)
        else
            matrix.set(total,6,1,p2+1)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Code {
//Run Score Function
Score(0,0)
Score(step,1)
Score(step*2,2)
Score(step*3,3)
Score(step*4,4)

//Fetch Score Values
a1 = matrix.get(vals,0,0)
b1 = matrix.get(vals,0,1)
a2 = matrix.get(vals,0,2)
b2 = matrix.get(vals,0,3)

//Lines & Labels & Alerts
for i=0 to nbr-1
    hide = array.get(bools,0)
    if not hide or (hide and (green?math.min(matrix.get(vals,i,0),
     matrix.get(vals,i,1))>0:
     math.min(matrix.get(vals,i,2),
     matrix.get(vals,i,3))>0))
        hi = h[1]+(step*i)
        lo = l[1]-(step*i)
        //Plot Lines
        CreateLine(hi,i,upCol)
        CreateLine(lo,5+i,dnCol)
        //Plot Labels
        if green
            CreateLabel(hi,i,upCol,i,0)
            CreateLabel(lo,5+i,dnCol,i,1)
        else
            CreateLabel(hi,i,upCol,i,2)
            CreateLabel(lo,5+i,dnCol,i,3)
        //Create Alert
        if array.includes(alert_bool, true)
            s1 = str.tostring(syminfo.ticker)
            s2 = "High Price: "+str.tostring(math.round_to_mintick(h[1]))+
             " | Low Price: "+str.tostring(math.round_to_mintick(l[1]))
            s3 = green?(math.max(a1,b1)==a1?"BULLISH":"BEARISH"):
             (math.max(a2,b2)==a2?"BULLISH":"BEARISH")
            s4 = green?(math.max(a1,b1)==a1?a1:b1):(math.min(a2,b2)==a2?a2:b2)
            s5 = red  ?(math.max(a2,b2)==a2?a2:b2):(math.min(a1,b1)==a1?a1:b1)
            string [] str_vals = array.from(s1,s2,"BIAS: "+s3,
             "Percentage: High: "+str.tostring(s4,format.percent)
             +" | Low: "+str.tostring(s5,format.percent))
            output = array.new_string()
            for x=0 to array.size(alert_bool)-1
                if array.get(alert_bool,x)
                    array.push(output,array.get(str_vals,x))
            //Alert Is Triggered On Every Bar Open With Bias And Percentage Ratio
            alert(array.join(output,'\n'),alert.freq_once_per_bar)
    else
        //Delete Old Lines & Labels
        line.delete(matrix.get(lines,0,i))
        line.delete(matrix.get(lines,0,5+i))
        label.delete(matrix.get(labels,0,i))
        label.delete(matrix.get(labels,0,5+i))

//Run Backtest Function
Backtest(green?(math.max(a1,b1)==a1?h[1]:l[1]):(math.max(a2,b2)==a2?h[1]:l[1]))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Linefill {
if fill
    var filler = linefill(na)
    for i=0 to 8
        get = matrix.get(lines,0,i)
        get1= matrix.get(lines,0,i+1)
        col = i>4?color.new(dnCol,80) : i==4?color.new(color.gray,100) : color.new(upCol,80)
        filler := linefill.new(get,get1,color=col)
        linefill.delete(filler[1])
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Table {
if barstate.islast and array.get(bools,1)
    //Calulate WinRatio
    W  = matrix.get(total,6,0)
    L  = matrix.get(total,6,1)
    WR = math.round(W/(W+L)*100,2)
    string [] tbl_vals = array.from("WIN: "+str.tostring(W),
     "LOSS: "+str.tostring(L),
     "Profitability: "+str.tostring(WR,format.percent))
    color [] tbl_col = array.from(color.green,color.red,chart.fg_color)
    for i=0 to 2
        table.cell(matrix.get(tbl,0,0),0,i,array.get(tbl_vals,i),
         text_halign=text.align_center,bgcolor=chart.bg_color,
         text_color=array.get(tbl_col,i),text_size=size.auto,
         tooltip=array.get(tbl_tips,i))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
check this

https://usethinkscript.com/threads/breakout-probability-expo-for-thinkorswim.12436/
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

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

Frequently Asked Questions

What is useThinkScript?

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

How do I get started?

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

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

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