Banknifty Volume - IN
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mayurssupe

//@version=5
indicator(title="BankNity Volume",overlay=false,shorttitle = "Volume - IN")

//_symbol = input.symbol(defval="",title="Symbol")
_reversal = input.bool(defval = false,title="Non Repainted Trend Cloud",group = "Cloud",tooltip = "The Cloud is a crossover of Price and volume it is additional confirmation when trend will reverse, if the Cloud gets red means trend is changing towards bears vicerversa for Bull Side")
_revTF = input.timeframe(title="Set Timeframe for Trend Cloud",defval="",group="Cloud")

len = input.int(title="RSI Period",defval=9,group="Volume")
_tf = input.timeframe(title="Timeframe",defval="",group="Timeframe")

bn_wt = input(0.2, title="Banknifty Weightage",group = "Weightage")
sbi_wt = input(0.025, title="SBI Weightage",group = "Weightage")
axis_wt = input(0.11, title="Axis Weightage")
baroda_wt = input(0.018, title="Baroda Weightage",group = "Weightage")
pnb_wt = input(0.2, title="PNB Weightage",group = "Weightage")
fed_wt = input(0.025, title="FED Weightage",group = "Weightage")
idfc_wt = input(0.01, title="IDFC Weightage",group = "Weightage")
indusind_wt = input(0.02, title="Indusind Weightage",group = "Weightage")
icici_wt = input(0.20, title="ICICI Weightage",group = "Weightage")
bandhan_wt = input(0.02, title="Bandhan Weightage",group = "Weightage")
kotak_wt = input(0.15, title="Kotak Weightage",group = "Weightage")
hdfc_wt = input(0.26, title="HDFC Weightage",group = "Weightage")
vix_wt = input(0.35, title="IndVix Weightage",group = "Weightage")


//Ticker Id's
bn = "NSE:BANKNIFTY1!"
sbi = "NSE:SBIN"
axis = "NSE:AXISBANK"
baroda = "NSE:BANKBARODA"
pnb = "NSE:PNB"
fed = "BSE:FEDERALBNK"
idfc = "NSE:IDFCFIRSTB"
indusind = "NSE:INDUSINDBK"
icici = "NSE:ICICIBANK"
bandhan = "NSE:BANDHANBNK"
kotak = "NSE:KOTAKBANK"
hdfc = "NSE:HDFCBANK"
vix = "INDIAVIX"


//Sercuirty Fuctions
frsi(tickerid,src,length)=> request.security(tickerid,_tf,ta.rsi(src,length))
fvwap(src)=> request.security(syminfo.tickerid,_tf,ta.vwap(src))
trendDetSecurity(tf,exp) => request.security(syminfo.tickerid,tf,exp)

//Declaring every Ticker
bn1 = frsi(bn,close,len)
sb = frsi(sbi,close,len)
ax = frsi(axis,close,len)
bar = frsi(baroda,close,len)
pn = frsi(pnb,close,len)
fe = frsi(fed,close,len)
id = frsi(idfc,close,len)
_in = frsi(indusind,close,len)
ic = frsi(icici,close,len)
ban = frsi(bandhan,close,len)
ko = frsi(kotak,close,len)
hd = frsi(hdfc,close,len)
ind_v = frsi(vix,close,len)


average  = (bn1 * bn_wt) + (sb * sbi_wt) + (ax * axis_wt) + (bar * baroda_wt) + (pn * pnb_wt) + (fe * fed_wt) + (id * idfc_wt) + (_in * indusind_wt) + (ic * icici_wt) + (ban * bandhan_wt) + (ko * kotak_wt ) + (hd * hdfc_wt ) + (ind_v * vix_wt )
//Average of All tickers
//average = math.avg(bn1,sb,ax,bar,pn,fe,id,_in,ic,ban,ko,hd,ind_v)
var int smoothingperiod = 124

avgColume = ta.hma((average - 50),smoothingperiod) 
avgLine = avgColume / 2

//Banknifty
ma = ta.ema(avgColume,55)

//Two Moving avrage to identify the trend change
var int volTher = 22
_price = trendDetSecurity(_revTF,ta.ema(avgColume,3))[1]  // Price
_volume = trendDetSecurity(_revTF,ta.wma(avgColume,21))[1] // volume

osc = 100 * (_price - _volume) / _price

longfilter = _price > _volume ? color.rgb(0, 238, 8,50) : _price < volume ? color.rgb(255, 123, 0,50) :color.gray

h1= plot(_reversal ? _price : na,title="Price",linewidth = 3,color=longfilter)
h2= plot(_reversal ? _volume : na,title="Volume",linewidth=3,color=longfilter)

plot(avgColume ? avgColume : 1,style=plot.style_columns,color=avgColume > ma ? color.aqua : avgColume < ma ? color.new(#e91e63,0) :color.silver,linewidth=3,trackprice=true,title="Volume")
fill(h1,h2,color=longfilter)
