Top12/Bottom88 Weighted Ratio 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MarlosClock
// first pine script, Top 12 QQQ Tick 
//@version=5
indicator('Top12/Bottom88 Weighted Ratio ', shorttitle='Top12/Bot88', overlay=false)


FBclose = request.security('FB', '60', close[0])

AAPLclose = request.security('AAPL', '60', close[0])

AMZNclose = request.security('AMZN', '60', close[0])

NFLXclose = request.security('NFLX', '60', close[0])

GOOGclose = request.security('GOOG', '60', close[0])

GOOGLclose = request.security('GOOGL', '60', close[0])

MSFTclose = request.security('MSFT', '60', close[0])

TSLAclose = request.security('TSLA', '60', close[0])

NVDAclose = request.security('NVDA', '60', close[0])

ADBEclose = request.security('ADBE', '60', close[0])

AVGOclose = request.security('AVGO', '60', close[0])

COSTclose = request.security('COST', '60', close[0])

CSCOclose = request.security('CSCO', '60', close[0])

PEPclose = request.security('PEP', '60', close[0])


//https://ycharts.com/companies/QQQ/holdings
//weightings are multiplied by the percentage currently. May need to be updated periodically
FBw = 3.67 * FBclose
AAPLw = 12.24 * AAPLclose
AMZNw = 6.26 * AMZNclose
NFLXw = 1.16 * NFLXclose
GOOGw = 3.78 * GOOGclose
GOOGLw = 3.75 * GOOGLclose
MSFTw = 12.58* MSFTclose
TSLAw = 3.57 * TSLAclose
NVDAw = 5.00 * NVDAclose
ADBEw = 1.69 * ADBEclose
PEPw = 1.94 * PEPclose
AVGOw = 2.05 * AVGOclose
COSTw = 1.72 * COSTclose
CSCOw = 1.64 * CSCOclose
//56% of QQQ total

//TotW = FBw + AAPLw + AMZNw + NFLXw + GOOGw + GOOGLw + MSFTw
TotW12 = FBw + AAPLw + AMZNw + NFLXw + GOOGw + GOOGLw + MSFTw + TSLAw + NVDAw + ADBEw + AVGOw + CSCOw + COSTw + PEPw
src = TotW12

Bottom_88 = request.security('NDX', '60', close[0])
Bottom_88w = ((Bottom_88*88)-TotW12)/100
src2 = src/Bottom_88w

// Plot colors for histogram
col_grow_above = input(color.rgb(73, 222, 207, 20), "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(color.rgb(207, 64, 164, 11), "Fall", group="Histogram", inline="Above")
col_grow_below = input(color.rgb(244, 79, 206, 13), "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(color.rgb(255, 82, 82, 9), "Fall", group="Histogram", inline="Below")
col_grow_abovet= input(color.rgb(72, 250, 232, 10), "Above   Grow", group="Histogram", inline="Above")
col_fall_abovet= input(color.rgb(232, 71, 170, 11), "Fall", group="Histogram", inline="Above")
col_grow_belowt= input(color.rgb(227, 73, 73, 5), "Below Grow", group="Histogram", inline="Below")
col_fall_belowt= input(color.rgb(255, 82, 171, 10), "Fall", group="Histogram", inline="Below")


//plot(src, title="Top12 Weighted Index", color=color.from_gradient(src,-40,40,color.fuchsia,color.teal))
plot(src2, title="Top12/Bot88", color=(src2>=0 ? (src2[1] < src2 ? col_grow_abovet : col_fall_abovet) : (src2[1] < src2 ? col_grow_belowt : col_fall_belowt)), style=plot.style_area)

