Old Tradability by Kiersten & Haji
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hajjiplays
//This code is now available to the public. People may now copy and reuse the code in bigger projects. 
//However this script property of NoGoodLuck LLC, and may not be copied or redistributed without credit to Elhadji Ouedrago or NoGoodLuck. 
//@version=5
 

//VERY BEGINNING -------------------------------------------------------------------------------------------------------VERY BEGINNING//
//VERY BEGINNING -------------------------------------------------------------------------------------------------------VERY BEGINNING//



indicator("Old Tradability by Kiersten & Haji", overlay = false) 

//SETTINGS ------------------------------------------------------------------------------------------------------------- SETTINGS//
//SETTINGS ------------------------------------------------------------------------------------------------------------- SETTINGS//
device = input.string("Computer", "Device", ["Computer", "Mobile"], group = "Basic Settings")
source = input.string("High / Low", "Source", ["High / Low", "Close"], group = "Basic Settings")
areanumber = input.int(8, "True Area Lookback Number", group = "Basic Settings") 
lookback = 100
timeframes=input.timeframe("15","Normalization Timeframe", group = "Basic Settings")

takeprofit = input.string("Normalized Take Profit", "Take Profit Levels", ["Normalized Take Profit", "Kiersten Take Profit"], group = "Structure Settings")
stoploss = input.string("Normalized Stop Loss", "Stop Loss Levels", ["Normalized Stop Loss", "Kiersten Stop Loss"], group = "Structure Settings")
kierstenamount = input.int(1, title = "Kiersten Dynamic Bar Amount", group = "Structure Settings")
bias = input.string("Automatic", "Trend Direction", options = ["Automatic", "Bullish", "Bearish"], group = "Structure Settings")

UsePatterns = input.bool(false, "Use Patterns In Alerts", group = "Patterns")
patterns_short = input.timeframe('60', "Patterns Short Timeframe", group = "Patterns")
patterns_long = input.timeframe('240', "Patterns Long Timeframe", group = "Patterns")

useLongHeikinAshi = input.bool(true, "Use 4 Hour Heikin Ashi", group = "Considerations")
useWilliamAlligator = input.bool(true, "Use William Alligator", group = "Considerations")
useChandelierExit = input.bool(true, "Use Chandelier Exit", group = "Considerations")
useShortHeikinAshi = input.bool(true, "Use 1 Hour Heikin Ashi", group = "Considerations")
useMFI = input.bool(true, "Use MFI", group = "Considerations") 
useMACD = input.bool(true, "Use MacD", group = "Considerations")
useEverything = input.bool(true, "Show Everything Crosses", group = "Considerations")

trueareaalertvalue = input.int(0, title = "True Area Score Alert Value", group = "Alerts")
normalizedvalue = input.int(50, "Normalization (Enter)", group = "Alerts") 
normalizedmode = input.string("Automatic", "Normalization Mode", ["Automatic", "Manual"])
normalizedvaluetakeprofit = input.float(50, "Normalization (Take Profit)", group = "Alerts")
normalizedvaluestoploss = input.float(50, "Normalization (Stop Loss)", group = "Alerts")

positionSize = input.int(title="Position Size", defval=5, group = "Risk Management")
maxrisk = input.int(10000, "Maximum Risk", group = "Risk Management")
minreward = input.int(0, "Minmum Reward", group = "Risk Management")
minRRR = input.int(0, "Minmum Risk Reward Ratio", group = "Risk Management")

//END OF SETTINGS ------------------------------------------------------------------------------------------------------END OF SETTINGS//
//END OF SETTINGS ------------------------------------------------------------------------------------------------------END OF SETTINGS//
 

//SPEED CALCULATIONS ---------------------------------------------------------------------------------------------------SPEED CALCULATIONS//
//SPEED CALCULATIONS ---------------------------------------------------------------------------------------------------SPEED CALCULATIONS//

// Calculate the duration of a bar in seconds

// Calculate the difference in price between the current and previous bar
price1 = request.security(syminfo.tickerid, "1", close[2])
price2 = request.security(syminfo.tickerid, "1", close[1])
priceChange = math.abs(price1 - price2)

// Convert the price change to pips
priceChangeInPips = priceChange / syminfo.mintick

// Calculate the speed of the stock in pips per second
speed = priceChangeInPips

//END SPEED CALCULATIONS -----------------------------------------------------------------------------------------------END SPEED CALCULATIONS//
//END SPEED CALCULATIONS -----------------------------------------------------------------------------------------------END SPEED CALCULATIONS//

//HEIKIN ASHI CALCULATIONS ---------------------------------------------------------------------------------------------HEIKIN ASHI CALCULATIONS//
//HEIKIN ASHI CALCULATIONS ---------------------------------------------------------------------------------------------HEIKIN ASHI CALCULATIONS//
ha_t = ticker.heikinashi(syminfo.tickerid)
normal = ticker.new(syminfo.prefix, syminfo.tickerid)


resS = 'S'
ha_openS = request.security(ha_t, resS, open)
ha_closeS = request.security(ha_t, resS, close)
ha_difS = ha_openS - ha_closeS
iff_S = ha_difS < 0 ? 2 : 3
ha_diffS = ha_difS > 0 ? 1 : iff_S
 
res1 = '1'
ha_open1 = request.security(ha_t, res1, open)
ha_close1 = request.security(ha_t, res1, close)
ha_dif1 = ha_open1 - ha_close1
iff_1 = ha_dif1 < 0 ? 2 : 3
ha_diff1 = ha_dif1 > 0 ? 1 : iff_1

res3 = '3'
ha_open3 = request.security(ha_t, res3, open)
ha_close3 = request.security(ha_t, res3, close)
ha_dif3 = ha_open3 - ha_close3
iff_3 = ha_dif3 < 0 ? 2 : 3
ha_diff3 = ha_dif3 > 0 ? 1 : iff_3
 
res5 = '5'
ha_open5 = request.security(ha_t, res5, open)
ha_close5 = request.security(ha_t, res5, close)
ha_dif5 = ha_open5 - ha_close5
iff_5 = ha_dif5 < 0 ? 2 : 3
ha_diff5 = ha_dif5 > 0 ? 1 : iff_5

res15 = '15'
ha_open15 = request.security(ha_t, res15, open)
ha_close15 = request.security(ha_t, res15, close)
ha_dif15 = ha_open15 - ha_close15
iff_15 = ha_dif15 < 0 ? 2 : 3
ha_diff15 = ha_dif15 > 0 ? 1 : iff_15

res30 = '30'
ha_open30 = request.security(ha_t, res30, open)
ha_close30 = request.security(ha_t, res30, close)
ha_dif30 = ha_open30 - ha_close30
iff_30 = ha_dif30 < 0 ? 2 : 3
ha_diff30 = ha_dif30 > 0 ? 1 : iff_30

res60 = '60'
ha_open60 = request.security(ha_t, res60, open)
ha_close60 = request.security(ha_t, res60, close)
ha_dif60 = ha_open60 - ha_close60
iff_60 = ha_dif60 < 0 ? 2 : 3
ha_diff60 = ha_dif60 > 0 ? 1 : iff_60

res120 = '120'
ha_open120 = request.security(ha_t, res120, open)
ha_close120 = request.security(ha_t, res120, close)
ha_dif120 = ha_open120 - ha_close120
iff_120 = ha_dif120 < 0 ? 2 : 3
ha_diff120 = ha_dif120 > 0 ? 1 : iff_120

res180 = '180'
ha_open180 = request.security(ha_t, res180, open)
ha_close180 = request.security(ha_t, res180, close)
ha_dif180 = ha_open180 - ha_close180
iff_180 = ha_dif180 < 0 ? 2 : 3
ha_diff180 = ha_dif180 > 0 ? 1 : iff_180

res240 = '240'
ha_open240 = request.security(ha_t, res240, open)
ha_close240 = request.security(ha_t, res240, close)
ha_dif240 = ha_open240 - ha_close240
iff_240 = ha_dif240 < 0 ? 2 : 3
ha_diff240 = ha_dif240 > 0 ? 1 : iff_240

resD = 'D'
ha_openD = request.security(ha_t, resD, open)
ha_closeD = request.security(ha_t, resD, close)
ha_difD = ha_openD - ha_closeD
iff_D = ha_difD < 0 ? 2 : 3
ha_diffD = ha_difD > 0 ? 1 : iff_D

resshort = patterns_short
ha_openshort = request.security(ha_t, resshort, open)
ha_closeshort = request.security(ha_t, resshort, close)
ha_difshort = ha_openshort - ha_closeshort
iff_short = ha_difshort < 0 ? 2 : 3
ha_diffshort = ha_difshort > 0 ? 1 : iff_short

reslong = patterns_long
ha_openlong = request.security(ha_t, reslong, open)
ha_closelong = request.security(ha_t, reslong, close)
ha_diflong = ha_openlong - ha_closelong
iff_long = ha_diflong < 0 ? 2 : 3
ha_difflong = ha_diflong > 0 ? 1 : iff_long

//END OF HEIKIN ASHI CALCULATIONS --------------------------------------------------------------------------------------END OF HEIKIN ASHI CALCULATIONS//
//END OF HEIKIN ASHI CALCULATIONS --------------------------------------------------------------------------------------END OF HEIKIN ASHI CALCULATIONS//


//PATTERN DETECTION ----------------------------------------------------------------------------------------------------PATTERN DETECTION//
//PATTERN DETECTION ----------------------------------------------------------------------------------------------------PATTERN DETECTION//
trend = 'Consolidation'

if ha_diffshort == 2 and ha_difflong == 2
    trend := 'Bullish'

if ha_diffshort == 1 and ha_difflong == 1
    trend := 'Bearish'

if ha_diffshort[2] == 1 and ha_diffshort[1] == 1 and ha_diffshort == 1 and ha_difflong[2] == 2 and ha_difflong[1] == 2 and ha_difflong == 2
    trend := 'Consolidation'

if ha_diffshort[2] == 2 and ha_diffshort[1] == 2 and ha_diffshort == 2 and ha_difflong[2] == 1 and ha_difflong[1] == 1 and ha_difflong == 1
    trend := 'Consolidation'

if ha_diffshort[1] == 1 and ha_diffshort == 2 and ha_difflong[1] == 1 and ha_difflong == 2
    trend := 'Double Up'

if ha_diffshort[2] == 1 and ha_diffshort[1] == 2 and ha_difflong[2] == 1 and ha_difflong[1] == 2 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Double Up Confirmed'

if ha_diffshort[2] == 1 and ha_diffshort[1] == 2 and ha_difflong[2] == 1 and ha_difflong[1] == 2 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Double Up Declined'

if ha_diffshort[1] == 2 and ha_diffshort == 1 and ha_difflong[1] == 2 and ha_difflong == 1
    trend := 'Double Down'

if ha_diffshort[2] == 2 and ha_diffshort[1] == 1 and ha_difflong[2] == 2 and ha_difflong[1] == 1 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Double Down Confirmed'

if ha_diffshort[2] == 2 and ha_diffshort[1] == 1 and ha_difflong[2] == 2 and ha_difflong[1] == 1 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Double Down Declined'

if ha_diffshort[1] == 1 and ha_diffshort == 2 and ha_difflong[1] == 2 and ha_difflong == 2
    trend := 'Bullish Continuation'

if ha_diffshort[2] == 1 and ha_diffshort[1] == 2 and ha_difflong[2] == 2 and ha_difflong[1] == 2 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Bullish Continuation Confirmed'

if ha_diffshort[2] == 1 and ha_diffshort[1] == 2 and ha_difflong[2] == 2 and ha_difflong[1] == 2 and ha_diffshort == 1 and ha_difflong == 2
    trend := 'Bullish Continuation Declined'

if ha_diffshort[1] == 2 and ha_diffshort == 1 and ha_difflong[1] == 1 and ha_difflong == 1
    trend := 'Bearish Continuation'

if ha_diffshort[2] == 2 and ha_diffshort[1] == 1 and ha_difflong[2] == 1 and ha_difflong[1] == 1 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Bearish Continuation Confirmed'

if ha_diffshort[2] == 2 and ha_diffshort[1] == 1 and ha_difflong[2] == 1 and ha_difflong[1] == 1 and ha_diffshort == 2 and ha_difflong == 1
    trend := 'Bearish Continuation Declined'

if ha_difflong[1] == 1 and ha_difflong == 2 and ha_diffshort[1] == 2 and ha_diffshort == 2
    trend := 'Bullish Break'

if ha_difflong[2] == 1 and ha_difflong[1] == 2 and ha_diffshort[2] == 2 and ha_diffshort[1] == 2 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Bullish Break Confirmed'

if ha_difflong[2] == 1 and ha_difflong[1] == 2 and ha_diffshort[2] == 2 and ha_diffshort[1] == 2 and ha_diffshort == 1 and ha_difflong == 2
    trend := 'Bullish Break Declined'

if ha_difflong[2] == 1 and ha_difflong[1] == 2 and ha_diffshort[2] == 2 and ha_diffshort[1] == 2 and ha_diffshort == 2 and ha_difflong == 1
    trend := 'Bullish Break Declined'

if ha_difflong[1] == 2 and ha_difflong == 1 and ha_diffshort[1] == 1 and ha_diffshort == 1
    trend := 'Bearish Break'

if ha_difflong[2] == 2 and ha_difflong[1] == 1 and ha_diffshort[2] == 1 and ha_diffshort[1] == 1 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Bearish Break Confirmed'

if ha_difflong[2] == 2 and ha_difflong[1] == 1 and ha_diffshort[2] == 1 and ha_diffshort[1] == 1 and ha_diffshort == 2 and ha_difflong == 1
    trend := 'Bearish Break Declined'

if ha_difflong[2] == 2 and ha_difflong[1] == 1 and ha_diffshort[2] == 1 and ha_diffshort[1] == 1 and ha_diffshort == 1 and ha_difflong == 2
    trend := 'Bearish Break Declined'

if ha_diffshort == 2 and ha_difflong[1] == 2 and ha_difflong == 1 or ha_diffshort == 2 and ha_difflong[2] == 2 and ha_difflong == 1
    trend := 'Bullish Trend Swapping'

if ha_diffshort[1] == 2 and ha_difflong[2] == 2 and ha_difflong[1] == 1 or ha_diffshort[1] == 2 and ha_difflong[3] == 2 and ha_difflong[1] == 1 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Bullish Trend Swapping Confirmed'

if ha_diffshort[1] == 2 and ha_difflong[2] == 2 and ha_difflong[1] == 1 or ha_diffshort[1] == 2 and ha_difflong[3] == 2 and ha_difflong[1] == 1 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Bullish Trend Swapping Declined'

if ha_diffshort == 1 and ha_difflong[1] == 1 and ha_difflong == 2 or ha_diffshort == 1 and ha_difflong[2] == 1 and ha_difflong == 2
    trend := 'Bearish Trend Swapping'

if ha_diffshort[1] == 1 and ha_difflong[2] == 1 and ha_difflong[1] == 2 or ha_diffshort[1] == 1 and ha_difflong[3] == 1 and ha_difflong[1] == 2 and ha_diffshort == 1 and ha_difflong == 1
    trend := 'Bearish Trend Swapping Confirmed'

if ha_diffshort[1] == 1 and ha_difflong[2] == 1 and ha_difflong[1] == 2 or ha_diffshort[1] == 1 and ha_difflong[3] == 1 and ha_difflong[1] == 2 and ha_diffshort == 2 and ha_difflong == 2
    trend := 'Bearish Trend Swapping Declined'

trendcolor = color.rgb(224, 224, 224)

if ha_diffshort == 2 and ha_difflong == 2
    trendcolor := color.green

if ha_diffshort == 1 and ha_difflong == 1
    trendcolor := color.red

if trend == 'Double Up Declined' or trend == 'Bullish Continuation Declined' or trend == 'Bullish Break Declined' or trend == 'Bullish Trend Swapping Declined'
    trendcolor := color.red

if  trend == 'Double Down Declined' or trend == 'Bearish Continuation Declined' or trend == 'Bearish Break Declined' or trend == 'Bearish Trend Swapping Declined'
    trendcolor := color.green


if trend == 'Bullish Trend Swapping'
    trendcolor := color.green
if trend == 'Bearish Trend Swapping'
    trendcolor := color.red

//END OF PATTERN DETECTION ---------------------------------------------------------------------------------------------END OF PATTERN DETECTION//
//END OF PATTERN DETECTION ---------------------------------------------------------------------------------------------END OFPATTERN DETECTION//

//PATTERN WIN RATE CALCULATION -----------------------------------------------------------------------------------------PATTERN WIN RATE CALCULATION//
//PATTERN WIN RATE CALCULATION -----------------------------------------------------------------------------------------PATTERN WIN RATE CALCULATION//

currentConversion = 0.0
backtracknumber = 3
arrownumber = 2

DoubleUpSuccess = 0.0
DoubleUpFail = 0.0
if trend == 'Double Up'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Up'
            if close[i - arrownumber] < close[i]
                DoubleUpSuccess := DoubleUpSuccess + 1
            else
                DoubleUpFail := DoubleUpFail + 1

DoubleUpConversion = DoubleUpSuccess / (DoubleUpSuccess + DoubleUpFail)

DoubleUpConfirmedSuccess = 0.0
DoubleUpConfirmedFail = 0.0

if trend == 'Double Up Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Up Confirmed'
            if close[i - arrownumber] < close[i]
                DoubleUpConfirmedSuccess := DoubleUpConfirmedSuccess + 1
            else
                DoubleUpConfirmedFail := DoubleUpConfirmedFail + 1

DoubleUpConfirmedConversion = DoubleUpConfirmedSuccess / (DoubleUpConfirmedSuccess + DoubleUpConfirmedFail)

DoubleDownDeclinedSuccess = 0.0
DoubleDownDeclinedFail = 0.0

if trend == 'Double Down Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Down Declined'
            if close[i - arrownumber] < close[i]
                DoubleDownDeclinedSuccess := DoubleDownDeclinedSuccess + 1
            else
                DoubleDownDeclinedFail := DoubleDownDeclinedFail + 1

DoubleDownDeclinedConversion = DoubleDownDeclinedSuccess / (DoubleDownDeclinedSuccess + DoubleDownDeclinedFail)

BullishContinuationSuccess = 0.0
BullishContinuationFail = 0.0

if trend == 'Bullish Continuation'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Continuation'
            if close[i - arrownumber] < close[i]
                BullishContinuationSuccess := BullishContinuationSuccess + 1
            else
                BullishContinuationFail := BullishContinuationFail + 1

BullishContinuationConversion = BullishContinuationSuccess / (BullishContinuationSuccess + BullishContinuationFail)

BullishContinuationConfirmedSuccess = 0.0
BullishContinuationConfirmedFail = 0.0

if trend == 'Bullish Continuation Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Continuation Confirmed'
            if close[i - arrownumber] < close[i]
                BullishContinuationConfirmedSuccess := BullishContinuationConfirmedSuccess + 1
            else
                BullishContinuationConfirmedFail := BullishContinuationConfirmedFail + 1

BullishContinuationConfirmedConversion = BullishContinuationConfirmedSuccess / (BullishContinuationConfirmedSuccess + BullishContinuationConfirmedFail)

BearishContinuationDeclinedSuccess = 0.0
BearishContinuationDeclinedFail = 0.0

if trend == 'Bearish Continuation Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Continuation Declined'
            if close[i - arrownumber] < close[i]
                BearishContinuationDeclinedSuccess := BearishContinuationDeclinedSuccess + 1
            else
                BearishContinuationDeclinedFail := BearishContinuationDeclinedFail + 1

BearishContinuationDeclinedConversion = BearishContinuationDeclinedSuccess / (BearishContinuationDeclinedSuccess + BearishContinuationDeclinedFail)

BullishBreakSuccess = 0.0
BullishBreakFail = 0.0

if trend == 'Bullish Break'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Break'
            if close[i - arrownumber] < close[i]
                BullishBreakSuccess := BullishBreakSuccess + 1
            else
                BullishBreakFail := BullishBreakFail + 1

BullishBreakConversion = BullishBreakSuccess / (BullishBreakSuccess + BullishBreakFail)

BullishBreakConfirmedSuccess = 0.0
BullishBreakConfirmedFail = 0.0

if trend == 'Bullish Break Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Break Confirmed'
            if close[i - arrownumber] < close[i]
                BullishBreakConfirmedSuccess := BullishBreakConfirmedSuccess + 1
            else
                BullishBreakConfirmedFail := BullishBreakConfirmedFail + 1

BullishBreakConfirmedConversion = BullishBreakConfirmedSuccess / (BullishBreakConfirmedSuccess + BullishBreakConfirmedFail)

BearishBreakDeclinedSuccess = 0.0
BearishBreakDeclinedFail = 0.0

if trend == 'Bearish Break Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Break Declined'
            if close[i - arrownumber] < close[i]
                BearishBreakDeclinedSuccess := BearishBreakDeclinedSuccess + 1
            else
                BearishBreakDeclinedFail := BearishBreakDeclinedFail + 1

BearishBreakDeclinedConversion = BearishBreakDeclinedSuccess / (BearishBreakDeclinedSuccess + BearishBreakDeclinedFail)

BullishTrendSwappingSuccess = 0.0
BullishTrendSwappingFail = 0.0

if trend == 'Bullish Trend Swapping'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Trend Swapping'
            if close[i - arrownumber] < close[i]
                BullishTrendSwappingSuccess := BullishTrendSwappingSuccess + 1
            else
                BullishTrendSwappingFail := BullishTrendSwappingFail + 1

BullishTrendSwappingConversion = BullishTrendSwappingSuccess / (BullishTrendSwappingSuccess + BullishTrendSwappingFail)

BullishTrendSwappingConfirmedSuccess = 0.0
BullishTrendSwappingConfirmedFail = 0.0

if trend == 'Bullish Trend Swapping Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Trend Swapping Confirmed'
            if close[i - arrownumber] < close[i]
                BullishTrendSwappingConfirmedSuccess := BullishTrendSwappingConfirmedSuccess + 1
            else
                BullishTrendSwappingConfirmedFail := BullishTrendSwappingConfirmedFail + 1

BullishTrendSwappingConfirmedConversion = BullishTrendSwappingConfirmedSuccess / (BullishTrendSwappingConfirmedSuccess + BullishTrendSwappingConfirmedFail)

BearishTrendSwappingDeclinedSuccess = 0.0
BearishTrendSwappingDeclinedFail = 0.0

if trend == 'Bearish Trend Swapping Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Trend Swapping Declined'
            if close[i - arrownumber] < close[i]
                BearishTrendSwappingDeclinedSuccess := BearishTrendSwappingDeclinedSuccess + 1
            else
                BearishTrendSwappingDeclinedFail := BearishTrendSwappingDeclinedFail + 1

BearishTrendSwappingDeclinedConversion = BearishTrendSwappingDeclinedSuccess / (BearishTrendSwappingDeclinedSuccess + BearishTrendSwappingDeclinedFail)

DoubleDownSuccess = 0.0
DoubleDownFail = 0.0

if trend == 'Double Down'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Down'
            if close[i - arrownumber] > close[i]
                DoubleDownSuccess := DoubleDownSuccess + 1
            else
                DoubleDownFail := DoubleDownFail + 1

DoubleDownConversion = DoubleDownSuccess / (DoubleDownSuccess + DoubleDownFail)

DoubleUpDeclinedSuccess = 0.0
DoubleUpDeclinedFail = 0.0

if trend == 'Double Up Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Up Declined'
            if close[i - arrownumber] < close[i]
                DoubleUpDeclinedSuccess := DoubleUpDeclinedSuccess + 1
            else
                DoubleUpDeclinedFail := DoubleUpDeclinedFail + 1

DoubleUpDeclinedConversion = DoubleUpDeclinedSuccess / (DoubleUpDeclinedSuccess + DoubleUpDeclinedFail)

DoubleDownConfirmedSuccess = 0.0
DoubleDownConfirmedFail = 0.0

if trend == 'Double Down Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Double Down Confirmed'
            if close[i - arrownumber] > close[i]
                DoubleDownConfirmedSuccess := DoubleDownConfirmedSuccess + 1
            else
                DoubleDownConfirmedFail := DoubleDownConfirmedFail + 1

DoubleDownConfirmedConversion = DoubleDownConfirmedSuccess / (DoubleDownConfirmedSuccess + DoubleDownConfirmedFail)

BearishContinuationSuccess = 0.0
BearishContinuationFail = 0.0

if trend == 'Bearish Continuation'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Continuation'
            if close[i - arrownumber] > close[i]
                BearishContinuationSuccess := BearishContinuationSuccess + 1
            else
                BearishContinuationFail := BearishContinuationFail + 1

BearishContinuationConversion = BearishContinuationSuccess / (BearishContinuationSuccess + BearishContinuationFail)

BearishContinuationConfirmedSuccess = 0.0
BearishContinuationConfirmedFail = 0.0

if trend == 'Bearish Continuation Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Continuation Confirmed'
            if close[i - arrownumber] > close[i]
                BearishContinuationConfirmedSuccess := BearishContinuationConfirmedSuccess + 1
            else
                BearishContinuationConfirmedFail := BearishContinuationConfirmedFail + 1

BearishContinuationConfirmedConversion = BearishContinuationConfirmedSuccess / (BearishContinuationConfirmedSuccess + BearishContinuationConfirmedFail)

BullishContinuationDeclinedSuccess = 0.0
BullishContinuationDeclinedFail = 0.0

if trend == 'Bullish Continuation Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Continuation Declined'
            if close[i - arrownumber] > close[i]
                BullishContinuationDeclinedSuccess := BullishContinuationDeclinedSuccess + 1
            else
                BullishContinuationDeclinedFail := BullishContinuationDeclinedFail + 1

BullishContinuationDeclinedConversion = BullishContinuationDeclinedSuccess / (BullishContinuationDeclinedSuccess + BullishContinuationDeclinedFail)

BearishBreakSuccess = 0.0
BearishBreakFail = 0.0

if trend == 'Bearish Break'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Break'
            if close[i - arrownumber] > close[i]
                BearishBreakSuccess := BearishBreakSuccess + 1
            else
                BearishBreakFail := BearishBreakFail + 1

BearishBreakConversion = BearishBreakSuccess / (BearishBreakSuccess + BearishBreakFail)

BearishBreakConfirmedSuccess = 0.0
BearishBreakConfirmedFail = 0.0

if trend == 'Bearish Break Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Break Confirmed'
            if close[i - arrownumber] > close[i]
                BearishBreakConfirmedSuccess := BearishBreakConfirmedSuccess + 1
            else
                BearishBreakConfirmedFail := BearishBreakConfirmedFail + 1

BearishBreakConfirmedConversion = BearishBreakConfirmedSuccess / (BearishBreakConfirmedSuccess + BearishBreakConfirmedFail)

BullishBreakDeclinedSuccess = 0.0
BullishBreakDeclinedFail = 0.0

if trend == 'Bullish Break Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Break Declined'
            if close[i - arrownumber] > close[i]
                BullishBreakDeclinedSuccess := BullishBreakDeclinedSuccess + 1
            else
                BullishBreakDeclinedFail := BullishBreakDeclinedFail + 1

BullishBreakDeclinedConversion = BullishBreakDeclinedSuccess / (BullishBreakDeclinedSuccess + BullishBreakDeclinedFail)

BearishTrendSwappingSuccess = 0.0
BearishTrendSwappingFail = 0.0

if trend == 'Bearish Trend Swapping'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Trend Swapping'
            if close[i - arrownumber] > close[i]
                BearishTrendSwappingSuccess := BearishTrendSwappingSuccess + 1
            else
                BearishTrendSwappingFail := BearishTrendSwappingFail + 1

BearishTrendSwappingConversion = BearishTrendSwappingSuccess / (BearishTrendSwappingSuccess + BearishTrendSwappingFail)

BearishTrendSwappingConfirmedSuccess = 0.0
BearishTrendSwappingConfirmedFail = 0.0

if trend == 'Bearish Trend Swapping Confirmed'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish Trend Swapping Confirmed'
            if close[i - arrownumber] > close[i]
                BearishTrendSwappingConfirmedSuccess := BearishTrendSwappingConfirmedSuccess + 1
            else
                BearishTrendSwappingConfirmedFail := BearishTrendSwappingConfirmedFail + 1

BearishTrendSwappingConfirmedConversion = BearishTrendSwappingConfirmedSuccess / (BearishTrendSwappingConfirmedSuccess + BearishTrendSwappingConfirmedFail)

BullishTrendSwappingDeclinedSuccess = 0.0
BullishTrendSwappingDeclinedFail = 0.0

if trend == 'Bullish Trend Swapping Declined'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish Trend Swapping Declined'
            if close[i - arrownumber] > close[i]
                BullishTrendSwappingDeclinedSuccess := BullishTrendSwappingDeclinedSuccess + 1
            else
                BullishTrendSwappingDeclinedFail := BullishTrendSwappingDeclinedFail + 1

BullishTrendSwappingDeclinedConversion = BullishTrendSwappingDeclinedSuccess / (BullishTrendSwappingDeclinedSuccess + BullishTrendSwappingDeclinedFail)

BullishSuccess = 0.0
BullishFail = 0.0

if trend == 'Bullish'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bullish'
            if close[i - arrownumber] > close[i]
                BullishSuccess := BullishSuccess + 1
            else
                BullishFail := BullishFail + 1

BullishConversion = BullishSuccess / (BullishSuccess + BullishFail)

BearishSuccess = 0.0
BearishFail = 0.0

if trend == 'Bearish'
    for i = arrownumber to backtracknumber
        if trend[i] == 'Bearish'
            if close[i - arrownumber] > close[i]
                BearishSuccess := BearishSuccess + 1
            else
                BearishFail := BearishFail + 1

BearishConversion = BearishSuccess / (BearishSuccess + BearishFail)

if trend == "Double Up"
    currentConversion := DoubleUpConversion
if trend == "Double Up Confirmed"
    currentConversion := DoubleUpConfirmedConversion
if trend == "Double Up Declined"
    currentConversion := DoubleUpDeclinedConversion
if trend == "Double Down"
    currentConversion := DoubleDownConversion
if trend == "Double Down Confirmed"
    currentConversion := DoubleDownConfirmedConversion
if trend == "Double Down Declined"
    currentConversion := DoubleDownDeclinedConversion
if trend == "Bullish Continuation"
    currentConversion := BullishContinuationConversion
if trend == "Bullish Continuation Confirmed"
    currentConversion := BullishContinuationConfirmedConversion
if trend == "Bullish Continuation Declined"
    currentConversion := BullishContinuationDeclinedConversion
if trend == "Bearish Continuation"
    currentConversion := BearishContinuationConversion
if trend == "Bearish Continuation Confirmed"
    currentConversion := BearishContinuationConfirmedConversion
if trend == "Bearish Continuation Declined"
    currentConversion := BearishContinuationDeclinedConversion
if trend == "Bullish Break"
    currentConversion := BullishBreakConversion
if trend == "Bullish Break Confirmed"
    currentConversion := BullishBreakConfirmedConversion
if trend == "Bullish Break Declined"
    currentConversion := BullishBreakDeclinedConversion
if trend == "Bearish Break"
    currentConversion := BearishBreakConversion
if trend == "Bearish Break Confirmed"
    currentConversion := BearishBreakConfirmedConversion
if trend == "Bearish Break Declined"
    currentConversion := BearishBreakDeclinedConversion
if trend == "Bullish Trend Swapping"
    currentConversion := BullishTrendSwappingConversion
if trend == "Bullish Trend Swapping Confirmed"
    currentConversion := BullishBreakConfirmedConversion
if trend == "Bullish Trend Swapping Declined"
    currentConversion := BullishBreakDeclinedConversion
if trend == "Bearish Trend Swapping"
    currentConversion := BearishTrendSwappingConversion
if trend == "Bearish Trend Swapping Confirmed"
    currentConversion := BearishBreakConfirmedConversion
if trend == "Bearish Trend Swapping Declined"
    currentConversion := BearishBreakDeclinedConversion
if trend == "Bullish"
    currentConversion := BullishConversion
if trend == "Bearish"
    currentConversion := BearishConversion

patterwinrate = (currentConversion * 1.5) * 100


//WILLIAMS ALLIGATOR CALCULATIONS --------------------------------------------------------------------------------------WILLIAMS ALLIGATOR CALCULATIONS//
//WILLIAMS ALLIGATOR CALCULATIONS --------------------------------------------------------------------------------------WILLIAMS ALLIGATOR CALCULATIONS//


smma(src, length) =>
    smma =  0.0
    smma := na(smma[1]) ? ta.sma(src, length) : (smma[1] * (length - 1) + src) / length
    smma
jawLength = 13
teethLength = 8
lipsLength = 5
jawOffset = 8
teethOffset = 5
lipsOffset = 3
jaw = smma(request.security(syminfo.tickerid, '15', hl2), jawLength)
teeth = smma(request.security(syminfo.tickerid, '15', hl2), teethLength)
lips = smma(request.security(syminfo.tickerid, '15', hl2), lipsLength)

williamsalligator = " Williams Alligator is Mixed"
if lips > teeth and lips > jaw and jaw < teeth
    williamsalligator := "Williams Alligator is Bullish ↑"
if lips < teeth and lips < jaw and jaw > teeth
    williamsalligator := "Williams Alligator is Bearish ↓"

//END OF WILLIAMS ALLIGATOR CALCULATIONS -------------------------------------------------------------------------------END OF WILLIAMS ALLIGATOR CALCULATIONS//
//END OF WILLIAMS ALLIGATOR CALCULATIONS --------------------------------------------------------------------------------END OF WILLIAMS ALLIGATOR CALCULATIONS//


////QUALITY CALCULATION ------------------------------------------------------------------------------------------------//QUALITY CALCULATION//
////QUALITY CALCULATION ------------------------------------------------------------------------------------------------//QUALITY CALCULATION//

fifteenclose200 = (request.security(syminfo.tickerid, timeframes, ta.sma(request.security(syminfo.tickerid, timeframes, close), 200)))
fifteenclose50 = (request.security(syminfo.tickerid, timeframes, ta.sma(request.security(syminfo.tickerid, timeframes, close), 50)))
fifteenclose9 = (request.security(syminfo.tickerid, timeframes, ta.sma(request.security(syminfo.tickerid, timeframes, close), 9)))

purequality = (((math.abs(close - fifteenclose200) * 8) + (math.abs(close - fifteenclose50) * 4) + (math.abs(close - fifteenclose9) * 2)))

currentquality = purequality[0]
rankedquality = 1
for i = 1 to 10
    if purequality[i] > currentquality
        rankedquality := rankedquality + 1

quality = ((rankedquality - 1) * 100) / 1000

//END OF QUALITY CALCULATION -------------------------------------------------------------------------------------------//END OF QUALITY CALCULATION//
//END OF QUALITY CALCULATION -------------------------------------------------------------------------------------------//END OF QUALITY CALCULATION//

//CHANDLIERS EXIT CALCULATION ------------------------------------------------------------------------------------------//CHANDLIERS EXIT CALCULATION//
//CHANDLIERS EXIT CALCULATION ------------------------------------------------------------------------------------------//CHANDLIERS EXIT CALCULATION//

lengthce = 4
multce = 2.0
showLabels = true
useClose = true
highlightState = true

atr = multce * ta.atr(lengthce)

longStop = (useClose ? ta.highest(close, lengthce) : ta.highest(lengthce)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop

shortStop = (useClose ? ta.lowest(close, lengthce) : ta.lowest(lengthce)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

//END OF CHANDLIERS EXIT CALCULATION -----------------------------------------------------------------------------------//END OF CHANDLIERS EXIT CALCULATION//
//END OF CHANDLIERS EXIT CALCULATION -----------------------------------------------------------------------------------//END OF CHANDLIERS EXIT CALCULATION//


//CUSTOM MACD CALCULATION ----------------------------------------------------------------------------------------------//CUSTOM MACD CALCULATION//
//CUSTOM MACD CALCULATION ----------------------------------------------------------------------------------------------//CUSTOM MACD CALCULATION//


[macd, signal, histo] = ta.macd(close, 12, 26, 9)

bigtime = ''
mediumtime = ''
smalltime = ''

if histo > 0
    bigtime := '⬆'
if histo < 0
    bigtime := '⬇'

[macdm, signalm, histom] = request.security(syminfo.tickerid, '15', ta.macd(close, 12, 26, 9))

if histom > 0
    mediumtime := '⬆'
if histom < 0
    mediumtime := '⬇'


[macds, signals, histos] = request.security(syminfo.tickerid, '5', ta.macd(close, 12, 26, 9))

if histos > 0
    smalltime := '⬆'
if histos < 0
    smalltime := '⬇'

//END OF CUSTOM MACD CALCULATION ---------------------------------------------------------------------------------------//END OF CUSTOM MACD CALCULATION//
//END OF CUSTOM MACD CALCULATION ---------------------------------------------------------------------------------------//END OF CUSTOM MACD CALCULATION//

//CUSTOM MFI CALCULATION -----------------------------------------------------------------------------------------------//CUSTOM MFI CALCULATION//
//CUSTOM MFI CALCULATION -----------------------------------------------------------------------------------------------//CUSTOM MFI CALCULATION//

five_minute_MFI = request.security(syminfo.tickerid, '5', ta.mfi(hlc3, 14))
fifteen_minute_MFI = request.security(syminfo.tickerid, '5', ta.mfi(hlc3, 14))
one_hour_MFI = request.security(syminfo.tickerid, '60', ta.mfi(hlc3, 14))

if five_minute_MFI > 80
    smalltime := '⬇'
if five_minute_MFI < 20
    smalltime := '⬆'

if fifteen_minute_MFI > 80
    mediumtime := '⬇'
if fifteen_minute_MFI < 20
    mediumtime := '⬆'

if one_hour_MFI > 80
    bigtime := '⬇'
if one_hour_MFI < 20
    bigtime := '⬆'


//END OF CUSTOM MFI CALCULATION ----------------------------------------------------------------------------------------//END OF CUSTOM MFI CALCULATION//
//END OF CUSTOM MFI CALCULATION ----------------------------------------------------------------------------------------//END OF CUSTOM MFI CALCULATION//

//TRUE AREA CALCULATION -----------------------------------------------------------------------------------------------//TRUE AREA CALCULATION//
//TRUE AREA CALCULATION -----------------------------------------------------------------------------------------------//TRUE AREA CALCULATION//


MACDTRADEBUY = smalltime == '⬆' and bigtime == '⬆' and mediumtime == '⬆' and (useMACD)
MACDTRADESELL = smalltime == '⬇' and bigtime == '⬇' and mediumtime == '⬇' and (useMACD)

fourhourHeikinAshibuy = ha_diff240 == 2 and (useLongHeikinAshi)
fourhourHeikinAshisell = ha_diff240 == 1 and (useLongHeikinAshi)

WilliamsAlligatorBuy = williamsalligator == "Williams Alligator is Bullish ↑" and (useWilliamAlligator)
WilliamsAlligatorSell = williamsalligator == "Williams Alligator is Bearish ↓" and (useWilliamAlligator)

ChandelierBuy = dir == 1 and (useChandelierExit)
ChandelierSell = dir == -1 and (useChandelierExit)

onehourHeikinAshiBuy = ha_diff60 == 2 and (useShortHeikinAshi)
onehourHeikinAshiSell = ha_diff60 == 1 and (useShortHeikinAshi)

MFIbuy = ta.mfi(close, 14)[2] <= 30 and (useMFI)
MFIsell = ta.mfi(close, 14)[2] >= 70 and (useMFI)

buyarea = 0.0
sellarea = 0.0

for i = 0 to areanumber
    if fourhourHeikinAshibuy[i]
        buyarea += 1
    if fourhourHeikinAshisell[i]
        sellarea += 1
    if WilliamsAlligatorBuy[i]
        buyarea += 1
    if WilliamsAlligatorSell[i]
        sellarea += 1 
    if ChandelierBuy[i]
        buyarea += 1 
    if ChandelierSell[i]
        sellarea += 1
    if onehourHeikinAshiBuy[i]
        buyarea += 1
    if onehourHeikinAshiSell[i]
        sellarea += 1
    if MFIbuy[i]
        buyarea += 1 
    if MFIsell[i]
        sellarea += 1
    if MACDTRADEBUY[i]
        buyarea += 1 
    if MACDTRADESELL[i]
        sellarea += 1

truearea = (buyarea / ((areanumber + 1) * 6)) * 100
areatrend = '↑↑↑'

if sellarea > buyarea
    truearea := (sellarea / ((areanumber + 1) * 6)) * 100
    areatrend := '↓↓↓'


//END OF TRUE AREA CALCULATION -----------------------------------------------------------------------------------------//END OF TRUE AREA CALCULATION//
//END OF TRUE AREA CALCULATION -----------------------------------------------------------------------------------------//END OF TRUE AREA CALCULATION//


//TREND AREA BAR -------------------------------------------------------------------------------------------------------//TREND AREA BAR//
//TREND AREA BAR -------------------------------------------------------------------------------------------------------//TREND AREA BAR//

BUY = buyarea > sellarea
SELL = buyarea < sellarea

if bias == "Bullish"
    BUY := true
    SELL := false
if bias == "Bearish"
    SELL := true
    BUY := false



barinnercolor_trueareabar = color.gray
if buyarea > sellarea
    barinnercolor_trueareabar := color.rgb(76, 175, 79, 20)
if buyarea < sellarea
    barinnercolor_trueareabar := color.rgb(255, 82, 82, 20)

baroutercolor_trueareabar = color.gray
if buyarea > sellarea
    baroutercolor_trueareabar := color.green
if buyarea < sellarea
    baroutercolor_trueareabar := color.red

defaultcolor = color.rgb(255, 255, 255, 100)

trueareacolor1 = defaultcolor
trueareacolor2 = defaultcolor
trueareacolor3 = defaultcolor
trueareacolor4 = defaultcolor
trueareacolor5 = defaultcolor
trueareacolor6 = defaultcolor
trueareacolor7 = defaultcolor
trueareacolor8 = defaultcolor
trueareacolor9 = defaultcolor
trueareacolor10 = defaultcolor

trueareacolor11 = defaultcolor
trueareacolor12 = defaultcolor
trueareacolor13 = defaultcolor
trueareacolor14 = defaultcolor
trueareacolor15 = defaultcolor
trueareacolor16 = defaultcolor
trueareacolor17 = defaultcolor
trueareacolor18 = defaultcolor
trueareacolor19 = defaultcolor
trueareacolor20 = defaultcolor

trueareacolor21 = defaultcolor
trueareacolor22 = defaultcolor
trueareacolor23 = defaultcolor
trueareacolor24 = defaultcolor
trueareacolor25 = defaultcolor
trueareacolor26 = defaultcolor
trueareacolor27 = defaultcolor
trueareacolor28 = defaultcolor
trueareacolor29 = defaultcolor
trueareacolor30 = defaultcolor

trueareacolor31 = defaultcolor
trueareacolor32 = defaultcolor
trueareacolor33 = defaultcolor
trueareacolor34 = defaultcolor
trueareacolor35 = defaultcolor
trueareacolor36 = defaultcolor
trueareacolor37 = defaultcolor
trueareacolor38 = defaultcolor
trueareacolor39 = defaultcolor
trueareacolor40 = defaultcolor

trueareacolor41 = defaultcolor
trueareacolor42 = defaultcolor
trueareacolor43 = defaultcolor
trueareacolor44 = defaultcolor
trueareacolor45 = defaultcolor
trueareacolor46 = defaultcolor
trueareacolor47 = defaultcolor
trueareacolor48 = defaultcolor
trueareacolor49 = defaultcolor
trueareacolor50 = defaultcolor

trueareacolor51 = defaultcolor
trueareacolor52 = defaultcolor
trueareacolor53 = defaultcolor
trueareacolor54 = defaultcolor
trueareacolor55 = defaultcolor
trueareacolor56 = defaultcolor
trueareacolor57 = defaultcolor
trueareacolor58 = defaultcolor
trueareacolor59 = defaultcolor
trueareacolor60 = defaultcolor

trueareacolor61 = defaultcolor
trueareacolor62 = defaultcolor
trueareacolor63 = defaultcolor
trueareacolor64 = defaultcolor
trueareacolor65 = defaultcolor
trueareacolor66 = defaultcolor
trueareacolor67 = defaultcolor
trueareacolor68 = defaultcolor
trueareacolor69 = defaultcolor
trueareacolor70 = defaultcolor

trueareacolor71 = defaultcolor
trueareacolor72 = defaultcolor
trueareacolor73 = defaultcolor
trueareacolor74 = defaultcolor
trueareacolor75 = defaultcolor
trueareacolor76 = defaultcolor
trueareacolor77 = defaultcolor
trueareacolor78 = defaultcolor
trueareacolor79 = defaultcolor
trueareacolor80 = defaultcolor

trueareacolor81 = defaultcolor
trueareacolor82 = defaultcolor
trueareacolor83 = defaultcolor
trueareacolor84 = defaultcolor
trueareacolor85 = defaultcolor
trueareacolor86 = defaultcolor
trueareacolor87 = defaultcolor
trueareacolor88 = defaultcolor
trueareacolor89 = defaultcolor
trueareacolor90 = defaultcolor

trueareacolor91 = defaultcolor
trueareacolor92 = defaultcolor
trueareacolor93 = defaultcolor
trueareacolor94 = defaultcolor
trueareacolor95 = defaultcolor
trueareacolor96 = defaultcolor
trueareacolor97 = defaultcolor
trueareacolor98 = defaultcolor
trueareacolor99 = defaultcolor

if truearea > 0
    trueareacolor1 := barinnercolor_trueareabar
if truearea > 1
    trueareacolor2 := barinnercolor_trueareabar
if truearea > 2
    trueareacolor3 := barinnercolor_trueareabar
if truearea > 3
    trueareacolor4 := barinnercolor_trueareabar
if truearea > 4
    trueareacolor5 := barinnercolor_trueareabar
if truearea > 5
    trueareacolor6 := barinnercolor_trueareabar
if truearea > 6
    trueareacolor7 := barinnercolor_trueareabar
if truearea > 7
    trueareacolor8 := barinnercolor_trueareabar
if truearea > 8
    trueareacolor9 := barinnercolor_trueareabar
if truearea > 9
    trueareacolor10 := barinnercolor_trueareabar
if truearea > 10
    trueareacolor11 := barinnercolor_trueareabar
if truearea > 11
    trueareacolor12 := barinnercolor_trueareabar
if truearea > 12
    trueareacolor13 := barinnercolor_trueareabar
if truearea > 13
    trueareacolor14 := barinnercolor_trueareabar
if truearea > 14
    trueareacolor15 := barinnercolor_trueareabar
if truearea > 15
    trueareacolor16 := barinnercolor_trueareabar
if truearea > 16
    trueareacolor17 := barinnercolor_trueareabar
if truearea > 17
    trueareacolor18 := barinnercolor_trueareabar
if truearea > 18
    trueareacolor19 := barinnercolor_trueareabar
if truearea > 19
    trueareacolor20 := barinnercolor_trueareabar
if truearea > 20
    trueareacolor21 := barinnercolor_trueareabar
if truearea > 21
    trueareacolor22 := barinnercolor_trueareabar
if truearea > 22
    trueareacolor23 := barinnercolor_trueareabar
if truearea > 23
    trueareacolor24 := barinnercolor_trueareabar
if truearea > 24
    trueareacolor25 := barinnercolor_trueareabar
if truearea > 25
    trueareacolor26 := barinnercolor_trueareabar
if truearea > 26
    trueareacolor27 := barinnercolor_trueareabar
if truearea > 27
    trueareacolor28 := barinnercolor_trueareabar
if truearea > 28
    trueareacolor29 := barinnercolor_trueareabar
if truearea > 29
    trueareacolor30 := barinnercolor_trueareabar
if truearea > 30
    trueareacolor31 := barinnercolor_trueareabar
if truearea > 31
    trueareacolor32 := barinnercolor_trueareabar
if truearea > 32
    trueareacolor33 := barinnercolor_trueareabar
if truearea > 33
    trueareacolor34 := barinnercolor_trueareabar
if truearea > 34
    trueareacolor35 := barinnercolor_trueareabar
if truearea > 35
    trueareacolor36 := barinnercolor_trueareabar
if truearea > 36
    trueareacolor37 := barinnercolor_trueareabar
if truearea > 37
    trueareacolor38 := barinnercolor_trueareabar
if truearea > 38
    trueareacolor39 := barinnercolor_trueareabar
if truearea > 39
    trueareacolor40 := barinnercolor_trueareabar
if truearea > 40
    trueareacolor41 := barinnercolor_trueareabar
if truearea > 41
    trueareacolor42 := barinnercolor_trueareabar
if truearea > 42
    trueareacolor43 := barinnercolor_trueareabar
if truearea > 43
    trueareacolor44 := barinnercolor_trueareabar
if truearea > 44
    trueareacolor45 := barinnercolor_trueareabar
if truearea > 45
    trueareacolor46 := barinnercolor_trueareabar
if truearea > 46
    trueareacolor47 := barinnercolor_trueareabar
if truearea > 47
    trueareacolor48 := barinnercolor_trueareabar
if truearea > 48
    trueareacolor49 := barinnercolor_trueareabar
if truearea > 49
    trueareacolor50 := barinnercolor_trueareabar
if truearea > 50
    trueareacolor51 := barinnercolor_trueareabar
if truearea > 51
    trueareacolor52 := barinnercolor_trueareabar
if truearea > 52
    trueareacolor53 := barinnercolor_trueareabar
if truearea > 53
    trueareacolor54 := barinnercolor_trueareabar
if truearea > 54
    trueareacolor54 := barinnercolor_trueareabar
if truearea > 54
    trueareacolor55 := barinnercolor_trueareabar
if truearea > 55
    trueareacolor56 := barinnercolor_trueareabar
if truearea > 56
    trueareacolor57 := barinnercolor_trueareabar
if truearea > 57
    trueareacolor58 := barinnercolor_trueareabar
if truearea > 58
    trueareacolor59 := barinnercolor_trueareabar
if truearea > 59
    trueareacolor60 := barinnercolor_trueareabar
if truearea > 60
    trueareacolor61 := barinnercolor_trueareabar
if truearea > 61
    trueareacolor62 := barinnercolor_trueareabar
if truearea > 62
    trueareacolor63 := barinnercolor_trueareabar
if truearea > 63
    trueareacolor64 := barinnercolor_trueareabar
if truearea > 64
    trueareacolor65 := barinnercolor_trueareabar
if truearea > 65
    trueareacolor66 := barinnercolor_trueareabar
if truearea > 66
    trueareacolor67 := barinnercolor_trueareabar
if truearea > 67
    trueareacolor68 := barinnercolor_trueareabar
if truearea > 68
    trueareacolor69 := barinnercolor_trueareabar
if truearea > 69
    trueareacolor70 := barinnercolor_trueareabar
if truearea > 70
    trueareacolor71 := barinnercolor_trueareabar
if truearea > 71
    trueareacolor72 := barinnercolor_trueareabar
if truearea > 72
    trueareacolor73 := barinnercolor_trueareabar
if truearea > 73
    trueareacolor74 := barinnercolor_trueareabar
if truearea > 74
    trueareacolor75 := barinnercolor_trueareabar
if truearea > 75
    trueareacolor76 := barinnercolor_trueareabar
if truearea > 76
    trueareacolor77 := barinnercolor_trueareabar
if truearea > 77
    trueareacolor78 := barinnercolor_trueareabar
if truearea > 78
    trueareacolor79 := barinnercolor_trueareabar
if truearea > 79
    trueareacolor80 := barinnercolor_trueareabar
if truearea > 80
    trueareacolor81 := barinnercolor_trueareabar
if truearea > 81
    trueareacolor82 := barinnercolor_trueareabar
if truearea > 82
    trueareacolor83 := barinnercolor_trueareabar
if truearea > 83
    trueareacolor84 := barinnercolor_trueareabar
if truearea > 84
    trueareacolor85 := barinnercolor_trueareabar
if truearea > 85
    trueareacolor86 := barinnercolor_trueareabar
if truearea > 86
    trueareacolor87 := barinnercolor_trueareabar
if truearea > 87
    trueareacolor88 := barinnercolor_trueareabar
if truearea > 88
    trueareacolor89 := barinnercolor_trueareabar
if truearea > 89
    trueareacolor90 := barinnercolor_trueareabar
if truearea > 90
    trueareacolor91 := barinnercolor_trueareabar
if truearea > 91
    trueareacolor92 := barinnercolor_trueareabar
if truearea > 92
    trueareacolor93 := barinnercolor_trueareabar
if truearea > 93
    trueareacolor94 := barinnercolor_trueareabar
if truearea > 94
    trueareacolor95 := barinnercolor_trueareabar
if truearea > 95
    trueareacolor96 := barinnercolor_trueareabar
if truearea > 96
    trueareacolor97 := barinnercolor_trueareabar
if truearea > 97
    trueareacolor98 := barinnercolor_trueareabar
if truearea > 98
    trueareacolor99 := barinnercolor_trueareabar

var trueareatable = table.new(position.top_center, 101, 2, border_width = 0, border_color = baroutercolor_trueareabar, frame_color = baroutercolor_trueareabar, frame_width = 3)
hi = 5
why = 0.5

if device == "Computer"
    table.cell(trueareatable, 20, 0, ' ', bgcolor=trueareacolor20, height=hi, width=why)
    table.cell(trueareatable, 21, 0, ' ', bgcolor=trueareacolor21, height=hi, width=why)
    table.cell(trueareatable, 22, 0, ' ', bgcolor=trueareacolor22, height=hi, width=why)
    table.cell(trueareatable, 22, 0, ' ', bgcolor=trueareacolor22, height=hi, width=why)
    table.cell(trueareatable, 24, 0, ' ', bgcolor=trueareacolor24, height=hi, width=why)
    table.cell(trueareatable, 25, 0, ' ', bgcolor=trueareacolor25, height=hi, width=why)
    table.cell(trueareatable, 26, 0, ' ', bgcolor=trueareacolor26, height=hi, width=why)
    table.cell(trueareatable, 27, 0, ' ', bgcolor=trueareacolor27, height=hi, width=why)
    table.cell(trueareatable, 28, 0, ' ', bgcolor=trueareacolor28, height=hi, width=why)
    table.cell(trueareatable, 29, 0, ' ', bgcolor=trueareacolor29, height=hi, width=why)
    table.cell(trueareatable, 30, 0, ' ', bgcolor=trueareacolor40, height=hi, width=why)
    table.cell(trueareatable, 30, 0, ' ', bgcolor=trueareacolor30, height=hi, width=why)
    table.cell(trueareatable, 31, 0, ' ', bgcolor=trueareacolor31, height=hi, width=why)
    table.cell(trueareatable, 32, 0, ' ', bgcolor=trueareacolor32, height=hi, width=why)
    table.cell(trueareatable, 33, 0, ' ', bgcolor=trueareacolor33, height=hi, width=why)
    table.cell(trueareatable, 34, 0, ' ', bgcolor=trueareacolor34, height=hi, width=why)
    table.cell(trueareatable, 35, 0, ' ', bgcolor=trueareacolor35, height=hi, width=why)
    table.cell(trueareatable, 36, 0, ' ', bgcolor=trueareacolor36, height=hi, width=why)
    table.cell(trueareatable, 37, 0, ' ', bgcolor=trueareacolor37, height=hi, width=why)
    table.cell(trueareatable, 38, 0, ' ', bgcolor=trueareacolor38, height=hi, width=why)
    table.cell(trueareatable, 39, 0, ' ', bgcolor=trueareacolor39, height=hi, width=why)
    table.cell(trueareatable, 40, 0, ' ', bgcolor=trueareacolor40, height=hi, width=why)
    table.cell(trueareatable, 41, 0, ' ', bgcolor=trueareacolor41, height=hi, width=why)
    table.cell(trueareatable, 42, 0, ' ', bgcolor=trueareacolor42, height=hi, width=why)
    table.cell(trueareatable, 43, 0, ' ', bgcolor=trueareacolor43, height=hi, width=why)
    table.cell(trueareatable, 44, 0, ' ', bgcolor=trueareacolor44, height=hi, width=why)
    table.cell(trueareatable, 45, 0, ' ', bgcolor=trueareacolor45, height=hi, width=why)
    table.cell(trueareatable, 46, 0, ' ', bgcolor=trueareacolor46, height=hi, width=why)
    table.cell(trueareatable, 47, 0, ' ', bgcolor=trueareacolor47, height=hi, width=why)
    table.cell(trueareatable, 48, 0, ' ', bgcolor=trueareacolor48, height=hi, width=why)
    table.cell(trueareatable, 49, 0, ' ', bgcolor=trueareacolor49, height=hi, width=why)
    table.cell(trueareatable, 50, 0, ' ', bgcolor=trueareacolor50, height=hi, width=why)
    table.cell(trueareatable, 51, 0, ' ', bgcolor=trueareacolor51, height=hi, width=why)
    table.cell(trueareatable, 52, 0, ' ', bgcolor=trueareacolor52, height=hi, width=why)
    table.cell(trueareatable, 53, 0, ' ', bgcolor=trueareacolor53, height=hi, width=why)
    table.cell(trueareatable, 54, 0, ' ', bgcolor=trueareacolor54, height=hi, width=why)
    table.cell(trueareatable, 55, 0, ' ', bgcolor=trueareacolor55, height=hi, width=why)
    table.cell(trueareatable, 56, 0, ' ', bgcolor=trueareacolor56, height=hi, width=why)
    table.cell(trueareatable, 57, 0, ' ', bgcolor=trueareacolor57, height=hi, width=why)
    table.cell(trueareatable, 58, 0, ' ', bgcolor=trueareacolor58, height=hi, width=why)
    table.cell(trueareatable, 59, 0, ' ', bgcolor=trueareacolor59, height=hi, width=why)
    table.cell(trueareatable, 60, 0, str.tostring(truearea, "#") + ' %', bgcolor=trueareacolor60, height=hi, width=why, text_color = color.white)
    table.cell(trueareatable, 61, 0, ' ', bgcolor=trueareacolor61, height=hi, width=why)
    table.cell(trueareatable, 62, 0, ' ', bgcolor=trueareacolor62, height=hi, width=why)
    table.cell(trueareatable, 63, 0, ' ', bgcolor=trueareacolor63, height=hi, width=why)
    table.cell(trueareatable, 64, 0, ' ', bgcolor=trueareacolor64, height=hi, width=why)
    table.cell(trueareatable, 65, 0, ' ', bgcolor=trueareacolor65, height=hi, width=why)
    table.cell(trueareatable, 66, 0, ' ', bgcolor=trueareacolor66, height=hi, width=why)
    table.cell(trueareatable, 67, 0, ' ', bgcolor=trueareacolor67, height=hi, width=why)
    table.cell(trueareatable, 68, 0, ' ', bgcolor=trueareacolor68, height=hi, width=why)
    table.cell(trueareatable, 69, 0, ' ', bgcolor=trueareacolor69, height=hi, width=why)
    table.cell(trueareatable, 70, 0, ' ', bgcolor=trueareacolor70, height=hi, width=why)
    table.cell(trueareatable, 71, 0, ' ', bgcolor=trueareacolor71, height=hi, width=why)
    table.cell(trueareatable, 72, 0, ' ', bgcolor=trueareacolor72, height=hi, width=why)
    table.cell(trueareatable, 73, 0, ' ', bgcolor=trueareacolor73, height=hi, width=why)
    table.cell(trueareatable, 74, 0, ' ', bgcolor=trueareacolor74, height=hi, width=why)
    table.cell(trueareatable, 75, 0, ' ', bgcolor=trueareacolor75, height=hi, width=why)
    table.cell(trueareatable, 76, 0, ' ', bgcolor=trueareacolor76, height=hi, width=why)
    table.cell(trueareatable, 77, 0, ' ', bgcolor=trueareacolor77, height=hi, width=why)
    table.cell(trueareatable, 78, 0, ' ', bgcolor=trueareacolor78, height=hi, width=why)
    table.cell(trueareatable, 79, 0, ' ', bgcolor=trueareacolor79, height=hi, width=why)
    table.cell(trueareatable, 80, 0, ' ', bgcolor=trueareacolor80, height=hi, width=why)
    table.cell(trueareatable, 81, 0, ' ', bgcolor=trueareacolor81, height=hi, width=why)
    table.cell(trueareatable, 82, 0, ' ', bgcolor=trueareacolor82, height=hi, width=why)
    table.cell(trueareatable, 83, 0, ' ', bgcolor=trueareacolor83, height=hi, width=why)
    table.cell(trueareatable, 84, 0, ' ', bgcolor=trueareacolor84, height=hi, width=why)
    table.cell(trueareatable, 85, 0, ' ', bgcolor=trueareacolor85, height=hi, width=why)
    table.cell(trueareatable, 86, 0, ' ', bgcolor=trueareacolor86, height=hi, width=why)
    table.cell(trueareatable, 87, 0, ' ', bgcolor=trueareacolor87, height=hi, width=why)
    table.cell(trueareatable, 89, 0, ' ', bgcolor=trueareacolor89, height=hi, width=why)
    table.cell(trueareatable, 90, 0, ' ', bgcolor=trueareacolor90, height=hi, width=why)
    table.cell(trueareatable, 91, 0, ' ', bgcolor=trueareacolor91, height=hi, width=why)
    table.cell(trueareatable, 92, 0, ' ', bgcolor=trueareacolor92, height=hi, width=why)
    table.cell(trueareatable, 93, 0, ' ', bgcolor=trueareacolor93, height=hi, width=why)
    table.cell(trueareatable, 94, 0, ' ', bgcolor=trueareacolor94, height=hi, width=why)
    table.cell(trueareatable, 95, 0, ' ', bgcolor=trueareacolor95, height=hi, width=why)
    table.cell(trueareatable, 96, 0, ' ', bgcolor=trueareacolor96, height=hi, width=why)
    table.cell(trueareatable, 97, 0, ' ', bgcolor=trueareacolor97, height=hi, width=why)
    table.cell(trueareatable, 98, 0, ' ', bgcolor=trueareacolor98, height=hi, width=why)
    table.cell(trueareatable, 99, 0, ' ', bgcolor=trueareacolor99, height=hi, width=why)
    table.merge_cells(trueareatable, 60, 0, 61, 0)
    table.set_frame_color(trueareatable, baroutercolor_trueareabar)


//END OF TREND AREA BAR ------------------------------------------------------------------------------------------------//END OF TREND AREA BAR//
//END OF TREND AREA BAR ------------------------------------------------------------------------------------------------//END OF TREND AREA BAR//


//MIN MAX NORMALIZATION ------------------------------------------------------------------------------------------------//MIN MAX NORMALIZATION//
//MIN MAX NORMALIZATION ------------------------------------------------------------------------------------------------//MIN MAX NORMALIZATION//


min_price = source == "High / Low" ? request.security(syminfo.tickerid, timeframes, ta.lowest(low, lookback)) : request.security(syminfo.tickerid, timeframes, ta.lowest(close, lookback))
max_price = source == "High / Low" ? request.security(syminfo.tickerid, timeframes, ta.highest(high, lookback)) : request.security(syminfo.tickerid, timeframes, ta.highest(close, lookback))
min_price_long = source == "High / Low" ? request.security(syminfo.tickerid, "", ta.lowest(low, lookback)) : request.security(syminfo.tickerid, "", ta.lowest(close, lookback))
max_price_long = source == "High / Low" ? request.security(syminfo.tickerid, "", ta.highest(high, lookback)) : request.security(syminfo.tickerid, "", ta.highest(close, lookback))


normalized_price = (close - min_price) / (max_price - min_price)
minmax = (normalized_price * 100)

space = request.security(syminfo.tickerid, timeframes, ta.atr(5))
spacelong = request.security(syminfo.tickerid, "", ta.atr(5))

takeprofitm = 0.0
stoplossm = 0.0

if BUY and (stoploss == "Kiersten Stop Loss")
    stoplossm := close - (space * kierstenamount)
if SELL and (stoploss == "Kiersten Stop Loss")
    stoplossm := close + (space * kierstenamount)

if BUY and (takeprofit == "Kiersten Take Profit") 
    takeprofitm:= close + (space * kierstenamount)
if SELL and (takeprofit == "Kiersten Take Profit")
    takeprofitm := close - (space * kierstenamount)


if (takeprofit == "Normalized Take Profit") and normalizedmode == "Automatic" and BUY
    normalizedvaluetakeprofit := 90

if (takeprofit == "Normalized Take Profit") and normalizedmode == "Automatic" and SELL
    normalizedvaluetakeprofit := 10

if (stoploss == "Normalized Stop Loss") and normalizedmode == "Automatic" and BUY
    normalizedvaluestoploss := -10

if (stoploss == "Normalized Stop Loss") and normalizedmode == "Automatic" and SELL
    normalizedvaluestoploss := 110



if (takeprofit == "Normalized Take Profit")
    takeprofitm := ((normalizedvaluetakeprofit/100) * (max_price - min_price)) + min_price 

if (stoploss == "Normalized Stop Loss") 
    stoplossm := ((normalizedvaluestoploss/100) * (max_price - min_price)) + min_price 

if stoploss == "Kiersten Stop Loss"
    normalizedvaluestoploss := ((stoplossm - min_price) / (max_price - min_price)) * 100

if takeprofit == "Kiersten Take Profit"
    normalizedvaluetakeprofit := ((takeprofitm - min_price) / (max_price - min_price)) * 100

minmaxbordercolor = color.gray
if takeprofitm > stoplossm
    minmaxbordercolor := color.green
if takeprofitm < stoplossm
    minmaxbordercolor := color.red
barinnercolor_minmaxbar = color.rgb(51, 153, 255, 50) 
barinnercolor_minmaxbartakeprofit = color.rgb(76, 175, 79, 50)
barinnercolor_minmaxbarstoploss = color.rgb(255, 82, 82, 50)
defaultcolorminmax = color.rgb(120, 123, 134, 70)

var minmax_table = table.new(position.middle_right, 1, 12, border_color = minmaxbordercolor, border_width = 1, frame_color = minmaxbordercolor, frame_width = 2)

minmaxcolor00frequency = 0
minmaxcolor0frequency = 0
minmaxcolor1frequency = 0
minmaxcolor2frequency = 0
minmaxcolor3frequency = 0
minmaxcolor4frequency = 0
minmaxcolor5frequency = 0
minmaxcolor6frequency = 0
minmaxcolor7frequency = 0
minmaxcolor8frequency = 0
minmaxcolor9frequency = 0
minmaxcolor10frequency = 0
minmaxcolor11frequency = 0
minmaxcolor12frequency = 0

for i = 1 to 100
    if minmax[i] <= 0
        minmaxcolor0frequency += 1
    if minmax[i] > 0 and minmax[i] < 10
        minmaxcolor1frequency += 1
    if minmax[i] >= 10 and minmax[i] < 20
        minmaxcolor2frequency += 1
    if minmax[i] >= 20 and minmax[i] < 30
        minmaxcolor3frequency += 1
    if minmax[i] >= 30 and minmax[i] < 40
        minmaxcolor4frequency += 1
    if minmax[i] >= 40 and minmax[i] < 50
        minmaxcolor5frequency += 1
    if minmax[i] >= 50 and minmax[i] < 60
        minmaxcolor6frequency += 1
    if minmax[i] >= 60 and minmax[i] < 70
        minmaxcolor7frequency += 1
    if minmax[i] >= 70 and minmax[i] < 80
        minmaxcolor8frequency += 1
    if minmax[i] >= 80 and minmax[i] < 90
        minmaxcolor9frequency += 1
    if minmax[i] >= 90 and minmax[i] < 100
        minmaxcolor10frequency += 1
    if minmax[i] >= 100
        minmaxcolor11frequency += 1

minmaxcolor00 = defaultcolorminmax
minmaxcolor0 = defaultcolorminmax
minmaxcolor1 = defaultcolorminmax
minmaxcolor2 = defaultcolorminmax
minmaxcolor3 = defaultcolorminmax
minmaxcolor4 = defaultcolorminmax
minmaxcolor5 = defaultcolorminmax
minmaxcolor6 = defaultcolorminmax
minmaxcolor7 = defaultcolorminmax
minmaxcolor8 = defaultcolorminmax
minmaxcolor9 = defaultcolorminmax
minmaxcolor10 = defaultcolorminmax
minmaxcolor11 = defaultcolorminmax
minmaxcolor12 = defaultcolorminmax



if normalizedvaluetakeprofit <= 0
    minmaxcolor0 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 0 and normalizedvaluetakeprofit <= 10
    minmaxcolor1 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 10 and normalizedvaluetakeprofit <= 20
    minmaxcolor2 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 20 and normalizedvaluetakeprofit <= 30
    minmaxcolor3 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 30 and normalizedvaluetakeprofit <= 40
    minmaxcolor4 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 40 and normalizedvaluetakeprofit <= 50
    minmaxcolor5 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit > 50 and normalizedvaluetakeprofit < 60
    minmaxcolor6 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit >= 60 and normalizedvaluetakeprofit < 70
    minmaxcolor7 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit >= 70 and normalizedvaluetakeprofit < 80
    minmaxcolor8 := barinnercolor_minmaxbartakeprofit 
if normalizedvaluetakeprofit >= 80 and normalizedvaluetakeprofit < 90
    minmaxcolor9 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit >= 90 and normalizedvaluetakeprofit < 100
    minmaxcolor10 := barinnercolor_minmaxbartakeprofit
if normalizedvaluetakeprofit >= 100
    minmaxcolor11 := barinnercolor_minmaxbartakeprofit


if normalizedvaluestoploss <= 0
    minmaxcolor0 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 0 and normalizedvaluestoploss <= 10
    minmaxcolor1 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 10 and normalizedvaluestoploss <= 20
    minmaxcolor2 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 20 and normalizedvaluestoploss <= 30
    minmaxcolor3 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 30 and normalizedvaluestoploss <= 40
    minmaxcolor4 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 40 and normalizedvaluestoploss <= 50
    minmaxcolor5 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss > 50 and normalizedvaluestoploss < 60
    minmaxcolor6 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss >= 60 and normalizedvaluestoploss < 70
    minmaxcolor7 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss >= 70 and normalizedvaluestoploss < 80
    minmaxcolor8 := barinnercolor_minmaxbarstoploss 
if normalizedvaluestoploss >= 80 and normalizedvaluestoploss < 90
    minmaxcolor9 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss >= 90 and normalizedvaluestoploss < 100
    minmaxcolor10 := barinnercolor_minmaxbarstoploss
if normalizedvaluestoploss >= 100
    minmaxcolor11 := barinnercolor_minmaxbarstoploss

if minmax <= 0
    minmaxcolor0 := barinnercolor_minmaxbar
if minmax > 0 and minmax <= 10
    minmaxcolor1 := barinnercolor_minmaxbar
if minmax > 10 and minmax <= 20
    minmaxcolor2 := barinnercolor_minmaxbar
if minmax > 20 and minmax <= 30
    minmaxcolor3 := barinnercolor_minmaxbar
if minmax > 30 and minmax <= 40
    minmaxcolor4 := barinnercolor_minmaxbar
if minmax > 40 and minmax <= 50
    minmaxcolor5 := barinnercolor_minmaxbar
if minmax > 50 and minmax < 60
    minmaxcolor6 := barinnercolor_minmaxbar
if minmax >= 60 and minmax < 70
    minmaxcolor7 := barinnercolor_minmaxbar
if minmax >= 70 and minmax < 80
    minmaxcolor8 := barinnercolor_minmaxbar
if minmax >= 80 and minmax < 90
    minmaxcolor9 := barinnercolor_minmaxbar
if minmax >= 90 and minmax < 100
    minmaxcolor10 := barinnercolor_minmaxbar
if minmax >= 100
    minmaxcolor11 := barinnercolor_minmaxbar

minmax_height = 5
minmax_width = 7.5

if device == "Computer"
    table.cell(minmax_table, 0, 0, ((minmax > 100 or normalizedvaluestoploss > 100 or normalizedvaluetakeprofit > 100) ? str.tostring(normalizedvaluetakeprofit > 100 ? normalizedvaluetakeprofit : normalizedvaluestoploss > 100 ? normalizedvaluestoploss : minmax > 100 ? minmax : na, "#.##") + " %" + "\n" +'   ⬆   ' : '   ⬆   '), bgcolor=minmaxcolor11, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 1, 'Top 10%' + " ~ (" + str.tostring(minmaxcolor10frequency) + "%)", bgcolor=minmaxcolor10, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 2, 'Top 20%' + " ~ (" + str.tostring(minmaxcolor9frequency) + "%)", bgcolor=minmaxcolor9, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 3, 'Top 30%' + " ~ (" + str.tostring(minmaxcolor8frequency) + "%)", bgcolor=minmaxcolor8, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 4, 'Top 40%' + " ~ (" + str.tostring(minmaxcolor7frequency) + "%)", bgcolor=minmaxcolor7, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 5, 'Top 50%'+  " ~ (" + str.tostring(minmaxcolor6frequency) + "%)", bgcolor=minmaxcolor6, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 6, 'Bottom 50%'+  " ~ (" +str.tostring(minmaxcolor5frequency) + "%)", bgcolor=minmaxcolor5, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 7, 'Bottom 40%'+  " ~ (" + str.tostring(minmaxcolor4frequency) + "%)", bgcolor=minmaxcolor4, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 8, 'Bottom 30%'+  " ~ (" + str.tostring(minmaxcolor3frequency) + "%)", bgcolor=minmaxcolor3, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 9, 'Bottom 20%'+  " ~ (" + str.tostring(minmaxcolor2frequency) + "%)", bgcolor=minmaxcolor2, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 10, 'Bottom 10%'+  " ~ (" + str.tostring(minmaxcolor1frequency) + "%)", bgcolor=minmaxcolor1, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny)
    table.cell(minmax_table, 0, 11, ((minmax < 0 or normalizedvaluestoploss < 0 or normalizedvaluetakeprofit < 0) ? '   ⬇   ' + "\n" + str.tostring(normalizedvaluetakeprofit < 0 ? normalizedvaluetakeprofit : normalizedvaluestoploss < 0 ? normalizedvaluestoploss : minmax < 0 ? minmax : na, "#.##") + " %" : '   ⬇   '), bgcolor=minmaxcolor0, height=minmax_height, width=minmax_width, text_color = color.white, text_size = size.tiny) 
table.set_frame_color(minmax_table, minmaxbordercolor)
table.set_border_color(minmax_table, minmaxbordercolor)
//END OF MIN MAX NORMALIZATION -----------------------------------------------------------------------------------------//END OF MIN MAX NORMALIZATION//
//END OF MIN MAX NORMALIZATION -----------------------------------------------------------------------------------------//END OF MIN MAX NORMALIZATION// 

//PATTERNS TABLE -------------------------------------------------------------------------------------------------------//PATTERNS TABLE//
//PATTERNS TABLE -------------------------------------------------------------------------------------------------------//PATTERNS TABLE// '   ⬇   '


PatternTable = table.new(position.middle_center,2,22)

if device == "Computer"
    for i = 2 to 13
        table.cell(PatternTable, 1, i)
    table.cell(PatternTable,1, 1,bgcolor = color.new(trendcolor[1], 80) ,height = 12, width =110, text = trend[1] + "      ------- >     " + trend,text_size = size.small,text_color = color.new(trendcolor[1], 20)) 

//PATTERNS TABLE END ---------------------------------------------------------------------------------------------------//PATTERNS TABLE END//
//PATTERNS TABLE END ---------------------------------------------------------------------------------------------------//PATTERNS TABLE END//


max = 100
min = 1

overbought = 65
oversold   = 35

src = close

N = max-min+1
diff = nz(src - src[1])

var num = array.new_float(N,0)
var den = array.new_float(N,0)
//----
k = 0
overbuy = 0
oversell = 0
avg = 0.
for i = min to max
    alpha = 1/i
    
    num_rma = alpha*diff + (1-alpha)*array.get(num,k)
    den_rma = alpha*math.abs(diff) + (1-alpha)*array.get(den,k)
    rsi = 50*num_rma/den_rma + 50
    avg += rsi
    
    overbuy := rsi > overbought ? overbuy + 1 : overbuy
    oversell := rsi < oversold ? oversell + 1 : oversell
    
    array.set(num,k,num_rma)
    array.set(den,k,den_rma)
    k += 1
//----


//TRADABILITY BAR ------------------------------------------------------------------------------------------------------//TRADABILITY BAR//
//TRADABILITY BAR ------------------------------------------------------------------------------------------------------//TRADABILITY BAR//

barinnercolor = color.from_gradient(quality, 0, 100, color.rgb(58, 33, 243, 20), color.rgb(255, 235, 59, 20))
baroutercolor = color.from_gradient(quality, 0, 100, color.blue, color.yellow) 

NormalizedBuy = false
NormalizedSell = false

if  minmax <= normalizedvalue
    NormalizedBuy := true

if  minmax >= (100 - normalizedvalue)
    NormalizedSell := true 


hi_ = 10
why_ = 20

reversalprobability = 0
reversalprobabilitybgcolor = color.rgb(120, 123, 134, 70)
reversalprobabilitycolor = color.gray

if BUY
    reversalprobability := (overbuy/N*100)
    reversalprobabilitybgcolor := color.rgb(255, 82, 82, 70)
    reversalprobabilitycolor := color.red
if SELL
    reversalprobability := (oversell/N*100)
    reversalprobabilitybgcolor := color.rgb(76, 175, 79, 70)
    reversalprobabilitycolor := color.green


// Define inputs
entryPrice = close
takeProfitPrice = takeprofitm
stopLossPrice = stoplossm


reward = BUY ? (positionSize * (takeProfitPrice - entryPrice) / syminfo.mintick) : (positionSize * (takeProfitPrice - entryPrice) / syminfo.mintick) * -1
risk = BUY ? (positionSize * (entryPrice - stopLossPrice) / syminfo.mintick) : (positionSize * (entryPrice - stopLossPrice) / syminfo.mintick) * -1
RRR = reward/risk


BuySetting = (truearea >= trueareaalertvalue) and (BUY) and (NormalizedBuy) and (((UsePatterns == true and (trendcolor[1] == color.green)) or (UsePatterns == false))) and (maxrisk >= risk) and (minreward <= reward) and (minRRR <= RRR)
SellSetting = (truearea >= trueareaalertvalue) and (SELL) and (NormalizedSell) and (((UsePatterns == true and (trendcolor[1] == color.red)) or (UsePatterns == false))) and (maxrisk >= risk) and (minreward <= reward) and (minRRR <= RRR)

reversalprobabilitycolor := color.from_gradient(RRR, 0, 10, color.rgb(33, 149, 243, 50), color.rgb(255, 235, 59, 50))

mobilecolor = color.rgb(255, 255, 255, 50)
framewide = 1

if BuySetting 
    mobilecolor := color.green
    framewide := 4
if SellSetting
    mobilecolor := color.red
    framewide := 4

var statstable = table.new(position.bottom_center, 6, 1, border_width = 1, border_color = color.new(mobilecolor, 90), frame_color = baroutercolor_trueareabar, frame_width = 2)
table.set_border_color(statstable, mobilecolor)
table.set_frame_color(statstable, mobilecolor)
 
if device == "Computer"
    table.cell(statstable , 1, 0, "Take Profit: " + str.tostring(takeprofitm, "#.#####") + "$" + "   (Reward " + str.tostring(reward, "#") + " $)", bgcolor= color.rgb(76, 175, 79, 70), height=hi_, width=why_, text_color = color.green, text_size = size.small) 
    table.cell(statstable , 2, 0, "Stop Loss: " + str.tostring(stoplossm, "#.#####") + "$" + "    (Risk " + str.tostring(risk, "#") + " $)", bgcolor= color.rgb(255, 82, 82, 70), height=hi_, width=why_, text_color = color.red, text_size = size.small) 
    table.cell(statstable , 3, 0, "Risk Reward Ratio: " + str.tostring(RRR, "#.##") + "x", bgcolor= color.from_gradient(reward/risk, 0.1, 10, color.rgb(33, 149, 243, 50), color.rgb(255, 235, 59, 50)), height=hi_, width=why_, text_color = color.white, text_size = size.small) 
    table.cell(statstable , 4, 0, "Likelihood of Reversal: " + str.tostring(reversalprobability, "#.##") + " %", bgcolor= reversalprobabilitybgcolor, height=hi_, width=why_, text_color = color.white, text_size = size.small) 
    table.cell(statstable, 5, 0, text = (str.tostring(speed, '#.##') + ' Pips Per Minute'), bgcolor = color.from_gradient(speed, ta.lowest(speed, lookback),ta.highest(speed, lookback), color.rgb(33, 149, 243, 70), color.rgb(255, 235, 59, 70)), text_color = color.from_gradient(speed, ta.lowest(speed, lookback),ta.highest(speed, lookback), color.blue, color.yellow), width = why_, height = hi_, text_size = size.small)


//END OF TRADABILITY BAR -----------------------------------------------------------------------------------------------//END OF TRADABILITY BAR//
//END OF TRADABILITY BAR -----------------------------------------------------------------------------------------------//END OF TRADABILITY BAR//

//PLOT COLORFUL LINES ---------------------------------------------------------------------------------------------------//PLOT COLORFUL LINES//
//PLOT COLORFUL LINES ---------------------------------------------------------------------------------------------------//PLOT COLORFUL LINES//

plot(0, color =  useLongHeikinAshi ? color.gray : na, style = plot.style_line, linewidth = 3) 
plot(0, color =  useLongHeikinAshi and fourhourHeikinAshibuy ? color.green : na, style = plot.style_line, linewidth = 3) 
plot(0, color =  useLongHeikinAshi and fourhourHeikinAshisell ? color.red : na, style = plot.style_line, linewidth = 3) 

plot(1, color = useWilliamAlligator ? color.gray : na, style = plot.style_line, linewidth = 3)
plot(1, color = useWilliamAlligator and WilliamsAlligatorBuy ? color.green : na, style = plot.style_line, linewidth = 3)
plot(1, color = useWilliamAlligator and WilliamsAlligatorSell ? color.red : na, style = plot.style_line, linewidth = 3)

plot(2, color = useChandelierExit ? color.gray : na, style = plot.style_line, linewidth = 3)
plot(2, color = useChandelierExit and ChandelierBuy ? color.green : na, style = plot.style_line)
plot(2, color = useChandelierExit and ChandelierSell ? color.red : na, style = plot.style_line)

plot(3, color = useShortHeikinAshi ? color.gray : na, style = plot.style_line, linewidth = 3)
plot(3, color = useShortHeikinAshi and onehourHeikinAshiBuy ? color.green : na, style = plot.style_line)
plot(3, color = useShortHeikinAshi and onehourHeikinAshiSell ? color.red : na, style = plot.style_line)

plot(4, color = useMFI ? color.gray : na, style = plot.style_cross)
plot(4, color = useMFI and MFIbuy ? color.green : na, style = plot.style_cross)
plot(4, color = useMFI and MFIsell ? color.red : na, style = plot.style_cross)

plot(5, color = useMACD ? color.gray : na, style = plot.style_line, linewidth = 3)
plot(5, color = useMACD and MACDTRADEBUY ? color.green : na, style = plot.style_line, linewidth = 3)
plot(5, color = useMACD and MACDTRADESELL ? color.red : na, style = plot.style_line, linewidth = 3)

plot(8.5, color = color.rgb(255, 255, 255, 100))
plot(-2, color = color.rgb(255, 255, 255, 100))


EVRYTHINGBUY = williamsalligator != "Williams Alligator is Bearish ↓" and dir == 1 and ha_diff60 == 2 and ta.mfi(close, 14)[2] <= 70 and MACDTRADESELL == false
EVRYTHINGSELL = williamsalligator != "Williams Alligator is Bullish ↑" and dir == -1 and ha_diff60 == 1 and ta.mfi(close, 14)[2] >= 30 and MACDTRADEBUY == false

EVERYTHINGBUY = EVRYTHINGBUY[1] == false and EVRYTHINGBUY
EVERYTHINGSELL = EVRYTHINGSELL[1] == false and EVRYTHINGSELL

plot(5, color = useEverything and EVERYTHINGBUY == true ? color.rgb(36, 255, 43, 90) : na, style = plot.style_area, linewidth = 4)
plot(6, color = useEverything and EVERYTHINGBUY == true ? color.rgb(45, 255, 52) : na, style = plot.style_cross, linewidth = 2)

plot(5, color = useEverything and EVERYTHINGSELL == true ? color.rgb(175, 76, 76, 90) : na, style = plot.style_area, linewidth = 4)
plot(6, color = useEverything and EVRYTHINGSELL == true ? color.rgb(175, 76, 76) : na, style = plot.style_cross, linewidth = 2)

//END PLOT COLORFUL LINES ----------------------------------------------------------------------------------------------//END PLOT COLORFUL LINES//
//END PLOT COLORFUL LINES ----------------------------------------------------------------------------------------------/END PLOT COLORFUL LINES//

//MOBILE VERSION -------------------------------------------------------------------------------------------------------//MOBILE VERSION//
//MOBILE VERSION -------------------------------------------------------------------------------------------------------//MOBILE VERSION//
 
plot(device == "Mobile" ? 100000 : na, color = color.rgb(255, 255, 255, 90))


var mobiletable = table.new(position.middle_left, 6, 13, border_width = 1, border_color = baroutercolor_trueareabar, frame_color = baroutercolor_trueareabar, frame_width = framewide)
table.set_border_color(mobiletable, color.new(mobilecolor, 99))
table.set_frame_color(mobiletable, mobilecolor)
table.set_frame_width(mobiletable, framewide)

hi__ = 12
why__ = 16.5

speedcolor = color.from_gradient(speed, ta.lowest(speed, lookback),ta.highest(speed, lookback) / 2, color.rgb(33, 149, 243, 70), color.rgb(255, 235, 59, 70))
if device == "Mobile"
    table.cell(mobiletable, 0, 0, text = "Price:  " + (str.tostring(close, '#.#####')) + " $", bgcolor = color.rgb(0, 0, 0), text_color = open > close ? color.red : color.green, width = why__ / 2, height = hi__ / 2, text_size = size.small)
    for i = 2 to 5
        table.cell(mobiletable, 0, i)
    table.merge_cells(mobiletable, 0, 0, 5, 0)  

    table.cell(mobiletable , 0, 1, bgcolor = color.new(barinnercolor_trueareabar, 80) ,height = hi__, width =why__, text = str.tostring(truearea[areanumber], "#") + "  %" + "\n" + "\n" + "      ↓      " + "\n" + "\n" + str.tostring(truearea, "#") + "  %",text_size = size.small,text_color = baroutercolor_trueareabar) 
    for i = 2 to 5
        table.cell(mobiletable, 2, i)
    table.merge_cells(mobiletable, 0, 1, 2, 1) 

    table.cell(mobiletable , 3, 1, bgcolor = color.new(trendcolor[1], 80) ,height = hi__, width =why__, text = trend[1] + "\n" + "\n" + "      ↓      " + "\n" + "\n" + trend,text_size = size.small,text_color = color.new(trendcolor[1], 20)) 
    table.merge_cells(mobiletable, 3, 1, 5, 1) 

    table.cell(mobiletable, 0, 2, ((minmax > 100 or normalizedvaluestoploss > 100 or normalizedvaluetakeprofit > 100) ? str.tostring(normalizedvaluetakeprofit > 100 ? normalizedvaluetakeprofit : normalizedvaluestoploss > 100 ? normalizedvaluestoploss : minmax > 100 ? minmax : na, "#.##") + " %" + "\n" + "\n" +'   <   ' : '   <   '), bgcolor=minmaxcolor11, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 1, 2, 'Top 10%' + "\n" + "( Frq " + str.tostring(minmaxcolor10frequency) + "% )", bgcolor=minmaxcolor10, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 2, 2, 'Top 20%' + "\n" + "( Frq " + str.tostring(minmaxcolor9frequency) + "% )", bgcolor=minmaxcolor9, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 3, 2, 'Top 30%' + "\n" + "( Frq " + str.tostring(minmaxcolor8frequency) + "% )", bgcolor=minmaxcolor8, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 4, 2, 'Top 40%' + "\n" + "( Frq " + str.tostring(minmaxcolor7frequency) + "% )", bgcolor=minmaxcolor7, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 5, 2, 'Top 50%' + "\n" + "( Frq " + str.tostring(minmaxcolor6frequency) + "% )", bgcolor=minmaxcolor6, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)

    table.cell(mobiletable, 0, 3, 'Bottom 50%' + "\n" + "( Frq " + str.tostring(minmaxcolor5frequency) + "% )", bgcolor=minmaxcolor5, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 1, 3, 'Bottom 40%'+ "\n" + "( Frq " + str.tostring(minmaxcolor4frequency) + "% )", bgcolor=minmaxcolor4, height=hi__, width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 2, 3, 'Bottom 30%' + "\n" + "( Frq " + str.tostring(minmaxcolor3frequency) + "% )", bgcolor=minmaxcolor3, height=hi__ , width=why__, text_color = color.white, text_size = size.tiny) 
    table.cell(mobiletable, 3, 3, 'Bottom 20%' + "\n" + "( Frq " + str.tostring(minmaxcolor2frequency) + "% )", bgcolor=minmaxcolor2, height=hi__ , width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 4, 3, 'Bottom 10%'+ "\n" + "( Frq " + str.tostring(minmaxcolor1frequency) + "% )", bgcolor=minmaxcolor1, height=hi__ , width=why__, text_color = color.white, text_size = size.tiny)
    table.cell(mobiletable, 5, 3, ((minmax < 0 or normalizedvaluestoploss < 0 or normalizedvaluetakeprofit < 0) ? str.tostring(normalizedvaluetakeprofit < 0 ? normalizedvaluetakeprofit : normalizedvaluestoploss < 0 ? normalizedvaluestoploss : minmax < 0 ? minmax : na, "#.##") + " %" + "\n" + "\n" +'   <   ' : '   <   '), bgcolor=minmaxcolor0, height=hi__ , width=why__, text_color = color.white, text_size = size.tiny)
    
    table.cell(mobiletable , 0, 4, "Top Frequency: " + str.tostring(minmaxcolor11frequency + minmaxcolor10frequency + minmaxcolor9frequency + minmaxcolor8frequency + minmaxcolor7frequency) + " %", bgcolor= color.rgb(76, 175, 79, 70), height=hi__ / 2, width=why__, text_color = color.green, text_size = size.small)
    table.cell(mobiletable , 2, 4, "Middle Frequency: " + str.tostring(minmaxcolor5frequency + minmaxcolor6frequency) + " %", bgcolor= color.rgb(120, 123, 134, 70), height=hi__ / 2, width=why__, text_color = color.rgb(255, 255, 255), text_size = size.small)
    table.cell(mobiletable , 4, 4, "Bottom Frequency: " + str.tostring(minmaxcolor4frequency + minmaxcolor3frequency + minmaxcolor2frequency + minmaxcolor1frequency + minmaxcolor0frequency)+ " %", bgcolor= color.rgb(255, 82, 82, 70), height=hi__ / 2, width=why__, text_color = color.red, text_size = size.small)

    table.merge_cells(mobiletable, 0, 4, 1, 4) 
    table.merge_cells(mobiletable, 2, 4, 3, 4) 
    table.merge_cells(mobiletable, 4, 4, 5, 4) 


    table.cell(mobiletable , 0, 5, "Stop Loss: " + str.tostring(stoplossm, "#.#####") + " $" + "\n" + "\n" + "   (Risk " + str.tostring(risk, "#") + " $)", bgcolor= color.rgb(255, 82, 82, 70), height=hi__, width=why__, text_color = color.red, text_size = size.small) 
    for i = 2 to 5
        table.cell(mobiletable, i, 5)
    table.merge_cells(mobiletable, 0, 5, 2, 5) 

    table.cell(mobiletable , 3, 5, "Take Profit: " + str.tostring(takeprofitm, "#.#####") + " $" + "\n" + "\n" + "   (Reward " + str.tostring(reward, "#") + " $)", bgcolor= color.rgb(76, 175, 79, 70), height=hi__, width=why__, text_color = color.green, text_size = size.small) 
    table.merge_cells(mobiletable, 3, 5, 5, 5) 

    table.cell(mobiletable , 0, 6, "Risk to Reward Ratio: " + str.tostring(RRR, "#.##") + " x" + "\n" + "\n" + "↓", bgcolor= reversalprobabilitycolor, height=hi__, width=why__, text_color = reversalprobabilitycolor, text_size = size.small) 
    table.merge_cells(mobiletable, 0, 6, 5, 6)
    
    table.cell(mobiletable , 0, 7, "////////////////////////////////////////////", bgcolor= RRR > 0 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 0 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 1, 7, "////////////////////////////////////////////", bgcolor= RRR > 2 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 2 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 2, 7, "////////////////////////////////////////////", bgcolor= RRR > 4 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 4 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 3, 7, "////////////////////////////////////////////", bgcolor= RRR > 6 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 6 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 4, 7, "////////////////////////////////////////////", bgcolor= RRR > 8 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 8 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 5, 7, "////////////////////////////////////////////", bgcolor= RRR > 10 ? color.new(reversalprobabilitycolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = RRR > 10 ? color.new(reversalprobabilitycolor, 80) : defaultcolor, text_size = size.huge) 

    table.cell(mobiletable, 0, 8, text = "Speed:  " + (str.tostring(speed, '#.##') + ' PPM') + "\n" + "\n" + (speed > 20 ? "🐇" : "🐢"), bgcolor = color.from_gradient(speed, ta.lowest(speed, lookback),ta.highest(speed, lookback) / 2, color.rgb(33, 149, 243, 70), color.rgb(255, 235, 59, 70)), text_color = color.from_gradient(speed, ta.lowest(speed, lookback),ta.highest(speed, lookback), color.rgb(34, 108, 255), color.rgb(251, 255, 0)), width = why__, height = hi__ * 1.5, text_size = size.normal)
    table.merge_cells(mobiletable, 0, 8, 5, 8)

    table.cell(mobiletable , 0, 9, "////////////////////////////////////////////", bgcolor= speed > 1 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 1 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 1, 9, "////////////////////////////////////////////", bgcolor= speed > 20 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 20 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 2, 9, "////////////////////////////////////////////", bgcolor= speed > 30 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 30 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 3, 9, "////////////////////////////////////////////", bgcolor= speed > 40 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 40 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 4, 9, "////////////////////////////////////////////", bgcolor= speed > 50 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 50 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable , 5, 9, "////////////////////////////////////////////", bgcolor= speed > 60 ? color.new(speedcolor, 60) : defaultcolor, height=hi__ / 4, width=why__, text_color = speed > 60 ? color.new(speedcolor, 80) : defaultcolor, text_size = size.huge) 
    table.cell(mobiletable, 0, 10, text = "By Kiersten and Haji", bgcolor = color.rgb(0, 0, 0), text_color = color.rgb(255, 38, 150, 10), width = why__ / 6, height = hi__ / 6, text_size = size.tiny)
    table.merge_cells(mobiletable, 0, 10, 5, 10)
hline(device == "Mobile" ? 8 : na, color = color.silver, linestyle = hline.style_solid, linewidth = device == "Mobile" ? 5 : 1)

//ALERTS ---------------------------------------------------------------------------------------------------------------//ALERTS//
//ALERTS ---------------------------------------------------------------------------------------------------------------//ALERTS//
CloseBuy = false
CloseSell = false

if  minmax <= normalizedvaluetakeprofit
    CloseSell := true

if  minmax >= normalizedvaluetakeprofit
    CloseBuy := true

alertcondition(BuySetting or SellSetting, ".Trade", "TRADE {{ticker}}")
alertcondition(CloseBuy, "I JUST BOUGHT", "GET OUT {{ticker}}")
alertcondition(CloseSell, "I JUST SOLD", "GET OUT {{ticker}}")

//END OF ALERTS --------------------------------------------------------------------------------------------------------//END OF ALERTS//
//END OF ALERTS --------------------------------------------------------------------------------------------------------//END OF ALERTS//

//VERY END -------------------------------------------------------------------------------------------------------------VERY END//
//VERY END -------------------------------------------------------------------------------------------------------------VERY END//