Cloud Bunching [5ema]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Reused some functions from (I believe made by ©paaax, @QuantNomad)
// ©paaax: The table position function (https://www.tradingview.com/script/Jp37jHwT-PX-MTF-Overview/).
// @QuantNomad: The function calculated value and array screener for 40+ instruments (https://www.tradingview.com/script/zN8rwPFF-Screener-for-40-instruments/).
// © vn-5ema
 
 //@version=5
indicator("Cloud Bunching [5ema]", overlay = true)
// Input condition
iBunch = input.float(defval = 1, minval=0, title="Bunching (%)", group = "Condition of Signal", tooltip = "The bunching ratio between Upper and Lower of Cloud. Change the value for each symbol to get the highest win rate.")
// Input the ratio to over of Close
iCross = input.float(defval = 2, minval=0, title="Crossing (%)", group = "Condition of Signal", tooltip = "The crossing ratio of close Close over Cloud. Change the value for each symbol to get the highest win rate.")
// Volume condition
opVolume = input.string(title="High Volume", defval = "Yes", options = ["Yes", "No"], group = "Condition of Signal", tooltip = "By default, only buy and sell if volume > MA20 Volume.")
// Table position
boolTable = input.bool(defval = false, title = "Table        ", group="Show on chart", inline = "table")
pos = input.string("Bottom Left", title="", options=["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group="Show on chart", inline = "table")
// Table position
/////// This function reused from ©paaax /////
TablePosition(pos) =>
    ret = position.top_left
    if pos == "Top Center"
        ret := position.top_center
    if pos == "Top Right"
        ret := position.top_right
    if pos == "Middle Left"
        ret := position.middle_left
    if pos == "Middle Center"
        ret := position.middle_center
    if pos == "Middle Right"
        ret := position.middle_right
    if pos == "Bottom Left"
        ret := position.bottom_left
    if pos == "Bottom Center"
        ret := position.bottom_center
    if pos == "Bottom Right"
        ret := position.bottom_right
    ret
//////////
boolCloud = input.bool(defval = true, title = "The Cloud", group="Show on chart")
// Cloud Color
bunchColor = input.color(color.new(#ffa726, 75), title = "Bunching color", group = "Set up Cloud color")
upperColor = input.color(color.new(#388e3c, 75),title = "Upper color", group = "Set up Cloud color")
lowerColor = input.color(color.new(#b22833, 75),title = "Lower color", group = "Set up Cloud color")
// Set up Alert
boolSignalAlert = input.string(title="Select signal", defval = "BUY and SELL", options =  ["BUY", "SELL", "BUY and SELL"], group = "Set up Alert")
// Timeframe
timeframe = input.timeframe(defval = "", title = "Time frame", group = "Set up Alert", tooltip = "By default, following the current chart. Can select another time frame to follow the symbol for showing on table and making the arlert.")
// Symbol bool
/////// This bool symbool refer from @QuantNomad /////
u01 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's01')
u02 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's02')
u03 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's03')
u04 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's04')
u05 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's05')
u06 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's06')
u07 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's07')
u08 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's08')
u09 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's09')
u10 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's10')
u11 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's11')
u12 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's12')
u13 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's13')
u14 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's14')
u15 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's15')
u16 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's16')
u17 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's17')
u18 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's18')
u19 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's19')
u20 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's20')
u21 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's21')
u22 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's22')
u23 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's23')
u24 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's24')
u25 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's25')
u26 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's26')
u27 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's27')
u28 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's28')
u29 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's29')
u30 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's30')
u31 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's31')
u32 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's32')
u33 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's33')
u34 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's34')
u35 = input.bool(false,  title = "", group = 'Symbols following and alert', inline = 's35')
u36 = input.bool(false, title = "", group = 'Symbols following and alert', inline = 's36')
u37 = input.bool(false, title = "", group = 'Symbols following and alert', inline = 's37')
u38 = input.bool(false, title = "", group = 'Symbols following and alert', inline = 's38')
u39 = input.bool(false, title = "", group = 'Symbols following and alert', inline = 's39')
//u40 = input.bool(false, title = "", group = 'Symbols following and alert', inline = 's40')
//Symbol choose
s01 = input.symbol('BTCUSDT',  group = 'Symbols following and alert', inline = 's01')
s02 = input.symbol('ETHUSDT',  group = 'Symbols following and alert', inline = 's02')
s03 = input.symbol('BNBUSDT', group = 'Symbols following and alert', inline = 's03')
s04 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's04')
s05 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's05')
s06 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's06')
s07 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's07')
s08 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's08')
s09 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's09')
s10 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's10')
s11 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's11')
s12 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's12')
s13 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's13')
s14 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's14')
s15 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's15')
s16 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's16')
s17 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's17')
s18 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's18')
s19 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's19')
s20 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's20')
s21 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's21')
s22 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's22')
s23 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's23')
s24 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's24')
s25 = input.symbol('USDT', group = 'Symbols following and alert', inline = 's25')
s26 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's26')
s27 = input.symbol('USDT', group = 'Symbols following and alert', inline = 's27')
s28 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's28')
s29 = input.symbol('USDT', group = 'Symbols following and alert', inline = 's29')
s30 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's30')
s31 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's31')
s32 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's32')
s33 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's33')
s34 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's34')
s35 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's35')
s36 = input.symbol('USDT', group = 'Symbols following and alert', inline = 's36')
s37 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's37')
s38 = input.symbol('USDT',   group = 'Symbols following and alert', inline = 's38')
s39 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's39')
//s40 = input.symbol('USDT',  group = 'Symbols following and alert', inline = 's40')
//////////

// CALCULATIONS //
// Get only symbol
only_symbol(s) => 
    array.get(str.split(s, ":"), 1)
// Calculate
oEMA1 = ta.ema(close, 20)
oEMA2 = ta.ema(close, 50)
oEMA3 = ta.ema(close, 200)
oEMA4 = ta.ema(close, 460)
oEMA5 = ta.ema(close, 610)
avgEMA = math.avg(oEMA1, oEMA2, oEMA3, oEMA4, oEMA5)
maxEMA = math.max(oEMA1, oEMA2, oEMA3, oEMA4, oEMA5)
minEMA = math.min(oEMA1, oEMA2, oEMA3, oEMA4, oEMA5)


//Calculate Bunching
cPriceBUY = ((close - maxEMA) / maxEMA) * 100
cPriceSELL = ((close - minEMA) / minEMA) * 100

//Bar Coditions
greenbar = close > open
redbar = close < open
bodybar = math.abs(close - open)
fullbar = high - low
topwick = high - math.max(close, open)
bottomwick = math.abs  (math.min(close, open) - low)

Hammer =  bodybar <  bottomwick *0.786 and topwick < 0.236 * bottomwick
InvertedHammer = bodybar < topwick *786 and bottomwick < 0.236 * topwick

redlongbody = redbar[1] ? (redbar and bodybar > 0.786 * fullbar and fullbar > fullbar[1]) : (redbar and bodybar > 0.786 * fullbar and (fullbar >= 1.5* fullbar[1] or InvertedHammer[1]))
greenlongbody = greenbar[1] ? (greenbar and bodybar > 0.786 * fullbar and fullbar > fullbar[1]) : (greenbar and bodybar > 0.786 * fullbar and (fullbar >= 1.5* fullbar[1] or Hammer[1]))

BullishEngulfing = redbar[1] and not InvertedHammer[1] and low[1] >  low and close[1] <= open  and close > high[1] and greenlongbody
BearishEngulfing = greenbar[1] and not Hammer[1] and low[1] >  low and close[1] < open and redlongbody

//Signal condition
barBUY =  (BullishEngulfing or greenlongbody) and close[1] > avgEMA and close > close[1] and (close + open) / 2 >= maxEMA
barSELL = (BearishEngulfing or redlongbody) and close[1] < avgEMA and close < close[1] and (open + close) / 2 <= minEMA

// Volume condition
oVolume = opVolume == "No" ? (volume > ta.sma(volume, 20) * 0) : (volume > ta.sma(volume, 20) * 1)
//Bunch
cBunch_func () =>
    cBunch = (math.abs(maxEMA - minEMA) / minEMA) * 100
//Cross
cPrice_func () =>
    cPrice = (cPriceBUY < 0 and cPriceSELL > 0) ? 0 : (cPriceSELL < 0) ? cPriceSELL : cPriceBUY
// Screener
screener_func() =>
    //Bunch
    cBunch = cBunch_func()
    //Cross
    cPrice = cPrice_func()
    //signal condition
    signalBUY = cBunch <= iBunch and cBunch > 0 and cPrice <= iCross and cPrice > 0 and barBUY and oVolume
    signalSELL = cBunch <= iBunch and cBunch > 0 and math.abs(cPrice) <= iCross and cPrice < 0 and barSELL and oVolume
   //Security func
    [cBunch, cPrice, signalSELL, signalBUY]

// Security call
/////// This bool symbool refer from @QuantNomad /////
[cBunch, cPrice, signalSELL, signalBUY] = request.security(symbol = syminfo.tickerid, timeframe = timeframe.period, expression =  screener_func())
[cBunch01, cPrice01, signalSELL01, signalBUY01] = request.security(s01, timeframe, screener_func())
[cBunch02, cPrice02, signalSELL02, signalBUY02] = request.security(s02, timeframe, screener_func())
[cBunch03, cPrice03, signalSELL03, signalBUY03] = request.security(s03, timeframe, screener_func())
[cBunch04, cPrice04, signalSELL04, signalBUY04] = request.security(s04, timeframe, screener_func())
[cBunch05, cPrice05, signalSELL05, signalBUY05] = request.security(s05, timeframe, screener_func())
[cBunch06, cPrice06, signalSELL06, signalBUY06] = request.security(s06, timeframe, screener_func())
[cBunch07, cPrice07, signalSELL07, signalBUY07] = request.security(s07, timeframe, screener_func())
[cBunch08, cPrice08, signalSELL08, signalBUY08] = request.security(s08, timeframe, screener_func())
[cBunch09, cPrice09, signalSELL09, signalBUY09] = request.security(s09, timeframe, screener_func())
[cBunch10, cPrice10, signalSELL10, signalBUY10] = request.security(s10, timeframe, screener_func())
[cBunch11, cPrice11, signalSELL11, signalBUY11] = request.security(s11, timeframe, screener_func())
[cBunch12, cPrice12, signalSELL12, signalBUY12] = request.security(s12, timeframe, screener_func())
[cBunch13, cPrice13, signalSELL13, signalBUY13] = request.security(s13, timeframe, screener_func())
[cBunch14, cPrice14, signalSELL14, signalBUY14] = request.security(s14, timeframe, screener_func())
[cBunch15, cPrice15, signalSELL15, signalBUY15] = request.security(s15, timeframe, screener_func())
[cBunch16, cPrice16, signalSELL16, signalBUY16] = request.security(s16, timeframe, screener_func())
[cBunch17, cPrice17, signalSELL17, signalBUY17] = request.security(s17, timeframe, screener_func())
[cBunch18, cPrice18, signalSELL18, signalBUY18] = request.security(s18, timeframe, screener_func())
[cBunch19, cPrice19, signalSELL19, signalBUY19] = request.security(s19, timeframe, screener_func())
[cBunch20, cPrice20, signalSELL20, signalBUY20] = request.security(s20, timeframe, screener_func())
[cBunch21, cPrice21, signalSELL21, signalBUY21] = request.security(s21, timeframe, screener_func())
[cBunch22, cPrice22, signalSELL22, signalBUY22] = request.security(s22, timeframe, screener_func())
[cBunch23, cPrice23, signalSELL23, signalBUY23] = request.security(s23, timeframe, screener_func())
[cBunch24, cPrice24, signalSELL24, signalBUY24] = request.security(s24, timeframe, screener_func())
[cBunch25, cPrice25, signalSELL25, signalBUY25] = request.security(s25, timeframe, screener_func())
[cBunch26, cPrice26, signalSELL26, signalBUY26] = request.security(s26, timeframe, screener_func())
[cBunch27, cPrice27, signalSELL27, signalBUY27] = request.security(s27, timeframe, screener_func())
[cBunch28, cPrice28, signalSELL28, signalBUY28] = request.security(s28, timeframe, screener_func())
[cBunch29, cPrice29, signalSELL29, signalBUY29] = request.security(s29, timeframe, screener_func())
[cBunch30, cPrice30, signalSELL30, signalBUY30] = request.security(s30, timeframe, screener_func())
[cBunch31, cPrice31, signalSELL31, signalBUY31] = request.security(s31, timeframe, screener_func())
[cBunch32, cPrice32, signalSELL32, signalBUY32] = request.security(s32, timeframe, screener_func())
[cBunch33, cPrice33, signalSELL33, signalBUY33] = request.security(s33, timeframe, screener_func())
[cBunch34, cPrice34, signalSELL34, signalBUY34] = request.security(s34, timeframe, screener_func())
[cBunch35, cPrice35, signalSELL35, signalBUY35] = request.security(s35, timeframe, screener_func())
[cBunch36, cPrice36, signalSELL36, signalBUY36] = request.security(s36, timeframe, screener_func())
[cBunch37, cPrice37, signalSELL37, signalBUY37] = request.security(s37, timeframe, screener_func())
[cBunch38, cPrice38, signalSELL38, signalBUY38] = request.security(s38, timeframe, screener_func())
[cBunch39, cPrice39, signalSELL39, signalBUY39] = request.security(s39, timeframe, screener_func())
//[cBunch40, cPrice40, signalSELL40, signalBUY40] = request.security(s40, timeframe, screener_func())

//Screener table
scr_table = ''
//Signal BUY
scr_table := u01 != false and signalBUY01 ? scr_table + s01 + ' ⦿' + '\n' : scr_table
scr_table := u02 != false and signalBUY02 ? scr_table + s02 + ' ⦿' + '\n' : scr_table
scr_table := u03 != false and signalBUY03 ? scr_table + s03 + ' ⦿' + '\n' : scr_table
scr_table := u04 != false and signalBUY04 ? scr_table + s04 + ' ⦿' + '\n' : scr_table
scr_table := u05 != false and signalBUY05 ? scr_table + s05 + ' ⦿' + '\n' : scr_table
scr_table := u06 != false and signalBUY06 ? scr_table + s06 + ' ⦿' + '\n' : scr_table
scr_table := u07 != false and signalBUY07 ? scr_table + s07 + ' ⦿' + '\n' : scr_table
scr_table := u08 != false and signalBUY08 ? scr_table + s08 + ' ⦿' + '\n' : scr_table
scr_table := u09 != false and signalBUY09 ? scr_table + s09 + ' ⦿' + '\n' : scr_table
scr_table := u10 != false and signalBUY10 ? scr_table + s10 + ' ⦿' + '\n' : scr_table
scr_table := u11 != false and signalBUY11 ? scr_table + s11 + ' ⦿' + '\n' : scr_table
scr_table := u12 != false and signalBUY12 ? scr_table + s12 + ' ⦿' + '\n' : scr_table
scr_table := u13 != false and signalBUY13 ? scr_table + s13 + ' ⦿' + '\n' : scr_table
scr_table := u14 != false and signalBUY14 ? scr_table + s14 + ' ⦿' + '\n' : scr_table
scr_table := u15 != false and signalBUY15 ? scr_table + s15 + ' ⦿' + '\n' : scr_table
scr_table := u16 != false and signalBUY16 ? scr_table + s16 + ' ⦿' + '\n' : scr_table
scr_table := u17 != false and signalBUY17 ? scr_table + s17 + ' ⦿' + '\n' : scr_table
scr_table := u18 != false and signalBUY18 ? scr_table + s18 + ' ⦿' + '\n' : scr_table
scr_table := u19 != false and signalBUY19 ? scr_table + s19 + ' ⦿' + '\n' : scr_table
scr_table := u20 != false and signalBUY20 ? scr_table + s20 + ' ⦿' + '\n' : scr_table
scr_table := u21 != false and signalBUY21 ? scr_table + s21 + ' ⦿' + '\n' : scr_table
scr_table := u22 != false and signalBUY22 ? scr_table + s22 + ' ⦿' + '\n' : scr_table
scr_table := u23 != false and signalBUY23 ? scr_table + s23 + ' ⦿' + '\n' : scr_table
scr_table := u24 != false and signalBUY24 ? scr_table + s24 + ' ⦿' + '\n' : scr_table
scr_table := u25 != false and signalBUY25 ? scr_table + s25 + ' ⦿' + '\n' : scr_table
scr_table := u26 != false and signalBUY26 ? scr_table + s26 + ' ⦿' + '\n' : scr_table
scr_table := u27 != false and signalBUY27 ? scr_table + s27 + ' ⦿' + '\n' : scr_table
scr_table := u28 != false and signalBUY28 ? scr_table + s28 + ' ⦿' + '\n' : scr_table
scr_table := u29 != false and signalBUY29 ? scr_table + s29 + ' ⦿' + '\n' : scr_table
scr_table := u30 != false and signalBUY30 ? scr_table + s30 + ' ⦿' + '\n' : scr_table
scr_table := u31 != false and signalBUY31 ? scr_table + s31 + ' ⦿' + '\n' : scr_table
scr_table := u32 != false and signalBUY32 ? scr_table + s32 + ' ⦿' + '\n' : scr_table
scr_table := u33 != false and signalBUY33 ? scr_table + s33 + ' ⦿' + '\n' : scr_table
scr_table := u34 != false and signalBUY34 ? scr_table + s34 + ' ⦿' + '\n' : scr_table
scr_table := u35 != false and signalBUY35 ? scr_table + s35 + ' ⦿' + '\n' : scr_table
scr_table := u36 != false and signalBUY36 ? scr_table + s36 + ' ⦿' + '\n' : scr_table
scr_table := u37 != false and signalBUY37 ? scr_table + s37 + ' ⦿' + '\n' : scr_table
scr_table := u38 != false and signalBUY38 ? scr_table + s38 + ' ⦿' + '\n' : scr_table
scr_table := u39 != false and signalBUY39 ? scr_table + s39 + ' ⦿' + '\n' : scr_table
//scr_table := u40 != false and signalBUY40 ? scr_table + s40 + ' ⦿' + '\n' : scr_table

//Signal SELL
scr_table := u01 != false and signalSELL01 ? scr_table + s01 + ' ⦿' + '\n' : scr_table
scr_table := u02 != false and signalSELL02 ? scr_table + s02 + ' ⦿' + '\n' : scr_table
scr_table := u03 != false and signalSELL03 ? scr_table + s03 + ' ⦿' + '\n' : scr_table
scr_table := u04 != false and signalSELL04 ? scr_table + s04 + ' ⦿' + '\n' : scr_table
scr_table := u05 != false and signalSELL05 ? scr_table + s05 + ' ⦿' + '\n' : scr_table
scr_table := u06 != false and signalSELL06 ? scr_table + s06 + ' ⦿' + '\n' : scr_table
scr_table := u07 != false and signalSELL07 ? scr_table + s07 + ' ⦿' + '\n' : scr_table
scr_table := u08 != false and signalSELL08 ? scr_table + s08 + ' ⦿' + '\n' : scr_table
scr_table := u09 != false and signalSELL09 ? scr_table + s09 + ' ⦿' + '\n' : scr_table
scr_table := u10 != false and signalSELL10 ? scr_table + s10 + ' ⦿' + '\n' : scr_table
scr_table := u11 != false and signalSELL11 ? scr_table + s11 + ' ⦿' + '\n' : scr_table
scr_table := u12 != false and signalSELL12 ? scr_table + s12 + ' ⦿' + '\n' : scr_table
scr_table := u13 != false and signalSELL13 ? scr_table + s13 + ' ⦿' + '\n' : scr_table
scr_table := u14 != false and signalSELL14 ? scr_table + s14 + ' ⦿' + '\n' : scr_table
scr_table := u15 != false and signalSELL15 ? scr_table + s15 + ' ⦿' + '\n' : scr_table
scr_table := u16 != false and signalSELL16 ? scr_table + s16 + ' ⦿' + '\n' : scr_table
scr_table := u17 != false and signalSELL17 ? scr_table + s17 + ' ⦿' + '\n' : scr_table
scr_table := u18 != false and signalSELL18 ? scr_table + s18 + ' ⦿' + '\n' : scr_table
scr_table := u19 != false and signalSELL19 ? scr_table + s19 + ' ⦿' + '\n' : scr_table
scr_table := u20 != false and signalSELL20 ? scr_table + s20 + ' ⦿' + '\n' : scr_table
scr_table := u21 != false and signalSELL21 ? scr_table + s21 + ' ⦿' + '\n' : scr_table
scr_table := u22 != false and signalSELL22 ? scr_table + s22 + ' ⦿' + '\n' : scr_table
scr_table := u23 != false and signalSELL23 ? scr_table + s23 + ' ⦿' + '\n' : scr_table
scr_table := u24 != false and signalSELL24 ? scr_table + s24 + ' ⦿' + '\n' : scr_table
scr_table := u25 != false and signalSELL25 ? scr_table + s25 + ' ⦿' + '\n' : scr_table
scr_table := u26 != false and signalSELL26 ? scr_table + s26 + ' ⦿' + '\n' : scr_table
scr_table := u27 != false and signalSELL27 ? scr_table + s27 + ' ⦿' + '\n' : scr_table
scr_table := u28 != false and signalSELL28 ? scr_table + s28 + ' ⦿' + '\n' : scr_table
scr_table := u29 != false and signalSELL29 ? scr_table + s29 + ' ⦿' + '\n' : scr_table
scr_table := u30 != false and signalSELL30 ? scr_table + s30 + ' ⦿' + '\n' : scr_table
scr_table := u31 != false and signalSELL31 ? scr_table + s31 + ' ⦿' + '\n' : scr_table
scr_table := u32 != false and signalSELL32 ? scr_table + s32 + ' ⦿' + '\n' : scr_table
scr_table := u33 != false and signalSELL33 ? scr_table + s33 + ' ⦿' + '\n' : scr_table
scr_table := u34 != false and signalSELL34 ? scr_table + s34 + ' ⦿' + '\n' : scr_table
scr_table := u35 != false and signalSELL35 ? scr_table + s35 + ' ⦿' + '\n' : scr_table
scr_table := u36 != false and signalSELL36 ? scr_table + s36 + ' ⦿' + '\n' : scr_table
scr_table := u37 != false and signalSELL37 ? scr_table + s37 + ' ⦿' + '\n' : scr_table
scr_table := u38 != false and signalSELL38 ? scr_table + s38 + ' ⦿' + '\n' : scr_table
scr_table := u39 != false and signalSELL39 ? scr_table + s39 + ' ⦿' + '\n' : scr_table
//scr_table := u40 != false and signalSELL40 ? scr_table + s40 + ' ⦿' + '\n' : scr_table
//////////
// Plot Cloud of current symbol
// Cloud
colortrend = color.from_gradient(oEMA5, minEMA, maxEMA, upperColor, lowerColor)
colorCloud  = color.from_gradient(cBunch, 0, iBunch, bunchColor, colortrend)
upperCloud =  plot(boolCloud == true ? maxEMA : na, "Upper Cloud", color.new(#d1d4dc, 100), offset = 1)
lowerCloud = plot(boolCloud == true ? minEMA : na, "Lower Cloud", color.new(#d1d4dc, 100), offset = 1)
fill(upperCloud, lowerCloud, color = boolCloud == false ?  na : colorCloud , title="Fill Cloud")

// Plot Signal
currentBUY = signalBUY and not signalBUY[1] and not signalBUY[2]
currentSELL = signalSELL and not signalSELL[1] and not signalSELL[2]
plotshape(currentBUY, title = "Shape Buy", style=shape.triangleup, location=location.belowbar, color = #4caf50, text = "", textcolor = color.white, size = size.tiny)
plotshape(currentSELL, title = "Shape Sell", style=shape.triangledown, location=location.abovebar, color = #f23645, text = "", textcolor = color.white, size = size.tiny)

// Plot table //
if boolTable
    var tbl = table.new(TablePosition(pos), 1, 2, frame_color=#151715, frame_width=1, border_width=1, border_color=color.new(color.white, 100))
    table.cell(tbl, 0, 0, 'Signal on Timeframe: ' + timeframe, text_halign = text.align_center, bgcolor = color.black, text_color = color.white, text_size = size.small)
    table.cell(tbl, 0, 1, scr_table, text_halign = text.align_right, bgcolor = color.black, text_color = signalBUY ? color.green : signalSELL ? color.red : color.white, text_size = size.small)

//Screener Alert
scr_alertBUY = ''
//Signal BUY
scr_alertBUY := u01 != false and signalBUY01 ? scr_alertBUY + s01 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u02 != false and signalBUY02 ? scr_alertBUY + s02 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u03 != false and signalBUY03 ? scr_alertBUY + s03 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u04 != false and signalBUY04 ? scr_alertBUY + s04 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u05 != false and signalBUY05 ? scr_alertBUY + s05 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u06 != false and signalBUY06 ? scr_alertBUY + s06 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u07 != false and signalBUY07 ? scr_alertBUY + s07 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u08 != false and signalBUY08 ? scr_alertBUY + s08 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u09 != false and signalBUY09 ? scr_alertBUY + s09 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u10 != false and signalBUY10 ? scr_alertBUY + s10 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u11 != false and signalBUY11 ? scr_alertBUY + s11 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u12 != false and signalBUY12 ? scr_alertBUY + s12 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u13 != false and signalBUY13 ? scr_alertBUY + s13 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u14 != false and signalBUY14 ? scr_alertBUY + s14 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u15 != false and signalBUY15 ? scr_alertBUY + s15 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u16 != false and signalBUY16 ? scr_alertBUY + s16 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u17 != false and signalBUY17 ? scr_alertBUY + s17 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u18 != false and signalBUY18 ? scr_alertBUY + s18 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u19 != false and signalBUY19 ? scr_alertBUY + s19 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u20 != false and signalBUY20 ? scr_alertBUY + s20 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u21 != false and signalBUY21 ? scr_alertBUY + s21 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u22 != false and signalBUY22 ? scr_alertBUY + s22 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u23 != false and signalBUY23 ? scr_alertBUY + s23 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u24 != false and signalBUY24 ? scr_alertBUY + s24 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u25 != false and signalBUY25 ? scr_alertBUY + s25 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u26 != false and signalBUY26 ? scr_alertBUY + s26 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u27 != false and signalBUY27 ? scr_alertBUY + s27 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u28 != false and signalBUY28 ? scr_alertBUY + s28 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u29 != false and signalBUY29 ? scr_alertBUY + s29 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u30 != false and signalBUY30 ? scr_alertBUY + s30 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u31 != false and signalBUY31 ? scr_alertBUY + s31 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u32 != false and signalBUY32 ? scr_alertBUY + s32 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u33 != false and signalBUY33 ? scr_alertBUY + s33 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u34 != false and signalBUY34 ? scr_alertBUY + s34 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u35 != false and signalBUY35 ? scr_alertBUY + s35 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u36 != false and signalBUY36 ? scr_alertBUY + s36 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u37 != false and signalBUY37 ? scr_alertBUY + s37 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u38 != false and signalBUY38 ? scr_alertBUY + s38 + ' - BUY' + '\n' : scr_alertBUY
scr_alertBUY := u39 != false and signalBUY39 ? scr_alertBUY + s39 + ' - BUY' + '\n' : scr_alertBUY
//scr_alertBUY := u40 != false and signalBUY40 ? scr_alertBUY + s40 + ' - BUY' + '\n' : scr_alertBUY

//Signal SELL
scr_alertSELL = ''
scr_alertSELL := u01 != false and signalSELL01 ? scr_alertSELL + s01 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u02 != false and signalSELL02 ? scr_alertSELL + s02 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u03 != false and signalSELL03 ? scr_alertSELL + s03 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u04 != false and signalSELL04 ? scr_alertSELL + s04 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u05 != false and signalSELL05 ? scr_alertSELL + s05 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u06 != false and signalSELL06 ? scr_alertSELL + s06 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u07 != false and signalSELL07 ? scr_alertSELL + s07 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u08 != false and signalSELL08 ? scr_alertSELL + s08 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u09 != false and signalSELL09 ? scr_alertSELL + s09 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u10 != false and signalSELL10 ? scr_alertSELL + s10 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u11 != false and signalSELL11 ? scr_alertSELL + s11 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u12 != false and signalSELL12 ? scr_alertSELL + s12 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u13 != false and signalSELL13 ? scr_alertSELL + s13 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u14 != false and signalSELL14 ? scr_alertSELL + s14 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u15 != false and signalSELL15 ? scr_alertSELL + s15 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u16 != false and signalSELL16 ? scr_alertSELL + s16 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u17 != false and signalSELL17 ? scr_alertSELL + s17 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u18 != false and signalSELL18 ? scr_alertSELL + s18 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u19 != false and signalSELL19 ? scr_alertSELL + s19 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u20 != false and signalSELL20 ? scr_alertSELL + s20 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u21 != false and signalSELL21 ? scr_alertSELL + s21 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u22 != false and signalSELL22 ? scr_alertSELL + s22 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u23 != false and signalSELL23 ? scr_alertSELL + s23 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u24 != false and signalSELL24 ? scr_alertSELL + s24 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u25 != false and signalSELL25 ? scr_alertSELL + s25 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u26 != false and signalSELL26 ? scr_alertSELL + s26 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u27 != false and signalSELL27 ? scr_alertSELL + s27 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u28 != false and signalSELL28 ? scr_alertSELL + s28 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u29 != false and signalSELL29 ? scr_alertSELL + s29 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u30 != false and signalSELL30 ? scr_alertSELL + s30 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u31 != false and signalSELL31 ? scr_alertSELL + s31 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u32 != false and signalSELL32 ? scr_alertSELL + s32 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u33 != false and signalSELL33 ? scr_alertSELL + s33 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u34 != false and signalSELL34 ? scr_alertSELL + s34 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u35 != false and signalSELL35 ? scr_alertSELL + s35 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u36 != false and signalSELL36 ? scr_alertSELL + s36 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u37 != false and signalSELL37 ? scr_alertSELL + s37 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u38 != false and signalSELL38 ? scr_alertSELL + s38 + ' - SELL' + '\n' : scr_alertSELL
scr_alertSELL := u39 != false and signalSELL39 ? scr_alertSELL + s39 + ' - SELL' + '\n' : scr_alertSELL
//scr_alertSELL := u40 != false and signalSELL40 ? scr_alertSELL + s40 + ' - SELL' + '\n' : scr_alertSELL

// Send alert only if screener is not empty
if (scr_alertBUY != '') and boolSignalAlert != "SELL"
    alert(scr_alertBUY + '\n([5ema.vn] - Timeframe: ' + timeframe + ')', freq = alert.freq_once_per_bar_close)
if (scr_alertSELL != '') and boolSignalAlert != "BUY"
    alert(scr_alertSELL + '\n([5ema.vn] - Timeframe: ' + timeframe + ')', freq = alert.freq_once_per_bar_close)   



  
    
    