Tickers Info Extension
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HALDRO

opt01    = 'XAU'
opt02    = 'DXY'
opt03    = 'BTC'
opt04    = 'ETH'
opt05    = 'SPX'
opt06    = 'NASDAQ'
opt07    = 'AVG STABLE.D'
opt08    = 'AVG STOCK Price'
opt09    = 'Alt Cap(TOTAL3)'
opt10    = 'Custom'

MA(source, length, type) =>
    switch type
        'SMA' => ta.sma(source, length)
        'EMA' => ta.ema(source, length)
        'RMA' => ta.rma(source, length)
        'WMA' => ta.wma(source, length)
        'VWMA'=> ta.vwma(source, length)
        'HMA' => ta.hma(source, length)

//@version=5
indicator('Tickers Info Extension')
// Chart Inputs
mod       = input.session	(opt01,			'Mode',			   group='Chart', inline='mode', options=[opt01, opt02, opt03, opt04, opt05, opt06, opt07, opt08, opt09, opt10])
custom    = input.symbol	('', 			'Custom',		   group='Chart', inline='mode', tooltip='If you want to select a different ticker, then select the Custom in Mode option')
compare   = input.bool		(true, 			'Compare ?', 	   group='Chart', inline='comp', tooltip='If Compare ON, the current ticker is divided by the selection in Mode')
typesym   = input.session	('Candles',		'Type Symbol', 	   group='Chart', inline='symb', options=['Candles', 'Open', 'High', 'Close', 'Low'])
// MA Settings
usema     = input.bool		(true, 			'Use MA ?', 	   group='MA Settings')
length    = input.int		(0050, 			'Length',   	   group='MA Settings', inline='ma')
maType    = input.string	('EMA', 		'MA Type',  	   group='MA Settings', inline='ma', options=['SMA', 'EMA', 'RMA', 'WMA', 'VWMA', 'HMA'])
// Color
upColor   = input.color		(#00ff6d, 		'UP Col',    	  group='Color', inline='color')
dnColor   = input.color		(#ff0056, 		'DN Col',    	  group='Color', inline='color')
wickColor = input.color		(#ffffff, 		'Wick Col',  	  group='Color', inline='color')
tablefont = input.color		(#ffa726, 		'Panel Font',	  group='Color', inline='table')
tablebg   = input.color		(#363A45, 		'Panel BG',  	  group='Color', inline='table')

// Ticker List
TF     	  = timeframe.period
ANY    	  = syminfo.tickerid
CST    	  = custom
BTC    	  = 'BITSTAMP:BTCUSD'
DJI    	  = 'TVC:DJI'
DXY    	  = 'TVC:DXY'
ETH    	  = 'BINANCE:ETHUSDT'
NDX    	  = 'NASDAQ:NDX'
SPX    	  = 'TVC:SPX'
WM2NS  	  = 'FRED:WM2NS'
XAU    	  = 'OANDA:XAUUSD'
USDT_D 	  = 'CRYPTOCAP:USDT.D'
USDC_D 	  = 'CRYPTOCAP:USDC.D'
DDAI_D 	  = 'CRYPTOCAP:DAI.D'
TOTAL3 	  = 'TOTAL3'

// Request OHLC
[O_ANY, H_ANY, L_ANY, C_ANY] = request.security(ANY, TF, [open, high, low, close])
[O_BTC, H_BTC, L_BTC, C_BTC] = request.security(BTC, TF, [open, high, low, close])
[O_CST, H_CST, L_CST, C_CST] = request.security(CST, TF, [open, high, low, close])
[O_DJI, H_DJI, L_DJI, C_DJI] = request.security(DJI, TF, [open, high, low, close])
[O_DXY, H_DXY, L_DXY, C_DXY] = request.security(DXY, TF, [open, high, low, close])
[O_ETH, H_ETH, L_ETH, C_ETH] = request.security(ETH, TF, [open, high, low, close])
[O_NDX, H_NDX, L_NDX, C_NDX] = request.security(NDX, TF, [open, high, low, close])
[O_SPX, H_SPX, L_SPX, C_SPX] = request.security(SPX, TF, [open, high, low, close])
[O_XAU, H_XAU, L_XAU, C_XAU] = request.security(XAU, TF, [open, high, low, close])
[O_USDT_D, H_USDT_D, L_USDT_D, C_USDT_D] = request.security(USDT_D, TF, [open, high, low, close])
[O_USDC_D, H_USDC_D, L_USDC_D, C_USDC_D] = request.security(USDC_D, TF, [open, high, low, close])
[O_DDAI_D, H_DDAI_D, L_DDAI_D, C_DDAI_D] = request.security(DDAI_D, TF, [open, high, low, close])
[O_TOTAL3, H_TOTAL3, L_TOTAL3, C_TOTAL3] = request.security(TOTAL3, TF, [open, high, low, close])

// Calculation
// STOCK MARKET PRICE
O_STOCKAVG = (O_DJI + O_SPX + O_NDX) / 3
H_STOCKAVG = (H_DJI + H_SPX + H_NDX) / 3
L_STOCKAVG = (L_DJI + L_SPX + L_NDX) / 3
C_STOCKAVG = (C_DJI + C_SPX + C_NDX) / 3

// AVG STABLE COIN DOMINACE
O_AVGDOM   = (O_USDT_D + O_USDC_D + O_DDAI_D)
H_AVGDOM   = (H_USDT_D + H_USDC_D + H_DDAI_D)
L_AVGDOM   = (L_USDT_D + L_USDC_D + L_DDAI_D)
C_AVGDOM   = (C_USDT_D + C_USDC_D + C_DDAI_D)

// Get OHLC Selected Ticker
tickerMod(Type) =>
	ticker_Open = switch Type
		opt01 => O_XAU     
		opt02 => O_DXY     
		opt03 => O_BTC     
		opt04 => O_ETH     
		opt05 => O_SPX     
		opt06 => O_NDX     
		opt07 => O_AVGDOM  
		opt08 => O_STOCKAVG
		opt09 => O_TOTAL3  
		opt10 => O_CST     

	ticker_High = switch Type
		opt01 => H_XAU     
		opt02 => H_DXY     
		opt03 => H_BTC     
		opt04 => H_ETH     
		opt05 => H_SPX     
		opt06 => H_NDX     
		opt07 => H_AVGDOM  
		opt08 => H_STOCKAVG
		opt09 => H_TOTAL3  
		opt10 => H_CST     

	ticker_Low = switch Type
		opt01 => L_XAU     
		opt02 => L_DXY     
		opt03 => L_BTC     
		opt04 => L_ETH     
		opt05 => L_SPX     
		opt06 => L_NDX     
		opt07 => L_AVGDOM  
		opt08 => L_STOCKAVG
		opt09 => L_TOTAL3  
		opt10 => L_CST     

	ticker_Close = switch Type
		opt01 => C_XAU     
		opt02 => C_DXY     
		opt03 => C_BTC     
		opt04 => C_ETH     
		opt05 => C_SPX     
		opt06 => C_NDX     
		opt07 => C_AVGDOM  
		opt08 => C_STOCKAVG
		opt09 => C_TOTAL3  
		opt10 => C_CST     
		
	if compare == true
		ticker_Open	 := O_ANY / ticker_Open	
		ticker_High	 := H_ANY / ticker_High	
		ticker_Low	 := L_ANY / ticker_Low		
		ticker_Close := C_ANY / ticker_Close	

	[ticker_Open, ticker_High, ticker_Low, ticker_Close]

[O,H,L,C] = tickerMod(mod)

stype = switch typesym
	'Open'  => O
	'High'  => H
	'Low'   => L
	'Close' => C
	=> na

// Plots
colorCandle = C > O ? upColor : dnColor, wickcolor=wickColor, Bordercolor=colorCandle
plotcandle(O,H,L,C, color=colorCandle, wickcolor=wickColor, bordercolor=Bordercolor, editable=false, display=typesym != 'Candles' ? display.none : display.all)

plot(usema ? MA(C, length, maType) : na, 'MA')
plot(stype, title = 'Price')

// Panel Symbol Info
string symbolOnly = str.substring(CST, str.pos(CST, ':') + 1)
msg = ' / '
cond = compare and mod != opt10 ? syminfo.ticker + msg + mod : mod==opt10 and compare != true ? symbolOnly : mod==opt10 and compare ? syminfo.ticker + msg + symbolOnly : mod
var table panel = table.new(position = position.bottom_right, columns = 2, rows = 1, bgcolor = tablebg, border_width = 1)
if barstate.islast
    table.cell(panel, 1, 0, text=str.tostring(cond), text_color = tablefont, bgcolor = tablebg)
