RTH & ETH TWAPs [vnhilton]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vnhilton

//@version=5
indicator("RTH & ETH TWAPs [vnhilton]", "RTH&ETH TWAPS", true)

//RTH Timezone
rth = time(timeframe.period, session.regular, syminfo.timezone)

//Parameters
srcrth = input(ohlc4, "Source For RTH TWAP", group="RTH Parameters")
srceth = input(ohlc4, "Source For ETH TWAP", group="ETH Parameters")

//TWAP Calculation - Function By TradingView (modified)
twap(source) =>
    var prices = 0.0
    var count  = 0

    if timeframe.change("1D")
        prices := 0
        count  := 0

	prices += source
	count  += 1

    prices / count

//Get RTH TWAP
var float twapRTH = na

if rth
    twapRTH := twap(srcrth)

//Get ETH TWAP
twapETH = twap(srceth)

//Plots
plotRTH  = plot(rth ? twapRTH : na, "RTH TWAP", color.new(#a5ff8d, 0), style=plot.style_linebr)
plotETH  = plot(twapETH,            "ETH TWAP", color.new(#a5ff8d, 75))
fill(plotRTH, plotETH, color.new(#a5ff8d, 95), "Plot Fill", display=display.none)
