Ticker Ratio Levels
// 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'

//@version=5
indicator('Ticker Levels', overlay = true)
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')

line1 = input(true, '', group='Lines', inline='date1')
lineDate1 = input.time(timestamp('2017-12-17 00:00 UTC'), 'Line 1', group='Lines', inline='date1')
line2 = input(true, '', group='Lines', inline='date2')
lineDate2 = input.time(timestamp('2019-06-26 00:00 UTC'), 'Line 2', group='Lines', inline='date2')
line3 = input(true, '', group='Lines', inline='date3')
lineDate3 = input.time(timestamp('2020-03-13 00:00 UTC'), 'Line 3', group='Lines', inline='date3')
line4 = input(true, '', group='Lines', inline='date4')
lineDate4 = input.time(timestamp('2017-09-14 00:00 UTC'), 'Line 4', group='Lines', inline='date4')
line5 = input(true, '', group='Lines', inline='date5')
lineDate5 = input.time(timestamp('2021-04-14 00:00 UTC'), 'Line 5', group='Lines', inline='date5')
line6 = input(true, '', group='Lines', inline='date6')
lineDate6 = input.time(timestamp('2021-07-19 14:00 UTC'), 'Line 6', group='Lines', inline='date6')

// 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])

// 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)

tickerMod(Type) =>
	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    

getLevel(getDate, Mod)=>
    timeStart = time >= getDate and time[1] < getDate
    ifStart   = ta.valuewhen(timeStart, C_ANY / Mod, 0)
    curPrice  = (C_ANY / Mod)
    result    = (ifStart / curPrice)*C_ANY

plot(line1 ? getLevel(lineDate1, tickerMod(mod)) : na, color=color.yellow)
plot(line2 ? getLevel(lineDate2, tickerMod(mod)) : na, color=color.yellow)
plot(line3 ? getLevel(lineDate3, tickerMod(mod)) : na, color=color.yellow)
plot(line4 ? getLevel(lineDate4, tickerMod(mod)) : na, color=color.yellow)
plot(line5 ? getLevel(lineDate5, tickerMod(mod)) : na, color=color.yellow)
plot(line6 ? getLevel(lineDate6, tickerMod(mod)) : na, color=color.yellow)