GIRISH indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © email_analysts

//@version=5
indicator("GIRISH indicator")

var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")

computeVWAP(src, isNewPeriod) =>
	var float sumSrcVol = na
	var float sumVol = na
    var float sumSrcSrcVol = na

	sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
	sumVol := isNewPeriod ? volume : volume + sumVol[1]
	// sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation
	sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume * math.pow(src, 2) + sumSrcSrcVol[1]

	_vwap = sumSrcVol / sumVol
	variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
	variance := variance < 0 ? 0 : variance
	stDev = math.sqrt(variance)

	[_vwap, stDev]

hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")
var anchor = input.string(defval = "Session", title="Anchor Period",
 options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings")
src1 = input(title = "Source", defval = hlc3, group="VWAP Settings")
offset = input(0, title="Offset", group="VWAP Settings")

timeChange(period) =>
	ta.change(time(period))

new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)

isNewPeriod = switch anchor
	"Earnings" => not na(new_earnings)
	"Dividends" => not na(new_dividends)
	"Splits" => not na(new_split)
	"Session" => timeChange("D")
	"Week" => timeChange("W")
	"Month" => timeChange("M")
	"Quarter" => timeChange("3M")
	"Year" => timeChange("12M")
	"Decade" => timeChange("12M") and year % 10 == 0
	"Century" => timeChange("12M") and year % 100 == 0
	=> false

isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"
if na(src1[1]) and not isEsdAnchor
	isNewPeriod := true

float vw = na

if not (hideonDWM and timeframe.isdwm)
    [_vwap, _stdev] = computeVWAP(src1, isNewPeriod)
    vw := _vwap

bar = -(vw-close)*10000/close
len6 = input.int(5, "GH Smooth", minval=1)

bar1 = ta.ema(bar, len6)

hlineup = hline(40, color=#ffffff)
hlinemid = hline(0, color=#ffffff)
hlinelow = hline(-40, color=#ffffff)

plot(bar1, color = color.white, style=plot.style_line, linewidth = 1, title="GH")

////////////////////////////////
len1 = input(title="OBV Length 1", defval = 3)
len2 = input(title="OBV Length 2", defval = 21)
ema1 = ta.ema(ta.obv, len1)
ema2 = ta.ema(ta.obv, len2)
obv=ema1-ema2

len3 = input(title="RSI Length 1", defval = 5)
len4 = input(title="RSI Length 2", defval = 9)
len5 = input(title="RSI Length 3", defval = 14)
sh = ta.rsi(close, len3)
sh9 = ta.rsi(close, len4)
ln = ta.ema(sh9, len5)
rsi = sh-ln


backgroundColor = obv >0 and rsi > 0 and vw-close > close/500 ? color.rgb(51, 100, 52):
                  obv >0 and rsi > 0 ? color.rgb(64, 161, 65):
                  obv < 0 and rsi < 0 and close-vw > close/500 ? color.rgb(146, 44, 44):
                  obv < 0 and rsi < 0 ? color.rgb(209, 110, 110, 25):
                  na

bgcolor(color=backgroundColor, transp=100)
