BTC Miner Netflows with smoothing
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Powerscooter
// Since IntoTheBlock only provides daily Inflow and Outflow data, this chart might look chunky on lower timeframes, even with smoothing.

//@version=5
indicator("BTC Miner Netflows")
smoothing = input.string(title="Smoothing", defval="SMA", options=["SMA", "RMA", "EMA", "WMA"], group="Netflow Settings")
ma_function(source, length) =>
	switch smoothing
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		=> ta.wma(source, length)
SmoothLength = input(21, 'MA Length', group="Netflow Settings")

//Plotting
Netflows = request.security("INTOTHEBLOCK:BTC_MINERNETFLOWS", "D", close)
SmoothFlow = ma_function(Netflows, SmoothLength)
Netflow = plot(SmoothFlow, "Exchange Inflows", color.white, transp = 10)
ZeroLine = plot(0, "Zero Line", color=color.white, transp = 60) //We need this because the fill() function only takes plot, not int.
fill(plot1=Netflow, plot2=ZeroLine, color=SmoothFlow > 0 ? color.new(color.green, 60) : color.new(color.red, 60))