Indicator · Pine Script v5 · Own pane

Index Generator [MUQWISHI]

by regalouisei· code credited to MUQWISHI

This indicator builds a custom multi-symbol index and draws it in a separate pane as candles, bars, or a line.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code358
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

358 lines of Pine Script v5 from pinescript/editors_picks/index-generator-by-muqwishi.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

index-generator-by-muqwishi.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MUQWISHI

//@version=5
indicator("Index Generator [MUQWISHI]")

// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// |                                   INPUT                                    |
// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
var G1 = "Mode & Style Settings"

// Index Name
indNme = input.string("My Oil & Gas Index", "Index Name         ", inline = "1", group = G1, display = display.none)

// Index Currency
curncy = input.string("USD", "Index Currency  ", inline = "0",  display = display.none)

// Table Location 
tblPos = input.string(  "Top Right"    , "Table Location   ", 
         ["Top Right" , "Middle Right" , "Bottom Right"     , 
          "Top Center", "Middle Center", "Bottom Center"    , 
          "Top Left"  , "Middle Left"  , "Bottom Left" ]    , inline = "1", display = display.none)

// Table Size
tblSiz = input.string("Small", "Table Size             ", 
         ["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], inline = "2", display = display.none)

// Table Colors
tBgCol = input.color(#5c698c, "   Title",  inline = "0")
cBgCol = input.color(#778899, "     Cell", inline = "1")
txtCol = input.color(#ffffff, "    Text",  inline = "2")

// Sorting
sortBy = input.string("Market Cap", "Sort Table By     ",             
               ["Symbols", "Change%", "Last", "Market Cap", "None"], inline = "4", display = display.none)
sortOd = input.string("Descending", "", ["Ascending", "Descending"], inline = "4", display = display.none)

// Index Plot Type
pltTyp = input.string("Candle", "Index Plot Type ", ["Candle", "Bar", "Line"], inline = "5", display = display.none)
pltCr1 = input.color(color.rgb(61, 158, 64), "  ",                           inline = "5")
pltCr2 = input.color(color.red, "",                                          inline = "5")

// Show & Hide
indChk = input.bool(true, "Show Index Title")
tblChk = input.bool(true, "Show Index Holdings")
pltChk = input.bool(true, "Show Index Plot")

// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// |                                  SYMBOLS                                   |
// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// Symbols Checkmark
c01 = input.bool(true,  "", group = "Symbols", inline = "s01")
c02 = input.bool(true,  "", group = "Symbols", inline = "s02")
c03 = input.bool(true,  "", group = "Symbols", inline = "s03")
c04 = input.bool(true,  "", group = "Symbols", inline = "s04")
c05 = input.bool(true,  "", group = "Symbols", inline = "s05")
c06 = input.bool(true,  "", group = "Symbols", inline = "s06")
c07 = input.bool(true,  "", group = "Symbols", inline = "s07")
c08 = input.bool(true,  "", group = "Symbols", inline = "s08")
c09 = input.bool(true,  "", group = "Symbols", inline = "s09")
c10 = input.bool(true,  "", group = "Symbols", inline = "s10")
c11 = input.bool(true,  "", group = "Symbols", inline = "s11")
c12 = input.bool(true,  "", group = "Symbols", inline = "s12")
c13 = input.bool(true,  "", group = "Symbols", inline = "s13")
c14 = input.bool(true,  "", group = "Symbols", inline = "s14")
c15 = input.bool(true,  "", group = "Symbols", inline = "s15")
c16 = input.bool(true,  "", group = "Symbols", inline = "s16")
c17 = input.bool(true,  "", group = "Symbols", inline = "s17")
c18 = input.bool(true,  "", group = "Symbols", inline = "s18")
c19 = input.bool(true,  "", group = "Symbols", inline = "s19")
c20 = input.bool(true,  "", group = "Symbols", inline = "s20")
c21 = input.bool(true,  "", group = "Symbols", inline = "s21")
c22 = input.bool(true,  "", group = "Symbols", inline = "s22")
c23 = input.bool(true,  "", group = "Symbols", inline = "s23")
c24 = input.bool(true,  "", group = "Symbols", inline = "s24")
c25 = input.bool(true,  "", group = "Symbols", inline = "s25")
c26 = input.bool(true,  "", group = "Symbols", inline = "s26")
c27 = input.bool(true,  "", group = "Symbols", inline = "s27")
c28 = input.bool(true,  "", group = "Symbols", inline = "s28")
c29 = input.bool(true,  "", group = "Symbols", inline = "s29")
c30 = input.bool(true,  "", group = "Symbols", inline = "s30")
c31 = input.bool(true,  "", group = "Symbols", inline = "s31")
c32 = input.bool(true,  "", group = "Symbols", inline = "s32")
c33 = input.bool(true,  "", group = "Symbols", inline = "s33")
c34 = input.bool(true,  "", group = "Symbols", inline = "s34")

// Symbol Input
s01 = input.symbol("2222",     "", group = "Symbols", inline = "s01", display = display.none)
s02 = input.symbol("XOM",      "", group = "Symbols", inline = "s02", display = display.none)
s03 = input.symbol("CVX",      "", group = "Symbols", inline = "s03", display = display.none)
s04 = input.symbol("601857",   "", group = "Symbols", inline = "s04", display = display.none)
s05 = input.symbol("SHEL",     "", group = "Symbols", inline = "s05", display = display.none)
s06 = input.symbol("TTE",      "", group = "Symbols", inline = "s06", display = display.none)
s07 = input.symbol("COP",      "", group = "Symbols", inline = "s07", display = display.none)
s08 = input.symbol("HKEX:883", "", group = "Symbols", inline = "s08", display = display.none)
s09 = input.symbol("BP",       "", group = "Symbols", inline = "s09", display = display.none)
s10 = input.symbol("PBR",      "", group = "Symbols", inline = "s10", display = display.none)
s11 = input.symbol("ADX:TAQA", "", group = "Symbols", inline = "s11", display = display.none)
s12 = input.symbol("CNQ",      "", group = "Symbols", inline = "s12", display = display.none)
s13 = input.symbol("EQNR",     "", group = "Symbols", inline = "s13", display = display.none)
s14 = input.symbol("SLB",      "", group = "Symbols", inline = "s14", display = display.none)
s15 = input.symbol("600028",   "", group = "Symbols", inline = "s15", display = display.none)
s16 = input.symbol("SO",       "", group = "Symbols", inline = "s16", display = display.none)
s17 = input.symbol("MPC",      "", group = "Symbols", inline = "s17", display = display.none)
s18 = input.symbol("EOG",      "", group = "Symbols", inline = "s18", display = display.none)
s19 = input.symbol("ENB",      "", group = "Symbols", inline = "s19", display = display.none)
s20 = input.symbol("DUK",      "", group = "Symbols", inline = "s20", display = display.none)
s21 = input.symbol("PSX",      "", group = "Symbols", inline = "s21", display = display.none)
s22 = input.symbol("ROSN",     "", group = "Symbols", inline = "s22", display = display.none)
s23 = input.symbol("ADNOCGAS", "", group = "Symbols", inline = "s23", display = display.none)
s24 = input.symbol("EPD",      "", group = "Symbols", inline = "s24", display = display.none)
s25 = input.symbol("PXD",      "", group = "Symbols", inline = "s25", display = display.none)
s26 = input.symbol("VLO",      "", group = "Symbols", inline = "s26", display = display.none)
s27 = input.symbol("OXY",      "", group = "Symbols", inline = "s27", display = display.none)
s28 = input.symbol("LKOH",     "", group = "Symbols", inline = "s28", display = display.none)
s29 = input.symbol("ET",       "", group = "Symbols", inline = "s29", display = display.none)
s30 = input.symbol("E",        "", group = "Symbols", inline = "s30", display = display.none)
s31 = input.symbol("SU",       "", group = "Symbols", inline = "s31", display = display.none)
s32 = input.symbol("WMB",      "", group = "Symbols", inline = "s32", display = display.none)
s33 = input.symbol("HES",      "", group = "Symbols", inline = "s33", display = display.none)
s34 = input.symbol("OKE",      "", group = "Symbols", inline = "s34", display = display.none)

// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// |                                CALCULATION                                 |
// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// +++++++++++++ Round Functions
s(x) => str.tostring(x, format.volume)
m(x) => math.round_to_mintick(x)

// +++++++++++++ Create Matrices 
valMtx = matrix.new<float> (0, 10, na)
datMtx = matrix.new<string>(0, 07, na)
exclud = array.new<string>(1, "")

// +++++++++++++ Main Function
main(flg) =>
    var dec = string(na), var cnt = string(na), var sec = string(na), 
    var ind = string(na), var mkt = float(na) , 
    var c0  = float(na) , var c1  = float(na)

    o = float(na), c = float(na), h = float(na), l = float(na), chg = float(na)
    if flg
        o := m(open),  c := m(close), h := m(high),  l := m(low)
      
        // Calculate Change         
        c0 := session.ismarket ? close : c0
        if timeframe.change("D")
            c1 := c0[1]
        chg := (close - c1)/c1 * 100

        // Get Symbol's Infos
        if barstate.islastconfirmedhistory
            dec := syminfo.description
            cnt := syminfo.country
            sec := syminfo.sector
            ind := syminfo.industry

        // Market Cap
        shr = syminfo.shares_outstanding_total
        if barstate.isrealtime
            mkt := shr * c1
        else
            mkt := shr * close 
        
    [o, c, h, l, mkt, chg, dec, cnt, sec, ind, time, timenow]

// +++++++++++++ Security Function
request(num, sym, flg) =>
    [o, c, h, l, mkt, chg, dec, cnt, sec, ind, tim, real] = 
     request.security(ticker.modify(sym, syminfo.session), timeframe.period,
      main(flg), ignore_invalid_symbol = true, currency = curncy)
     
    if flg
        if na(mkt)
            exclud.set(0, (exclud.get(0) != "" ? exclud.get(0) + ", " : "") + str.split(sym, ":").get(1))
        else
            if tim >= time
                valMtx.add_row(valMtx.rows(), array.from(num, o, c, h, l, mkt, 0, tim, chg, real))
            else
                valMtx.add_row(valMtx.rows(), array.from(num, c, c, c, c, mkt, 0, tim, chg, real))

            datMtx.add_row(datMtx.rows(), array.from(s(num), str.split(sym, ":").get(1), str.split(sym, ":").get(0), dec, cnt, sec, ind))

// +++++++++++++ Import Data
request(01, s01, c01),  request(02, s02, c02),  request(03, s03, c03),  
request(04, s04, c04),  request(05, s05, c05),  request(06, s06, c06), 
request(07, s07, c07),  request(08, s08, c08),  request(09, s09, c09),  
request(10, s10, c10),  request(11, s11, c11),  request(12, s12, c12),  
request(13, s13, c13),  request(14, s14, c14),  request(15, s15, c15),  
request(16, s16, c16),  request(17, s17, c17),  request(18, s18, c18),  
request(19, s19, c19),  request(20, s20, c20),  request(21, s21, c21),  
request(22, s22, c22),  request(23, s23, c23),  request(24, s24, c24),  
request(25, s25, c25),  request(26, s26, c26),  request(27, s27, c27),  
request(28, s28, c28),  request(29, s29, c29),  request(30, s30, c30),  
request(31, s31, c31),  request(32, s32, c32),  request(33, s33, c33),  
request(34, s34, c34),  //request(35, s35, c35), 

// +++++++++++++ Prepare Data
o = float(na), c = float(na), h = float(na), l = float(na)
plotCond = valMtx.col(7).max() >= time // Does lastLin bar's time equal to max time of all holding?
if valMtx.rows() > 0
    totMrkt = valMtx.col(5).sum()

    for i = 0 to valMtx.rows() - 1
        wight = valMtx.get(i, 5)/totMrkt
        valMtx.set(i, 6, wight)

        if plotCond
            o := nz(o) + wight * valMtx.get(i, 1)
            c := nz(c) + wight * valMtx.get(i, 2)
            h := nz(h) + wight * valMtx.get(i, 3)
            l := nz(l) + wight * valMtx.get(i, 4)

    if sortBy != "None"
        order = sortOd == "Ascending" ? order.ascending : order.descending
        if sortBy == "Symbols"
            datMtx.sort(1, order)
        else
            a = sortBy == "Change%" ? 8 : sortBy == "Last" ? 2 : 6
            valMtx.sort(a, order)

// Index Change
indexChange(c) =>
    var c0     = 0.0   // Close at Regular Session.
    var c1     = 0.0   // Close at Day Session.
    var isChgD = false // Change in Day

    c0   := not na(c) ? c : c0
    isChgD := dayofmonth != dayofmonth[1] ? true : isChgD
    if isChgD and not na(c) 
        c1 := c0[1], isChgD := false

    [c0, (c0 - c1), (c0 - c1)/c1 * 100]
 
[indxCls, indxChg, indxChgP] = indexChange(c)


// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// |                                  PLOTTING                                  |
// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
var cndColor1 = pltCr1, cndColor1 := na(c) ? cndColor1 : (c > o    ? pltCr1 : c < o    ? pltCr2 : pltCr1)
var cndColor2 = pltCr1, cndColor2 := na(c) ? cndColor2 : (c > c[1] ? pltCr1 : c < c[1] ? pltCr2 : pltCr1)

// Candle Plot
plotcandle(o, h, l, c, "Candle", cndColor1, color.gray, true, bordercolor = cndColor1, 
           display = pltChk and pltTyp == "Candle" ? display.all : display.none)

// Bar Plot
plotbar (o, h, l, c, "Bar", cndColor1, true,   display = pltChk and pltTyp == "Bar"  ? display.all : display.none)

// Line Plot
plot(c, "Line", cndColor2, 2, editable = true, display = pltChk and pltTyp == "Line" ? display.all : display.none)

// Change Percentage 
plot(timeframe.isintraday ? (c-c[1])/c[1] * 100 : not na(c) ? indxChgP : na, "", cndColor1, editable = false, 
           display = pltChk ? display.status_line : display.none, format = format.percent)

// Last Price Line
var line  lastLin = na 
var label lastLab = na
if not na(lastLin)
    lastLin.set_xy1(bar_index    , indxCls)
    lastLin.set_xy2(bar_index + 1, indxCls)
    lastLin.set_color(pltTyp == "Line" ? cndColor2 : cndColor1)

else if pltChk
    lastLin := line.new(0, 0, 0, 0, xloc.bar_index, extend.both, na, line.style_dotted, 1)


// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// |                                   TABLE                                    |
// |++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
// +++++++++++++ Get Tbale Location & Size
locNsze(x) => 
    y   = str.split(str.lower(x), " ")
    out = ""
    for i = 0 to y.size() - 1
        out := out + y.get(i)
        if i != y.size() - 1
            out := out + "_"
    out

// +++++++++++++ Create Table
var table tbl = na 
var nRows = 36
var nCols = 5
if  nRows > 5
    tbl := table.new(locNsze(tblPos), nCols, nRows, color(na), color(na), 1, color(na), 1)

// +++++++++++++ Cell Function
cell(col, row, txt, bCol, tCol) => 
    tbl.cell(col, row, txt, 0, 0, tCol, bgcolor = bCol, text_size = locNsze(tblSiz))


// +++++++++++++ Draw Table
if barstate.islast and not na(tbl)
    tbl.clear(0, 0, nCols - 1, nRows - 1)

    v = 0
    if indChk
        // Index
        r = indxChg > 0 ? pltCr1 : indxChg < 0 ? pltCr2 : txtCol

        cell(0, v, indNme + "\n" +
             str.tostring(indxCls > 1 ? math.round(indxCls, 2) : indxCls, "0.00######") + "    " + 
             str.tostring(indxCls > 1 ? math.round(indxChg, 2) : indxCls, "0.00######") + "    " +
             str.tostring(indxChgP, format.percent), color(na), r), 
        tbl.cell_set_text_size(0, v, size.auto)
        tbl.cell_set_text_font_family(0, v, font.family_default)
        tbl.merge_cells(0, v, nCols - 1, v), 
        v += 1

    if tblChk
        excld = array.get(exclud, 0)

        // Holdings
        cell(0, v, "Symbols" + (excld != "" ? "\n⚠️" : ""),                          tBgCol, txtCol)
        if excld != ""
            tbl.cell_set_tooltip(0, v,  "These symbols are not included in the index's holdings" + 
                          " because their total number of shares are not provided/NaN.\n\n"  + excld)

        cell(1, v, "Last\n("+curncy+")",                                              tBgCol, txtCol)
        cell(2, v, "Chg%\n(" + (timeframe.isintraday ? "D" : timeframe.period) + ")", tBgCol, txtCol)
        cell(3, v, "Market\nCap",                                                     tBgCol, txtCol)
        cell(4, v, "Weight%",                                                         tBgCol, txtCol)
        v += 1

        if valMtx.rows() > 0
            for i = 0 to valMtx.rows() - 1

                // Symbol 
                idx   = datMtx.col(0).indexof(str.tostring(valMtx.get(i, 0)))
                symbl = datMtx.get(idx, 1)
                r     = sortBy == "Symbols" ? v + idx : v

                cell(0, r, symbl, tBgCol, txtCol)
                tbl.cell_set_tooltip(0, r, datMtx.get(idx, 3) +
                 "\n================================="        +
                 "\nExᴄʜᴀɴɢᴇ﹕"    + datMtx.get(idx, 2)       +
                 "\nCᴏᴜɴᴛʀʏ﹕"     + datMtx.get(idx, 4)       +
                 "\nSᴇᴄᴛᴏʀ﹕"      + datMtx.get(idx, 5)       +
                 "\nIɴᴅᴜsᴛʀɪᴀʟ﹕"  + datMtx.get(idx, 6))

                // Last 
                cell(1, r, str.tostring(valMtx.get(i, 2), "0.00########"), cBgCol, txtCol)

                // Change
                symChg = valMtx.get(i, 8)
                symCol = symChg > 0 ? pltCr1 : symChg < 0 ? pltCr2 : cBgCol
                cell(2, r, str.tostring(symChg, format.percent), symCol, txtCol)

                // Market Cap
                cell(3, r, str.tostring(valMtx.get(i, 5), format.volume), cBgCol, txtCol)

                // Weight %
                cell(4, r, str.tostring(valMtx.get(i, 6) * 100, format.percent), cBgCol, txtCol)
                
                v := sortBy == "Symbols" ? v : v + 1

Overview

A holdings table can list the selected symbols and sort them by symbol name, percent change, last price, or market cap, in ascending or descending order. Users set the index name and currency, table position, size, and colors, and can show or hide the title, holdings, plot, and individual symbols. The visible code does not define trading entries or exits.

Details

Published by

regalouisei on GitHub

Code credit

MUQWISHI, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Screeners & dashboards

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Index Name         stringMy Oil & Gas IndexindNme
Index Currency  stringUSDcurncy
Table Location   stringTop RighttblPos
Table Size             stringSmalltblSiz
   Titlecolor#5c698ctBgCol
     Cellcolor#778899cBgCol
    Textcolor#fffffftxtCol
Sort Table By     stringMarket CapsortBy
sortOdstringDescendingsortOd
Index Plot Type stringCandlepltTyp
  colorcolor.rgb(61, 158, 64)pltCr1
pltCr2colorcolor.redpltCr2
Show all 40 settings
SettingTypeDefaultVariable
Show Index TitlebooltrueindChk
Show Index HoldingsbooltruetblChk
Show Index PlotbooltruepltChk
c01booltruec01
c02booltruec02
c03booltruec03
c04booltruec04
c05booltruec05
c06booltruec06
c07booltruec07
c08booltruec08
c09booltruec09
c10booltruec10
c11booltruec11
c12booltruec12
c13booltruec13
c14booltruec14
c15booltruec15
c16booltruec16
c17booltruec17
c18booltruec18
c19booltruec19
c20booltruec20
c21booltruec21
c22booltruec22
c23booltruec23
c24booltruec24
c25booltruec25
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

This indicator measures the chart symbol’s percentage change from the opening price at the start of each US presidential term and plots those values as histogram columns in a separate pane. Columns are offset so each administration appears separately, with a s

Indicator v6 Screeners & dashboards
Updated 10 days ago · GPL-3.0 GitHub repository of Presidents Performance

This indicator scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

Indicator v6 Oscillators & momentumDivergence
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Scanner

Tables-001

by ricardosantos79
261 stars

This indicator builds a TradingView table in a separate pane and fills its cells with fixed placeholder text according to whether each row and column index is even or odd. Users set the table position, the number of rows and columns, and the background, frame,

Indicator v4 Screeners & dashboards
Updated 4 years ago · None stated GitHub repository of Tables-001
257 stars

Donald SPX - Options Trading is an indicator designed to assist SPX index option traders by tracking session benchmarks and multi-timeframe moving average data. It calculates a 200-period weighted moving average (WMA) and requests multi-timeframe bar data from

Indicator v5 Moving averagesScreeners & dashboards Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Index Member Distribution

by TradersPost
218 stars

Calculates and plots a weighted histogram of constituent returns for major market indices (NDX, SPX, DJIA, and RUT) in a separate pane. Each histogram bin reflects the summed weights of members within that percentage return bracket. The script renders vertical

Indicator v6 Screeners & dashboards
Updated 3 months ago · None stated GitHub repository of Index Member Distribution

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers