BTC Twitter Sentiment
// 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 sentiment data, this chart might look chunky on lower timeframes, even with smoothing.

//@version=5
indicator("BTC Twitter Sentiment", overlay=false)
//If there's an additional ticker that you'd like to see here, please let me know!
Source = input.string(title="Blockchain", defval="BTC", options=["AAVE","ADA","ALGO","AXS","BAT","BCH","BIT","BTC","CHZ","CRO","CRV","DASH","DOGE","ENS","ETH","FTM","FTT","FXS","GRT","HT","KCS","LDO","LEO","LINK","LTC","MANA","MATIC","MKR","NEXO","OKB","QNT","SAND","SHIB","SNX","UNI","ZEC"], group="Inputs")
smoothing = input.string(title="Smoothing", defval="SMA", options=["SMA", "RMA", "EMA", "WMA"], group="Smoothing 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(1, 'MA Length', group="Smoothing Settings")
TwitterPosT = "INTOTHEBLOCK:" + Source + "_TWITTERPOSITIVE"
TwitterNegT = "INTOTHEBLOCK:" + Source + "_TWITTERNEGATIVE"
TwitterNeuT = "INTOTHEBLOCK:" + Source + "_TWITTERNEUTRAL"
TwitterPos = request.security(TwitterPosT, "D", close)
TwitterNeg = request.security(TwitterNegT, "D", close)
TwitterNeu = request.security(TwitterNeuT, "D", close)

//Plotting
ZeroLine = plot(ma_function(0, SmoothLength), color=color.blue, transp=100, editable = false, display=display.none) //We need to make this ZeroLine, as the fill function doesn't accept variable of type int
NegLine = plot(ma_function(TwitterNeg, SmoothLength), "Negative Tweets", color=color.red, display=display.all-display.status_line)
NeuLine = plot(ma_function(TwitterNeu+TwitterNeg, SmoothLength), "Neutral Tweets", color=color.white, display=display.all-display.status_line)
PosLine = plot(ma_function(TwitterNeu+TwitterNeg+TwitterPos, SmoothLength), "Positive Tweets", color=color.green, display=display.all-display.status_line)
//Separate plots that only show the numbers (This is because showing numbers for original plots would show aggregate numbers)
NegNumber = plot(ma_function(TwitterNeg, SmoothLength), "Negative Tweets Number display", color=color.red, display=display.status_line)
NeuNumber = plot(ma_function(TwitterNeu, SmoothLength), "Neutral Tweets Number display", color=color.white, display=display.status_line)
PosNumber = plot(ma_function(TwitterPos, SmoothLength), "Positive Tweets Number display", color=color.green, display=display.status_line)
fill(PosLine, NeuLine, color=color.green,title= "Positive Background", transp=50)
fill(NeuLine, NegLine, color=color.white,title= "Neutral Background", transp=50)
fill(ZeroLine, NegLine, color=color.red,title= "Negative Background", transp=50)