Dominator Plus- Darshan Hirpara
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dominator Plus- Darshan Hirpara

//@version=4
study(title="Dominator Plus- Darshan Hirpara", shorttitle="Dominator Plus", precision=2,max_bars_back=200)

    // This indicator is a modified version of the TradingView "Technicals Ratings" indicator. 
    // The technical indicators were not changes even their parameters as well
    
    
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 INPUTS AND GLOBAL VARIABLES DECLARATION                                                //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

//-----------------------------------------------------------------------------------------------------------------------------------------------------//
//                                                                  -   ASSETS AND RESOLUTIONS                                                        //{
res_1 =             input( defval="60",                 title="Resolution 1",   group="Resolution",     inline='resolutions',  type=input.resolution   )
res_2 =             input( defval="240",                title="Resolution 2",   group="Resolution",     inline='resolutions',  type=input.resolution   )
res_3 =             input( defval="D",                  title="Resolution 3",   group="Resolution",     inline='resolutions',  type=input.resolution   )
switch=             input( defval= false,               title='Second set?',    group="Resolution",     inline='resolutions',  type=input.bool         )
asset_01=not switch?input( defval="BINANCE:HOTUSDT",    title="Asset 01",       group="Assets set 1",   inline='A1',   type=input.symbol ): input( defval="BINANCE:NBSUSDT",   title="Asset 13",   group="Assets set 2",    inline='B1',    type=input.symbol ) 
asset_02=not switch?input( defval="BINANCE:MKRUSDT",    title="Asset 02",       group="Assets set 1",   inline='A1',   type=input.symbol ): input( defval="BINANCE:PERLUSDT",  title="Asset 14",   group="Assets set 2",    inline='B1',    type=input.symbol ) 
asset_03=not switch?input( defval="BINANCE:MATICUSDT",  title="Asset 03",       group="Assets set 1",   inline='A2',   type=input.symbol ): input( defval="BINANCE:STORJUSDT", title="Asset 15",   group="Assets set 2",    inline='B2',    type=input.symbol )  
asset_04=not switch?input( defval="BINANCE:NEOUSDT",    title="Asset 04",       group="Assets set 1",   inline='A2',   type=input.symbol ): input( defval="BINANCE:DODOUSDT",  title="Asset 16",   group="Assets set 2",    inline='B2',    type=input.symbol )  
asset_05=not switch?input( defval="BINANCE:VETUSDT",    title="Asset 05",       group="Assets set 1",   inline='A3',   type=input.symbol ): input( defval="BINANCE:AUDIOUSDT", title="Asset 17",   group="Assets set 2",    inline='B3',    type=input.symbol )  
asset_06=not switch?input( defval="BINANCE:DENTUSDT",   title="Asset 06",       group="Assets set 1",   inline='A3',   type=input.symbol ): input( defval="BINANCE:ETHUSDT",   title="Asset 18",   group="Assets set 2",    inline='B3',    type=input.symbol )  
asset_07=not switch?input( defval="BINANCE:AXSUSDT",    title="Asset 07",       group="Assets set 1",   inline='A4',   type=input.symbol ): input( defval="BINANCE:BTCUSDT",   title="Asset 19",   group="Assets set 2",    inline='B4',    type=input.symbol )  
asset_08=not switch?input( defval="BINANCE:NBSUSDT",    title="Asset 08",       group="Assets set 1",   inline='A4',   type=input.symbol ): input( defval="BINANCE:CHZUSDT",   title="Asset 20",   group="Assets set 2",    inline='B4',    type=input.symbol )  
asset_09=not switch?input( defval="BINANCE:ADAUSDT",    title="Asset 09",       group="Assets set 1",   inline='A5',   type=input.symbol ): input( defval="BINANCE:FTMUSDT",   title="Asset 21",   group="Assets set 2",    inline='B5',    type=input.symbol )  
asset_10=not switch?input( defval="BINANCE:SOLUSDT",    title="Asset 10",       group="Assets set 1",   inline='A5',   type=input.symbol ): input( defval="BINANCE:ONEUSDT",   title="Asset 22",   group="Assets set 2",    inline='B5',    type=input.symbol )  
asset_11=not switch?input( defval="BINANCE:WINUSDT",    title="Asset 11",       group="Assets set 1",   inline='A6',   type=input.symbol ): input( defval="BINANCE:XVSUSDT",   title="Asset 23",   group="Assets set 2",    inline='B6',    type=input.symbol )  
asset_12=not switch?input( defval="BINANCE:MTLUSDT",    title="Asset 12",       group="Assets set 1",   inline='A6',   type=input.symbol ): input( defval="BINANCE:DOGEUSDT",  title="Asset 24",   group="Assets set 2",    inline='B6',    type=input.symbol )  
//}
//-----------------------------------------------------------------------------------------------------------------------------------------------------//
//                                                                  -   ANALYSIS AND VISUALIZATION                                                    //{
ratingSignal=   input( defval="All",        title="Rating base",    group="Analysis and visualization", inline='table ration',  type=input.string, options = ["MAs", "Oscillators", "All"]  )
poscol=         input( defval=color.green,  title="Buy Color",      group="Analysis and visualization", inline='Colors',        type=input.color                                            )
neutralcolor=   input( defval=color.yellow, title="Neutral Color",  group="Analysis and visualization", inline='Colors',        type=input.color                                            )
negcol=         input( defval=color.red,    title="Sell Color",     group="Analysis and visualization", inline='Colors',        type=input.color                                            )
//}
//-----------------------------------------------------------------------------------------------------------------------------------------------------//
//                                                                  -   TABLE SETTINGS                                                                //{
//                                                                              -   Table position                                                    //{                                                                                                                                                                                                                                                                                                               
tbl_rows=               input( defval=4 ,           title='Table rows',             group="Table position",                         inline='rows',              type=input.integer,                                             options=[3,4,6,12]                                      )
hide_infoboard=         input( defval=false,        title="hide",                   group="Table position",                         inline="rows",              type=input.bool                                                                                                         )
pos_y_infoboard=        input( defval="top",        title='Infoboard',              group="Table position",                         inline="Infoboard",         type=input.string,                                              options=["top", "middle", "bottom"]                     )
pos_x_infoboard=        input( defval="right",      title='Infoboard',              group="Table position",                         inline="Infoboard",         type=input.string,                                              options=['left', 'center', 'right']                     )
//}                                                                                                                                                                                                                                                                                     
//                                                                              -   Table colors                                                      //{                                                                                                                              
border_color=           input( defval=color.silver, title="Border color",           group="Table settings",                         inline="Border color",      type=input.color                                                                                                        )
border_trans=           input( defval=50,           title="transparency",           group="Table settings",                         inline="Border color",      type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
border_width=           input( defval=1,            title="width",                  group="Table settings",                         inline="Border color",      type=input.integer,     minval=0,   maxval=3,       step=1                                                              )
frame_color=            input( defval=color.black,  title="Frame color",            group="Table settings",                         inline="Frame color",       type=input.color                                                                                                        )
frame_trans=            input( defval=10,           title="transparency",           group="Table settings",                         inline="Frame color",       type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
frame_width=            input( defval=2,            title="width",                  group="Table settings",                         inline="Frame color",       type=input.integer,     minval=0,   maxval=5,       step=1                                                              )
//}                                                                                                                                                                                                                                                                                         
//                                                                              -   Header column                                                     //{                                                                                                                                                                                                                 
bgcolor_c=              input( defval=color.gray,   title="Head col color",         group="Header columns",                         inline="Column color",      type=input.color                                                                                                        )
bgtrans_c=              input( defval=20,           title="transparency",           group="Header columns",                         inline="Column color",      type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_color_c=           input( defval=color.white,  title="Font color",             group="Header columns",                         inline="Column font",       type=input.color                                                                                                        )
font_trans_c=           input( defval=0,            title="transparency",           group="Header columns",                         inline="Column font",       type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_size_c=            input( defval="small",      title="size",                   group="Header columns",                         inline="Column font",       type=input.string,                                              options=["auto","tiny","small","normal","large","huge"] )
halign_c=               input( defval='center',     title="Horizontal alignment",   group="Header columns",                         inline="Column align",      type=input.string,                                              options=['left', 'center', 'right']                     )
//}                                                                                                                                                                                                                                                                                     
//                                                                              -   Header row                                                        //{                                                                                                                              
bgcolor_r=              input( defval=color.white,  title="Head row color",         group="Header rows",                            inline="Row color",         type=input.color                                                                                                        )
bgtrans_r=              input( defval=0,            title="transparency",           group="Header rows",                            inline="Row color",         type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_color_r=           input( defval=color.black,  title="Font color",             group="Header rows",                            inline="Row font",          type=input.color                                                                                                        )
font_trans_r=           input( defval=0,            title="transparency",           group="Header rows",                            inline="Row font",          type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_size_r=            input( defval="small",      title="size",                   group="Header rows",                            inline="Row font",          type=input.string,                                              options=["auto","tiny","small","normal","large","huge"] )
halign_r=               input( defval='left',       title="Horizontal alignment",   group="Header rows",                            inline="Row align",         type=input.string,                                              options=['left', 'center', 'right']                     )
//}                                                                                                                                                                                                                                                                                         
//                                                                              -   Cells                                                             //{                                                                                                                                                                                                                 
bgcolor=                input( defval=color.black,  title="Cell color",             group="Cell settings",                          inline="BG color",          type=input.color                                                                                                        )
bgtrans=                input( defval=20,           title="transparency",           group="Cell settings",                          inline="BG color",          type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_color=             input( defval=color.white,  title="Font color",             group="Cell settings",                          inline="Font color",        type=input.color                                                                                                        )
font_trans=             input( defval=20,           title="transparency",           group="Cell settings",                          inline="Font color",        type=input.integer,     minval=0,   maxval=100,     step=10                                                             )
font_size=              input( defval="small",      title="size",                   group="Cell settings",                          inline="Font color",        type=input.string,                                              options=["auto","tiny","small","normal","large","huge"] )
halign=                 input( defval='center',     title="Horizontal alignment",   group="Cell settings",                          inline="Font align",        type=input.string,                                              options=['left', 'center', 'right']                     )
//}
//                                                                              -   Global variables                                                  //{                                                                                                                                                                                                                 
var int tbl_columns=    12/tbl_rows                                                                                                                    //}
//}
//-----------------------------------------------------------------------------------------------------------------------------------------------------//}

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 FUNCTIONS: GENERAL                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

//-----------------------------------------------------------------------------------------------------------------------------------------------------//
//                                                                  -   Generate size proverty form string                                            //{

f_size(f_size_name) =>
    if f_size_name == "tiny"
        size.tiny
    else if f_size_name == "small"
        size.small
    else if f_size_name == "normal"
        size.normal
    else if f_size_name == "large"
        size.large
    else if f_size_name == "huge"
        size.huge
    else
        size.auto
//}
//-----------------------------------------------------------------------------------------------------------------------------------------------------//
//                                                                  -   Generate alignment proverty form string                                       //{

f_align(f_align_name) =>
    if f_align_name == "left"
        text.align_left
    else if f_align_name == "right"
        text.align_right
    else
        text.align_center
//}
//-----------------------------------------------------------------------------------------------------------------------------------------------------//}

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 TABLE INITIALIZATION                                                                   //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//  CREATE TABLE                 PROPERTY                                       VALUE                                                                                                                                                                          //{        
var infoboard = table.new(
                             position=          pos_y_infoboard+"_"+pos_x_infoboard,
                             columns=           50,
                             rows=              200,
                             border_color =     color.new(border_color,border_trans),
                             border_width =     border_width,
                             frame_color =      color.new(frame_color,frame_trans),
                             frame_width =      frame_width,
                             bgcolor=           color.new(bgcolor,bgtrans) 
                          )
//}
  //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 //  CREATE HEADER       TABLE      COLUMNS   ROWS.  VALUE                BACKGROUNG COLOR                        TEXT COLOR                                       HORIZONTAL ALIGNMENT.             TEXT SIZE                         VERTICAL ALIGNMENT      //{
if barstate.isfirst and not hide_infoboard
    table.cell (table_id=infoboard, column=0, row=0, text="Factors",      bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c), text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
    table.cell (table_id=infoboard, column=1, row=0, text="Assets",       bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c), text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
    table.cell (table_id=infoboard, column=2, row=0, text="Res: "+res_1,  bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c), text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
    table.cell (table_id=infoboard, column=3, row=0, text="Res: "+res_2,  bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c), text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
    table.cell (table_id=infoboard, column=4, row=0, text="Res: "+res_3,  bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c), text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)    

//}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  //}

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 TECHNICAL RATINGS CALCULATION                                                          //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

StrongBound = 0.5
WeakBound = 0.1


count_rising(plot) =>
    v_plot = plot > 0 ? plot : -plot
    var count = 0
    if v_plot == 0
        count := 0
    else if v_plot >= v_plot[1]
        count := min(5, count + 1)
    else if v_plot < v_plot[1]
        count := max(1, count - 1)
    count

f_position_condition(f_tradeSignal)=>
    f_poscond = f_tradeSignal > WeakBound
    f_negcond = f_tradeSignal < -WeakBound
    f_posseries = f_poscond ? f_tradeSignal : 0
    f_negseries = f_negcond ? f_tradeSignal : 0
    f_poscount = count_rising(f_posseries)
    f_negcount = count_rising(f_negseries)
    f_pc = f_poscond ? f_poscount : f_negcond ? f_negcount : 0
    [f_poscond,f_negcond,f_posseries,f_negseries,f_poscount,f_negcount,f_pc]

getTimeOfNextBar() =>
    currentTime = time(timeframe.period)
    changeTime = change(currentTime)
    minChange = if (not na(changeTime))
        var float minChange = changeTime
        minChange := min(minChange, changeTime)
    int(currentTime + minChange)


calcRatingStatus(value) =>
    if -StrongBound > value
        "Strong Sell"
    else if value < -WeakBound
        "Sell"
    else if value > StrongBound
        "Strong Buy"
    else if value > WeakBound
        "Buy"
    else
        "Neutral"

getSignal(ratingTotal_1, ratingOther, ratingMA) =>
    float _res = ratingTotal_1
    if ratingSignal == "MAs"
        _res := ratingMA
    if ratingSignal == "Oscillators"
        _res := ratingOther
    _res


f_color(f_tradeSignal)=>
    f_col_buy = color.from_gradient(f_tradeSignal, 0.0, 0.2, neutralcolor, poscol)
    f_col_sell = color.from_gradient(f_tradeSignal, -0.2, 0.0, negcol, neutralcolor)
    f_col_gradient = color.from_gradient(f_tradeSignal, -0.2, 0.2, f_col_sell, f_col_buy)
    f_col_gradient





colorTransp(col, transp) =>
    red = color.r(col)
    green = color.g(col)
    blue = color.b(col)
    color.rgb(red, green, blue, transp)



// Awesome Oscillator
AO() => 
    sma(hl2, 5) - sma(hl2, 34)
// Stochastic RSI
StochRSI() =>
    rsi1 = rsi(close, 14)
    K = sma(stoch(rsi1, rsi1, rsi1, 14), 3)
    D = sma(K, 3)
    [K, D]
// Ultimate Oscillator
tl() => close[1] < low ? close[1]: low
uo(ShortLen, MiddlLen, LongLen) =>
    Value1 = sum(tr, ShortLen)
    Value2 = sum(tr, MiddlLen)
    Value3 = sum(tr, LongLen)
    Value4 = sum(close - tl(), ShortLen)
    Value5 = sum(close - tl(), MiddlLen)
    Value6 = sum(close - tl(), LongLen)
    float UO = na
    if Value1 != 0 and Value2 != 0 and Value3 != 0
        var0 = LongLen / ShortLen
        var1 = LongLen / MiddlLen
        Value7 = (Value4 / Value1) * (var0)
        Value8 = (Value5 / Value2) * (var1)
        Value9 = (Value6 / Value3)
        UO := (Value7 + Value8 + Value9) / (var0 + var1 + 1)
    UO
// Ichimoku Cloud
donchian(len) => avg(lowest(len), highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = avg(conversionLine, baseLine)
    leadLine2 = donchian(52)
    [conversionLine, baseLine, leadLine1, leadLine2]
    
calcRatingMA(ma, src) => na(ma) or na(src) ? na : (ma == src ? 0 : ( ma < src ? 1 : -1 ))
calcRating(buy, sell) => buy ? 1 : ( sell ? -1 : 0 )


f_drawInfo(f_ratingTotal,f_ratingOther,f_ratingMA,f_ratingOtherC,f_ratingMAC,f_tradeSignal)=>
    f_MAText = f_ratingMAC == 0 ? "" : calcRatingStatus(f_ratingMA) + "\n"
    f_OtherText = f_ratingOtherC == 0 ? "" : calcRatingStatus(f_ratingOther) + "\n"
    f_TotaText =  calcRatingStatus(f_ratingTotal)
    [f_poscond,f_negcond,f_posseries,f_negseries,f_poscount,f_negcount,f_pc]=   f_position_condition(f_tradeSignal)
    info_text= f_MAText+ f_OtherText + f_TotaText
    info_text


calcRatingAll() =>
    //============== MA =================
    SMA10 = sma(close, 10)
    SMA20 = sma(close, 20)
    SMA30 = sma(close, 30)
    SMA50 = sma(close, 50)
    SMA100 = sma(close, 100)
    SMA200 = sma(close, 200)
    
    EMA10 = ema(close, 10)
    EMA20 = ema(close, 20)
    EMA30 = ema(close, 30)
    EMA50 = ema(close, 50)
    EMA100 = ema(close, 100)
    EMA200 = ema(close, 200)
    
    HullMA9 = hma(close, 9)
    
    // Volume Weighted Moving Average (VWMA)
    VWMA = vwma(close, 20)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()
    
    // ======= Other =============
    // Relative Strength Index, RSI
    RSI = rsi(close,14)
    
    // Stochastic
    lengthStoch = 14
    smoothKStoch = 3
    smoothDStoch = 3
    kStoch = sma(stoch(close, high, low, lengthStoch), smoothKStoch)
    dStoch = sma(kStoch, smoothDStoch)
    
    // Commodity Channel Index, CCI
    CCI = cci(close, 20)
    
    // Average Directional Index
    float adxValue = na, float adxPlus = na, float adxMinus = na
    [P, M, V] = dmi(14, 14)
    adxValue := V
    adxPlus := P
    adxMinus := M
    // Awesome Oscillator
    ao = AO()
    
    // Momentum
    Mom = mom(close, 10)
    // Moving Average Convergence/Divergence, MACD
    [macdMACD, signalMACD, _] = macd(close, 12, 26, 9)
    // Stochastic RSI
    [Stoch_RSI_K, Stoch_RSI_D] = StochRSI()
    // Williams Percent Range
    WR = wpr(14)
    
    // Bull / Bear Power
    BullPower = high - ema(close, 13)
    BearPower = low - ema(close, 13)
    // Ultimate Oscillator
    UO = uo(7,14,28)
    if not na(UO)
        UO := UO * 100
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    PriceAvg = ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0
    
    if not na(SMA10)
        ratingMA := ratingMA + calcRatingMA(SMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA20)
        ratingMA := ratingMA + calcRatingMA(SMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA30)
        ratingMA := ratingMA + calcRatingMA(SMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA50)
        ratingMA := ratingMA + calcRatingMA(SMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA100)
        ratingMA := ratingMA + calcRatingMA(SMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA200)
        ratingMA := ratingMA + calcRatingMA(SMA200, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA10)
        ratingMA := ratingMA + calcRatingMA(EMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA20)
        ratingMA := ratingMA + calcRatingMA(EMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA30)
        ratingMA := ratingMA + calcRatingMA(EMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA50)
        ratingMA := ratingMA + calcRatingMA(EMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA100)
        ratingMA := ratingMA + calcRatingMA(EMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA200)
        ratingMA := ratingMA + calcRatingMA(EMA200, close)
        ratingMAC := ratingMAC + 1
    
    if not na(HullMA9)
        ratingHullMA9 = calcRatingMA(HullMA9, close)
        ratingMA := ratingMA + ratingHullMA9
        ratingMAC := ratingMAC + 1
    
    if not na(VWMA)
        ratingVWMA = calcRatingMA(VWMA, close)
        ratingMA := ratingMA + ratingVWMA
        ratingMAC := ratingMAC + 1
    
    float ratingIC = na
    if not (na(IC_Lead1) or na(IC_Lead2) or na(close) or na(close[1]) or na(IC_BLine) or na(IC_CLine))
        ratingIC := calcRating(
         IC_Lead1 > IC_Lead2 and close > IC_Lead1 and close < IC_BLine and close[1] < IC_CLine and close > IC_CLine,
         IC_Lead2 > IC_Lead1 and close < IC_Lead2 and close > IC_BLine and close[1] > IC_CLine and close < IC_CLine)
    if not na(ratingIC)
        ratingMA := ratingMA + ratingIC
        ratingMAC := ratingMAC + 1
    
    ratingMA := ratingMAC > 0 ? ratingMA / ratingMAC : na
    
    float ratingOther = 0
    float ratingOtherC = 0
    
    ratingRSI = RSI
    if not(na(ratingRSI) or na(ratingRSI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingRSI < 30 and ratingRSI[1] < ratingRSI, ratingRSI > 70 and ratingRSI[1] > ratingRSI)
    
    if not(na(kStoch) or na(dStoch) or na(kStoch[1]) or na(dStoch[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(kStoch < 20 and dStoch < 20 and kStoch > dStoch and kStoch[1] < dStoch[1], kStoch > 80 and dStoch > 80 and kStoch < dStoch and kStoch[1] > dStoch[1])
    
    ratingCCI = CCI
    if not(na(ratingCCI) or na(ratingCCI[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(ratingCCI < -100 and ratingCCI > ratingCCI[1], ratingCCI > 100 and ratingCCI < ratingCCI[1])
    
    if not(na(adxValue) or na(adxPlus[1]) or na(adxMinus[1]) or na(adxPlus) or na(adxMinus))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(adxValue > 20 and adxPlus[1] < adxMinus[1] and adxPlus > adxMinus, adxValue > 20 and adxPlus[1] > adxMinus[1] and adxPlus < adxMinus)
    
    if not(na(ao) or na(ao[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(crossover(ao,0) or (ao > 0 and ao[1] > 0 and ao > ao[1] and ao[2] > ao[1]), crossunder(ao,0) or (ao < 0 and ao[1] < 0 and ao < ao[1] and ao[2] < ao[1]))
    
    if not(na(Mom) or na(Mom[1]))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(Mom > Mom[1], Mom < Mom[1])
    
    if not(na(macdMACD) or na(signalMACD))
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + calcRating(macdMACD > signalMACD, macdMACD < signalMACD)
    
    float ratingStoch_RSI = na
    if not(na(DownTrend) or na(UpTrend) or na(Stoch_RSI_K) or na(Stoch_RSI_D) or na(Stoch_RSI_K[1]) or na(Stoch_RSI_D[1]))
        ratingStoch_RSI := calcRating(
         DownTrend and Stoch_RSI_K < 20 and Stoch_RSI_D < 20 and Stoch_RSI_K > Stoch_RSI_D and Stoch_RSI_K[1] < Stoch_RSI_D[1],
         UpTrend and Stoch_RSI_K > 80 and Stoch_RSI_D > 80 and Stoch_RSI_K < Stoch_RSI_D and Stoch_RSI_K[1] > Stoch_RSI_D[1])
    if not na(ratingStoch_RSI)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingStoch_RSI
    
    float ratingWR = na
    if not(na(WR) or na(WR[1]))
        ratingWR := calcRating(WR < -80 and WR > WR[1], WR > -20 and WR < WR[1])
    if not na(ratingWR)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingWR
    
    float ratingBBPower = na
    if not(na(UpTrend) or na(DownTrend) or na(BearPower) or na(BearPower[1]) or na(BullPower) or na(BullPower[1]))
        ratingBBPower := calcRating(
         UpTrend and BearPower < 0 and BearPower > BearPower[1],
         DownTrend and BullPower > 0 and BullPower < BullPower[1])
    if not na(ratingBBPower)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingBBPower
    
    float ratingUO = na
    if not(na(UO))
        ratingUO := calcRating(UO > 70, UO < 30)
    if not na(ratingUO)
        ratingOtherC := ratingOtherC + 1
        ratingOther := ratingOther + ratingUO
    
    ratingOther := ratingOtherC > 0 ? ratingOther / ratingOtherC : na
    
    float ratingTotal = 0
    float ratingTotalC = 0
    if not na(ratingMA)
        ratingTotal := ratingTotal + ratingMA
        ratingTotalC := ratingTotalC + 1
    if not na(ratingOther)
        ratingTotal := ratingTotal + ratingOther
        ratingTotalC := ratingTotalC + 1
    ratingTotal := ratingTotalC > 0 ? ratingTotal / ratingTotalC : na
    
    
    
    [ratingTotal,ratingOther,ratingMA,ratingOtherC,ratingMAC] 

f_security(f_tickerid, f_resolution)=>
    [ratingTotal_low,ratingOther_low,ratingMA_low,ratingOtherC_low,ratingMAC_low]=security(f_tickerid, f_resolution, calcRatingAll())

//}

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 SECURITY CALL AND UPDATE TABLE                                                         //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

f_fill_table(f_ticker,i)=>

    [ratingTotal_low,ratingOther_low,ratingMA_low,ratingOtherC_low,ratingMAC_low]=      security(f_ticker, res_1, calcRatingAll())
    [ratingTotal_mid,ratingOther_mid,ratingMA_mid,ratingOtherC_mid,ratingMAC_mid]=      security(f_ticker, res_2, calcRatingAll())
    [ratingTotal_high,ratingOther_high,ratingMA_high,ratingOtherC_high,ratingMAC_high]= security(f_ticker, res_3, calcRatingAll())

    tradeSignal_low = getSignal(ratingTotal_low, ratingOther_low, ratingMA_low)
    info_text_low = f_drawInfo(ratingTotal_low,ratingOther_low,ratingMA_low,ratingOtherC_low,ratingMAC_low,tradeSignal_low)
    col_gradient_low = f_color(tradeSignal_low)
    
    tradeSignal_mid = getSignal(ratingTotal_mid, ratingOther_mid, ratingMA_mid)
    info_text_mid = f_drawInfo(ratingTotal_mid,ratingOther_mid,ratingMA_mid,ratingOtherC_mid,ratingMAC_mid,tradeSignal_mid)
    col_gradient_mid = f_color(tradeSignal_mid)
    
    tradeSignal_high = getSignal(ratingTotal_high, ratingOther_high, ratingMA_high)
    info_text_high = f_drawInfo(ratingTotal_high,ratingOther_high,ratingMA_high,ratingOtherC_high,ratingMAC_high,tradeSignal_high)
    col_gradient_high = f_color(tradeSignal_high)

    f_ticker_id=str.replace_all(f_ticker,"BINANCE:","")
    ci=floor((i-1)/tbl_rows)*4
    ri=i-int((i-1)/tbl_rows)*tbl_rows
    
    if ci==0   
        table.cell  (table_id=infoboard,    column=0,      row=i,        text="Moving Averages\nOscillators\nAll", bgcolor=color.new(color.silver,bgtrans_r), text_color=color.new(font_color_r,font_trans_r),    text_halign=text.align_left,    text_size=f_size(font_size_r),    text_valign=text.align_center)

    if i==1
        for tbl_c=0 to tbl_columns-1
            table.cell  (table_id=infoboard,    column=tbl_c*4+1,   row=0,     text="Assets",        bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c),    text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
            table.cell  (table_id=infoboard,    column=tbl_c*4+2,   row=0,     text="Res: "+res_1,   bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c),    text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
            table.cell  (table_id=infoboard,    column=tbl_c*4+3,   row=0,     text="Res: "+res_2,   bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c),    text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)
            table.cell  (table_id=infoboard,    column=tbl_c*4+4,   row=0,     text="Res: "+res_3,   bgcolor=color.new(bgcolor_c,bgtrans_c), text_color=color.new(font_color_c,font_trans_c),    text_halign=f_align(halign_c),    text_size=f_size(font_size_c),    text_valign=text.align_center)


  //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 //  CREATE HEADER          TABLE        COLUMNS     ROWS        VALUE                           BACKGROUNG COLOR                        TEXT COLOR                                          HORIZONTAL ALIGNMENT.           TEXT SIZE               VERTICAL ALIGNMENT            ROW STEP //{
    table.cell  (table_id=infoboard,    column=ci+1,   row=ri,     text=f_ticker_id,        bgcolor=color.new(bgcolor_r,bgtrans_r), text_color=color.new(font_color_r,font_trans_r),    text_halign=f_align(halign_r),    text_size=f_size(font_size_r),    text_valign=text.align_center)
    table.cell  (table_id=infoboard,    column=ci+2,   row=ri,     text=info_text_low,      bgcolor=col_gradient_low, text_color=color.new(font_color,font_trans),    text_halign=f_align(halign),    text_size=f_size(font_size),    text_valign=text.align_center)
    table.cell  (table_id=infoboard,    column=ci+3,   row=ri,     text=info_text_mid,      bgcolor=col_gradient_mid, text_color=color.new(font_color,font_trans),    text_halign=f_align(halign),    text_size=f_size(font_size),    text_valign=text.align_center)
    table.cell  (table_id=infoboard,    column=ci+4,   row=ri,     text=info_text_high,     bgcolor=col_gradient_high, text_color=color.new(font_color,font_trans),    text_halign=f_align(halign),    text_size=f_size(font_size),    text_valign=text.align_center)
//}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //}

  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                 ASSET CALLS                                                                           //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{

if barstate.islast and not hide_infoboard
    for i = 1 to 12
        if i==1
            f_fill_table(asset_01,i)
        else if i==2
            f_fill_table(asset_02,i)
        else if i==3
            f_fill_table(asset_03,i)
        else if i==4
            f_fill_table(asset_04,i)
        else if i==5
            f_fill_table(asset_05,i)
        else if i==6
            f_fill_table(asset_06,i)
        else if i==7
            f_fill_table(asset_07,i)
        else if i==8
            f_fill_table(asset_08,i)
        else if i==9
            f_fill_table(asset_09,i)
        else if i==10
            f_fill_table(asset_10,i)
        else if i==11
            f_fill_table(asset_11,i)
        else if i==12
            f_fill_table(asset_12,i)
//}












